From 80c269548770289d457fd7e2b7187c05b67d3a27 Mon Sep 17 00:00:00 2001 From: Markus Winter Date: Sat, 2 Dec 2023 16:31:52 +0100 Subject: [PATCH] move link elements to head fixes JENKINS-72196 when in a form there are repeatables that both contain a codemirror config via a textarea. When deleting the first of those it can happen that the link elements importing the css for codemirror are defined in a div that gets deleted. This effectively removes the css from the DOM tree, so that other textareas afterwards that also require the codemirror css are no longer styled properly. The Behaviour uses a high negative value for the priority so that the move of the link elements is applied before any other behaviour jumps in, e.g. hetero-list and repeatable add the elements to the dom via jelly of all things can that can be added and later remove them from the dom and keep them in memory. --- war/src/main/webapp/scripts/hudson-behavior.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/war/src/main/webapp/scripts/hudson-behavior.js b/war/src/main/webapp/scripts/hudson-behavior.js index 7284a14e2ba1..678260fdad17 100644 --- a/war/src/main/webapp/scripts/hudson-behavior.js +++ b/war/src/main/webapp/scripts/hudson-behavior.js @@ -1214,6 +1214,13 @@ function rowvgStartEachRow(recursive, f) { } (function () { + // This moves all link elements to the head + // fixes JENKINS-72196 when a link is inside a div of a repeatable and the + // div is deleted then the styling is lost for divs afterwards. + Behaviour.specify("body link", "move-css-to-head", -9999, function (link) { + document.head.appendChild(link); + }); + var p = 20; Behaviour.specify("TABLE.sortable", "table-sortable", ++p, function (e) { // sortable table