Skip to content

Commit

Permalink
[JENKINS-74025] Extract inline JavaScript from checkboxContent.jelly
Browse files Browse the repository at this point in the history
  • Loading branch information
yaroslavafenkin authored and kinow committed Nov 23, 2024
1 parent 36cdae1 commit d92050c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 26 deletions.
19 changes: 19 additions & 0 deletions src/main/resources/org/biouno/unochoice/common/checkbox-content.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
window.addEventListener("DOMContentLoaded", () => {
document.querySelectorAll(".checkbox-content-data-holder").forEach((dataHolder) => {
const { maxCount, randomName } = dataHolder.dataset;

var height = 0;
var refElement = document.getElementById(`ecp_${randomName}_0`);
if (maxCount > 0 && refElement && refElement.offsetHeight != 0) {
for (var i = 0; i < maxCount; i++) {
height += refElement.offsetHeight + 3;
}
}
else {
height = maxCount * 25.5;
}

height = Math.floor(height);
document.getElementById(`ecp_${randomName}`).style.height = height + "px";
});
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?jelly escape-by-default='true' ?>
<j:jelly xmlns:j="jelly:core"
xmlns:d="jelly:define"
xmlns:transitionWrapper="transitionWrapper">
xmlns:transitionWrapper="transitionWrapper"
xmlns:st="jelly:stapler">
<d:taglib uri="transitionWrapper">
<d:tag name="randomTableIdBlock">
<j:choose>
Expand Down Expand Up @@ -101,29 +102,6 @@
</j:forEach>
</transitionWrapper:randomTableIdBlock>
</div>
<script type="text/javascript">
<![CDATA[
(function() {
var f = function() {
var height = 0;
var maxCount = ${it.getVisibleItemCount()};
var refElement = document.getElementById("ecp_${h.escape(it.randomName)}_0");
if(maxCount > 0 && refElement && refElement.offsetHeight !=0) {
for(var i=0; i< maxCount; i++) {
height += refElement.offsetHeight + 3;
}
}
else {
height = maxCount * 25.5;
}
height = Math.floor(height);
document.getElementById("ecp_${h.escape(it.randomName)}").style.height = height + "px";
};
f();
})();
]]>
</script>
<span class="checkbox-content-data-holder" data-max-count="${it.getVisibleItemCount()}" data-random-name="${h.escape(it.randomName)}" />
<st:adjunct includes="org.biouno.unochoice.common.checkbox-content" />
</j:jelly>

0 comments on commit d92050c

Please sign in to comment.