diff --git a/views/assets/scripts.js b/views/assets/scripts.js index 9346c4c..4b30868 100644 --- a/views/assets/scripts.js +++ b/views/assets/scripts.js @@ -335,15 +335,13 @@ document.addEventListener("DOMContentLoaded", function() { } }); }); -const v = []; +const w = []; document.addEventListener("DOMContentLoaded", () => { S(); }); -const O = function(a) { - typeof a == "function" && v.push(a); -}, S = function() { - for (; v.length > 0; ) { - const a = v.shift(); +const S = function() { + for (; w.length > 0; ) { + const a = w.shift(); try { a(); } catch (e) { @@ -351,17 +349,24 @@ const O = function(a) { } } }; -class V extends HTMLElement { +class O extends HTMLElement { constructor() { - super(), this.scrollHandler = null, this.scrollTimeout = null, this.clickHandlers = [], this.manualNavigation = !1; + super(), this.scrollTimeout = null, this.clickHandlers = [], this.manualNavigation = !1, this.handleScroll = this.handleScroll.bind(this); + } + handleScroll() { + console.log("Scroll event fired!"), clearTimeout(this.scrollTimeout), this.scrollTimeout = setTimeout(() => { + this.updateActiveLink(), this.updateSidebarScrollToTopButton(); + }, 50); } connectedCallback() { - O(() => { + console.log("AkteureScrollspy connected"), setTimeout(() => { this.initializeScrollspyAfterDelay(); + }, 50), window.addEventListener("pageshow", (e) => { + e.persisted && (this.cleanup(), this.initializeScrollspy()); }); } initializeScrollspyAfterDelay() { - if (this.sections = document.querySelectorAll(".author-section"), this.navLinks = document.querySelectorAll(".scrollspy-link"), this.sections.length === 0 || this.navLinks.length === 0) { + if (console.log("initializeScrollspyAfterDelay running"), this.sections = document.querySelectorAll(".author-section"), this.navLinks = document.querySelectorAll(".scrollspy-link"), this.sections.length === 0 || this.navLinks.length === 0) { setTimeout(() => { this.sections = document.querySelectorAll(".author-section"), this.navLinks = document.querySelectorAll(".scrollspy-link"), this.sections.length > 0 && this.navLinks.length > 0 && this.initializeScrollspy(); }, 500); @@ -370,14 +375,10 @@ class V extends HTMLElement { this.initializeScrollspy(); } disconnectedCallback() { - this.cleanup(); + console.log("AkteureScrollspy disconnected"), this.cleanup(); } initializeScrollspy() { - this.scrollHandler = () => { - clearTimeout(this.scrollTimeout), this.scrollTimeout = setTimeout(() => { - this.updateActiveLink(), this.updateSidebarScrollToTopButton(); - }, 50); - }, window.addEventListener("scroll", this.scrollHandler), this.navLinks.forEach((e) => { + console.log("initializeScrollspy running"), window.addEventListener("scroll", this.handleScroll), this.navLinks.forEach((e) => { const t = (i) => { i.preventDefault(); const n = e.getAttribute("data-target"), s = document.getElementById(n); @@ -389,7 +390,9 @@ class V extends HTMLElement { }, 1e3)); }; this.clickHandlers.push({ link: e, handler: t }), e.addEventListener("click", t); - }), this.updateActiveLink(), this.updateSidebarScrollToTopButton(); + }), setTimeout(() => { + this.updateActiveLink(); + }, 300), this.updateSidebarScrollToTopButton(); } ensureMarkerVisibility() { const e = document.getElementById("scrollspy-slider"), t = document.getElementById("scrollspy-nav"); @@ -487,9 +490,9 @@ class V extends HTMLElement { document.documentElement.offsetHeight ), s = window.innerHeight, o = n - s, r = o > 0 ? window.scrollY / o : 0, l = t.clientHeight, d = t.scrollHeight - l; if (d > 0) { - const u = r * d, g = i.getBoundingClientRect(), p = t.getBoundingClientRect(), f = g.top - p.top + t.scrollTop, m = l / 2, q = f - m, y = 0.7, I = y * u + (1 - y) * q, w = Math.max(0, Math.min(d, I)), T = t.scrollTop; - Math.abs(w - T) > 10 && t.scrollTo({ - top: w, + const u = r * d, g = i.getBoundingClientRect(), p = t.getBoundingClientRect(), f = g.top - p.top + t.scrollTop, m = l / 2, q = f - m, y = 0.7, I = y * u + (1 - y) * q, v = Math.max(0, Math.min(d, I)), T = t.scrollTop; + Math.abs(v - T) > 10 && t.scrollTo({ + top: v, behavior: "smooth" }); } @@ -501,15 +504,15 @@ class V extends HTMLElement { t > i * 0.5 ? (e.classList.remove("opacity-0"), e.classList.add("opacity-100")) : (e.classList.remove("opacity-100"), e.classList.add("opacity-0")); } cleanup() { - this.scrollHandler && (window.removeEventListener("scroll", this.scrollHandler), this.scrollHandler = null), this.scrollTimeout && (clearTimeout(this.scrollTimeout), this.scrollTimeout = null), this.clickHandlers && this.clickHandlers.length > 0 && this.clickHandlers.forEach(({ link: t, handler: i }) => { + console.log("Scrollspy cleanup running"), window.removeEventListener("scroll", this.handleScroll), this.scrollTimeout && (clearTimeout(this.scrollTimeout), this.scrollTimeout = null), this.clickHandlers && this.clickHandlers.length > 0 && this.clickHandlers.forEach(({ link: t, handler: i }) => { t && i && t.removeEventListener("click", i); }); const e = document.getElementById("scrollspy-slider"); e && (e.style.opacity = "0", e.style.height = "0"), this.sections = null, this.navLinks = null, this.clickHandlers = [], this.manualNavigation = !1; } } -customElements.define("akteure-scrollspy", V); -class $ extends HTMLElement { +customElements.define("akteure-scrollspy", O); +class V extends HTMLElement { constructor() { super(), this.resizeObserver = null; } @@ -862,7 +865,7 @@ class $ extends HTMLElement { return "KGPZ"; } } -customElements.define("single-page-viewer", $); +customElements.define("single-page-viewer", V); document.body.addEventListener("htmx:beforeRequest", function(a) { const e = document.querySelector("single-page-viewer"); e && e.style.display !== "none" && (console.log("Cleaning up single page viewer before HTMX navigation"), e.close()); @@ -871,7 +874,7 @@ window.addEventListener("beforeunload", function() { const a = document.querySelector("single-page-viewer"); a && a.close(); }); -class R extends HTMLElement { +class $ extends HTMLElement { constructor() { super(), this.isVisible = !1, this.scrollHandler = null, this.htmxAfterSwapHandler = null; } @@ -912,8 +915,8 @@ class R extends HTMLElement { }); } } -customElements.define("scroll-to-top-button", R); -class z extends HTMLElement { +customElements.define("scroll-to-top-button", $); +class R extends HTMLElement { constructor() { super(), this.pageObserver = null, this.pageContainers = /* @__PURE__ */ new Map(), this.singlePageViewerActive = !1, this.singlePageViewerCurrentPage = null, this.boundHandleSinglePageViewer = this.handleSinglePageViewer.bind(this); } @@ -1032,8 +1035,8 @@ class z extends HTMLElement { this.pageObserver && (this.pageObserver.disconnect(), this.pageObserver = null), document.removeEventListener("singlepageviewer:opened", this.boundHandleSinglePageViewer), document.removeEventListener("singlepageviewer:closed", this.boundHandleSinglePageViewer), document.removeEventListener("singlepageviewer:pagechanged", this.boundHandleSinglePageViewer), this.pageContainers.clear(); } } -customElements.define("inhaltsverzeichnis-scrollspy", z); -class j extends HTMLElement { +customElements.define("inhaltsverzeichnis-scrollspy", R); +class z extends HTMLElement { constructor() { super(), this.innerHTML = `