From 4676f9518404849eb68f1465e1096b7e7960cfb9 Mon Sep 17 00:00:00 2001 From: KingKDot Date: Thu, 23 Apr 2026 22:57:34 -0500 Subject: [PATCH] fix ripple Co-authored-by: Copilot --- Overlord-Server/public/assets/ripple.js | 68 ++++++++++++++++--------- 1 file changed, 43 insertions(+), 25 deletions(-) diff --git a/Overlord-Server/public/assets/ripple.js b/Overlord-Server/public/assets/ripple.js index f45683b..77d019f 100644 --- a/Overlord-Server/public/assets/ripple.js +++ b/Overlord-Server/public/assets/ripple.js @@ -1,32 +1,50 @@ -function addRippleEffect(element) { - element.classList.add("ripple"); +(() => { + if (window.__overlordRippleInitialized) { + return; + } + window.__overlordRippleInitialized = true; - element.addEventListener("click", function (e) { - this.classList.remove("ripple-active"); + function addRippleEffect(element) { + if (!element || element.dataset.rippleBound === "1") { + return; + } - const rect = this.getBoundingClientRect(); - const x = e.clientX - rect.left; - const y = e.clientY - rect.top; + element.classList.add("ripple"); + element.dataset.rippleBound = "1"; - this.style.setProperty("--x", x + "px"); - this.style.setProperty("--y", y + "px"); - - void this.offsetWidth; - - this.classList.add("ripple-active"); - - setTimeout(() => { + element.addEventListener("click", function (e) { this.classList.remove("ripple-active"); - }, 600); - }); -} -document.addEventListener("DOMContentLoaded", () => { - document - .querySelectorAll("button:not(.no-ripple), .button:not(.no-ripple)") - .forEach((btn) => { - addRippleEffect(btn); + const rect = this.getBoundingClientRect(); + const x = e.clientX - rect.left; + const y = e.clientY - rect.top; + + this.style.setProperty("--x", x + "px"); + this.style.setProperty("--y", y + "px"); + + void this.offsetWidth; + + this.classList.add("ripple-active"); + + setTimeout(() => { + this.classList.remove("ripple-active"); + }, 600); }); -}); + } -window.addRippleEffect = addRippleEffect; + function initRippleEffects() { + document + .querySelectorAll("button:not(.no-ripple), .button:not(.no-ripple)") + .forEach((btn) => { + addRippleEffect(btn); + }); + } + + if (document.readyState === "loading") { + document.addEventListener("DOMContentLoaded", initRippleEffects, { once: true }); + } else { + initRippleEffects(); + } + + window.addRippleEffect = addRippleEffect; +})();