From 11f3387d732f6be4a20d248713f3874b3758e90f Mon Sep 17 00:00:00 2001 From: Johannes Raggam Date: Mon, 1 Sep 2025 01:38:32 +0200 Subject: [PATCH 1/3] maint(pat-inject): Change one more forEach to a for loop. --- src/pat/inject/inject.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pat/inject/inject.js b/src/pat/inject/inject.js index e396c4c12..5081397a4 100644 --- a/src/pat/inject/inject.js +++ b/src/pat/inject/inject.js @@ -595,7 +595,8 @@ const inject = { ) { $title = sources$[sources$.length - 1]; } - cfgs.forEach((cfg, idx1) => { + + for (const [idx1, cfg] of cfgs.entries()) { const perform_inject = () => { if (cfg.target !== "none") { for (const target of cfg.$target) { @@ -615,7 +616,7 @@ const inject = { } else { perform_inject(); } - }); + } if (cfgs[0].nextHref && $el.is("a")) { // In case next-href is specified the anchor's href will // be set to it after the injection is triggered. From 253ac4ae4a97fa92e0e9faf1763407e3876dfbde Mon Sep 17 00:00:00 2001 From: Johannes Raggam Date: Mon, 1 Sep 2025 12:06:41 +0200 Subject: [PATCH 2/3] fix(pat-scroll): Fix issue where no scroll target can be found. Use document.body instead. --- src/pat/scroll/scroll.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/pat/scroll/scroll.js b/src/pat/scroll/scroll.js index 7e8c248ab..c5d70f103 100644 --- a/src/pat/scroll/scroll.js +++ b/src/pat/scroll/scroll.js @@ -52,12 +52,15 @@ class Pattern extends BasePattern { await utils.timeout(this.options.delay); } - const target = this.get_target(); - const scroll_container = dom.find_scroll_container( - target.parentElement, - this.options.direction === "top" ? "y" : "x", - window - ); + const target = this.get_target() || document.body; + const scroll_container = + target === document.body + ? document.body + : dom.find_scroll_container( + target.parentElement, + this.options.direction === "top" ? "y" : "x", + window + ); // Set/remove classes on beginning and end of scroll this.el.classList.add("pat-scroll-animated"); From ed8e9419e1c43b6aa9398d365932175b3c79d4a0 Mon Sep 17 00:00:00 2001 From: Johannes Raggam Date: Mon, 1 Sep 2025 12:30:45 +0200 Subject: [PATCH 3/3] fix(core dom): Don't break when elements given to get_relative_position and scroll_to_element are window or document and as such no real DOM elements. Use document.body instead. --- src/core/dom.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/core/dom.js b/src/core/dom.js index 01c9ef8b8..053d81e06 100644 --- a/src/core/dom.js +++ b/src/core/dom.js @@ -364,9 +364,12 @@ const get_relative_position = (el, reference_el = document.body) => { // the relative position of the target. // In case of a scroll container of window, we do not have // getBoundingClientRect method, so get the body instead. - if (reference_el === window) { + if (reference_el === window || document) { reference_el = document.body; } + if (el === window || document) { + el = document.body; + } // Calculate absolute [ยน] position difference between // scroll_container and scroll_target. @@ -407,6 +410,14 @@ const get_relative_position = (el, reference_el = document.body) => { * @param {string} [direction="top"] - The direction to scroll to. Can be either "top", "left" or "both". */ const scroll_to_element = (el, scroll_container, offset = 0, direction = "top") => { + // Normalize el and scroll_container + if (el === window || document) { + el = document.body; + } + if (scroll_container === window || document) { + scroll_container = document.body; + } + // Get the position of the element relative to the scroll container. const position = get_relative_position(el, scroll_container);