From a54ef2b855097557044f6ae6f97b02a8e8e9a8c9 Mon Sep 17 00:00:00 2001 From: Markus Winter Date: Sat, 20 Jul 2024 13:59:25 +0200 Subject: [PATCH 1/3] remove YUI from ensureVisible replace usage of YUI with plain javascript in the ensureVisible method The current logic seems to have no effect, so it is changed in the following When the element is bigger then the current viewport height, scroll so that the element is at the top. If the elements is smaller than the viewport height and the bottom is outside scoll so that the bottom is at the lower end of the viewport. Otherwise no scrolling is needed the element is already completely inside the viewport. --- .../main/webapp/scripts/hudson-behavior.js | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/war/src/main/webapp/scripts/hudson-behavior.js b/war/src/main/webapp/scripts/hudson-behavior.js index 8d1a0a9e8e8a..5f1e09cdafbf 100644 --- a/war/src/main/webapp/scripts/hudson-behavior.js +++ b/war/src/main/webapp/scripts/hudson-behavior.js @@ -2242,14 +2242,13 @@ function getStyle(e, a) { */ // eslint-disable-next-line no-unused-vars function ensureVisible(e) { - var viewport = YAHOO.util.Dom.getClientRegion(); - var pos = YAHOO.util.Dom.getRegion(e); - - var Y = viewport.top; - var H = viewport.height; + const scrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop); + let Y = scrollTop; + let H = window.innerHeight; + let c = 0; function handleStickers(name, f) { - var e = document.getElementById(name); + const e = document.getElementById(name); if (e) { f(e); } @@ -2261,6 +2260,7 @@ function ensureVisible(e) { t = t.clientHeight; Y += t; H -= t; + c += t; }); handleStickers("bottom-sticker", function (b) { @@ -2268,17 +2268,15 @@ function ensureVisible(e) { H -= b; }); - var y = pos.top; - var h = pos.height; + const box = e.getBoundingClientRect(); + const y = Math.round(box.top + scrollTop); + const h = e.offsetHeight; + const d = y + h - (Y + H); - var d = y + h - (Y + H); - if (d > 0) { - document.body.scrollTop += d; - } else { - d = Y - y; - if (d > 0) { - document.body.scrollTop -= d; - } + if (h > H) { + document.documentElement.scrollTop = y - c; + } else if (d > 0) { + document.documentElement.scrollTop += d; } } From 9d88f4070bf5d1100b39798118c38a2957630481 Mon Sep 17 00:00:00 2001 From: Markus Winter Date: Sat, 20 Jul 2024 14:53:02 +0200 Subject: [PATCH 2/3] apply prettier --- war/src/main/webapp/scripts/hudson-behavior.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/war/src/main/webapp/scripts/hudson-behavior.js b/war/src/main/webapp/scripts/hudson-behavior.js index 5f1e09cdafbf..da53764792eb 100644 --- a/war/src/main/webapp/scripts/hudson-behavior.js +++ b/war/src/main/webapp/scripts/hudson-behavior.js @@ -2242,7 +2242,10 @@ function getStyle(e, a) { */ // eslint-disable-next-line no-unused-vars function ensureVisible(e) { - const scrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop); + const scrollTop = Math.max( + document.documentElement.scrollTop, + document.body.scrollTop, + ); let Y = scrollTop; let H = window.innerHeight; let c = 0; From 666d74bb1e818a5f9cfb8cee18b8ebc3799785b0 Mon Sep 17 00:00:00 2001 From: Markus Winter Date: Tue, 23 Jul 2024 00:19:49 +0200 Subject: [PATCH 3/3] remove body.scrollTop --- war/src/main/webapp/scripts/hudson-behavior.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/war/src/main/webapp/scripts/hudson-behavior.js b/war/src/main/webapp/scripts/hudson-behavior.js index da53764792eb..110a09fa199f 100644 --- a/war/src/main/webapp/scripts/hudson-behavior.js +++ b/war/src/main/webapp/scripts/hudson-behavior.js @@ -2242,10 +2242,7 @@ function getStyle(e, a) { */ // eslint-disable-next-line no-unused-vars function ensureVisible(e) { - const scrollTop = Math.max( - document.documentElement.scrollTop, - document.body.scrollTop, - ); + const scrollTop = document.documentElement.scrollTop; let Y = scrollTop; let H = window.innerHeight; let c = 0;