From 548a32fb19c18c58e502e06c519b04432c50de58 Mon Sep 17 00:00:00 2001 From: Zbynek Konecny Date: Sat, 15 Jun 2024 20:08:15 +0200 Subject: [PATCH] Replace usages of YUI framework by simple JS/CSS --- .../hudson/console/ExpandableDetailsNote.java | 5 +- .../console/ExpandableDetailsNote/script.js | 6 +-- .../console/ExpandableDetailsNote/style.css | 2 +- .../resources/hudson/model/View/index.jelly | 1 - .../SlowTriggerAdminMonitor/message.groovy | 4 +- .../RekeySecretAdminMonitor/message.groovy | 4 +- .../lib/form/repeatable/repeatable.js | 40 +++++++-------- .../jenkins/security/Security3245Test.java | 13 ++--- .../js/components/dropdowns/hetero-list.js | 14 +----- war/src/main/scss/form/_reorderable-list.scss | 8 +++ .../main/webapp/scripts/hudson-behavior.js | 3 +- war/src/main/webapp/scripts/sortable.js | 49 ++++++------------- 12 files changed, 62 insertions(+), 87 deletions(-) diff --git a/core/src/main/java/hudson/console/ExpandableDetailsNote.java b/core/src/main/java/hudson/console/ExpandableDetailsNote.java index 1f558e6a260b..beb623b5034c 100644 --- a/core/src/main/java/hudson/console/ExpandableDetailsNote.java +++ b/core/src/main/java/hudson/console/ExpandableDetailsNote.java @@ -26,8 +26,8 @@ import edu.umd.cs.findbugs.annotations.NonNull; import hudson.Extension; -import hudson.Functions; import hudson.MarkupText; +import hudson.Util; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; @@ -53,7 +53,8 @@ public ExpandableDetailsNote(String caption, String html) { @Override public ConsoleAnnotator annotate(Object context, MarkupText text, int charPos) { text.addMarkup(charPos, - "
" + html + "
"); + "
" + html + "
"); return null; } diff --git a/core/src/main/resources/hudson/console/ExpandableDetailsNote/script.js b/core/src/main/resources/hudson/console/ExpandableDetailsNote/script.js index bd71b5fec807..f42f4113802d 100644 --- a/core/src/main/resources/hudson/console/ExpandableDetailsNote/script.js +++ b/core/src/main/resources/hudson/console/ExpandableDetailsNote/script.js @@ -1,11 +1,11 @@ (function () { Behaviour.specify( - "INPUT.reveal-expandable-detail", + "BUTTON.reveal-expandable-detail", "ExpandableDetailsNote", 0, function (e) { - var detail = e.nextSibling; - makeButton(e, function () { + e.addEventListener("click", () => { + const detail = e.nextSibling; detail.style.display = detail.style.display == "block" ? "none" : "block"; }); diff --git a/core/src/main/resources/hudson/console/ExpandableDetailsNote/style.css b/core/src/main/resources/hudson/console/ExpandableDetailsNote/style.css index 3015eb2ba7e8..b3636a127219 100644 --- a/core/src/main/resources/hudson/console/ExpandableDetailsNote/style.css +++ b/core/src/main/resources/hudson/console/ExpandableDetailsNote/style.css @@ -1,6 +1,6 @@ DIV.expandable-detail { display: none; - background-color: #d3d7cf; + background-color: var(--background); margin: 0.5em; padding: 0.5em; } diff --git a/core/src/main/resources/hudson/model/View/index.jelly b/core/src/main/resources/hudson/model/View/index.jelly index 3f20913e81cc..b09115956171 100644 --- a/core/src/main/resources/hudson/model/View/index.jelly +++ b/core/src/main/resources/hudson/model/View/index.jelly @@ -44,7 +44,6 @@ THE SOFTWARE. - ", "

")); FreeStyleBuild build = j.buildAndAssertSuccess(p); AtomicBoolean alerts = new AtomicBoolean(); @@ -40,12 +40,9 @@ public void captionCannotAttributeEscape() throws Exception { wc.setAlertHandler((pr, s) -> alerts.set(true)); final HtmlPage page = wc.goTo(build.getUrl() + "console"); String content = page.getWebResponse().getContentAsString(); - assertThat(content, containsString("")); - - // Execute JavaScript code to simulate click event - String jsCode = "document.querySelector('.reveal-expandable-detail').dispatchEvent(new MouseEvent('click'));"; - page.executeJavaScript(jsCode); - + assertThat(content, containsString("")); + // check that alert was not executed Assert.assertFalse("Alert not expected", alerts.get()); } } diff --git a/war/src/main/js/components/dropdowns/hetero-list.js b/war/src/main/js/components/dropdowns/hetero-list.js index 2b216bc20168..0eab2b9ea324 100644 --- a/war/src/main/js/components/dropdowns/hetero-list.js +++ b/war/src/main/js/components/dropdowns/hetero-list.js @@ -77,11 +77,10 @@ function generateButtons() { function insert(instance, template) { let nc = document.createElement("div"); - nc.className = "repeated-chunk"; + nc.className = "repeated-chunk fade-in"; nc.setAttribute("name", template.name); nc.setAttribute("descriptorId", template.descriptorId); nc.innerHTML = template.html; - nc.style.opacity = "0"; instance.hide(); @@ -150,18 +149,9 @@ function generateButtons() { if (withDragDrop) { registerSortableDragDrop(nc); } - - new YAHOO.util.Anim( - nc, - { - opacity: { to: 1 }, - }, - 0.2, - YAHOO.util.Easing.easeIn, - ).animate(); - Behaviour.applySubtree(nc, true); ensureVisible(nc); + nc.classList.remove("fade-in"); layoutUpdateCallback.call(); }, true, diff --git a/war/src/main/scss/form/_reorderable-list.scss b/war/src/main/scss/form/_reorderable-list.scss index c19152975d2e..7cd726556df1 100644 --- a/war/src/main/scss/form/_reorderable-list.scss +++ b/war/src/main/scss/form/_reorderable-list.scss @@ -7,6 +7,14 @@ border-radius: 10px; margin-bottom: 1rem; margin-top: 1rem; + transition: + opacity 0.2s ease-in, + max-height 0.2s ease-in; +} + +.repeated-chunk.fade-in, +.repeated-chunk.fade-out { + opacity: 0; } .repeated-chunk .show-if-last { diff --git a/war/src/main/webapp/scripts/hudson-behavior.js b/war/src/main/webapp/scripts/hudson-behavior.js index 161db88cfd72..2314cdcf7863 100644 --- a/war/src/main/webapp/scripts/hudson-behavior.js +++ b/war/src/main/webapp/scripts/hudson-behavior.js @@ -1661,7 +1661,8 @@ function rowvgStartEachRow(recursive, f) { } } changeTo(e, "-hover.png"); - YAHOO.util.Event.stopEvent(event); + event.stopPropagation(); + event.preventDefault(); return false; }; e = null; // memory leak prevention diff --git a/war/src/main/webapp/scripts/sortable.js b/war/src/main/webapp/scripts/sortable.js index 7b4b9e8f4da8..b42be9ee945b 100644 --- a/war/src/main/webapp/scripts/sortable.js +++ b/war/src/main/webapp/scripts/sortable.js @@ -133,16 +133,14 @@ var Sortable = (function () { */ getStoredPreference: function () { var key = this.getStorageKey(); - if (storage.hasKey(key)) { - var val = storage.getItem(key); - if (val) { - var vals = val.split(":"); - if (vals.length == 2) { - return { - column: parseInt(vals[0]), - direction: arrowTable[vals[1]], - }; - } + var val = sessionStorage.getItem(key); + if (val) { + var vals = val.split(":"); + if (vals.length == 2) { + return { + column: parseInt(vals[0]), + direction: arrowTable[vals[1]], + }; } } return null; @@ -156,7 +154,13 @@ var Sortable = (function () { savePreference: function () { var key = this.getStorageKey(); - storage.setItem(key, this.pref.column + ":" + this.pref.direction.id); + var value = this.pref.column + ":" + this.pref.direction.id; + try { + sessionStorage.setItem(key, value); + } catch (e) { + // storage could be full + console.warn(e); + } }, /** @@ -442,29 +446,6 @@ var Sortable = (function () { }, }; - var storage; - try { - storage = YAHOO.util.StorageManager.get( - YAHOO.util.StorageEngineHTML5.ENGINE_NAME, - YAHOO.util.StorageManager.LOCATION_SESSION, - { - order: [YAHOO.util.StorageEngineGears], - }, - ); - // eslint-disable-next-line no-unused-vars - } catch (e) { - // no storage available - storage = { - setItem: function () {}, - getItem: function () { - return null; - }, - hasKey: function () { - return false; - }, - }; - } - return { Sortable: Sortable, sorter: sorter,