Files
overlord/Overlord-Server/public/assets/ripple.js
T

51 lines
1.2 KiB
JavaScript
Raw Normal View History

2026-04-23 22:57:34 -05:00
(() => {
if (window.__overlordRippleInitialized) {
return;
}
window.__overlordRippleInitialized = true;
2026-03-05 00:04:26 -06:00
2026-04-23 22:57:34 -05:00
function addRippleEffect(element) {
if (!element || element.dataset.rippleBound === "1") {
return;
}
2026-03-05 00:04:26 -06:00
2026-04-23 22:57:34 -05:00
element.classList.add("ripple");
element.dataset.rippleBound = "1";
2026-03-05 00:04:26 -06:00
2026-04-23 22:57:34 -05:00
element.addEventListener("click", function (e) {
2026-03-05 00:04:26 -06:00
this.classList.remove("ripple-active");
2026-04-23 22:57:34 -05:00
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);
2026-03-05 00:04:26 -06:00
});
2026-04-23 22:57:34 -05:00
}
2026-03-05 00:04:26 -06:00
2026-04-23 22:57:34 -05:00
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;
})();