document.addEventListener("DOMContentLoaded", () => { const qs = (sel, root = document) => root.querySelector(sel); const qsa = (sel, root = document) => Array.from(root.querySelectorAll(sel)); const body = document.body; // --------------------------- // 1) Aside / Burger menu // --------------------------- const openMenu = () => body.setAttribute("data-menu-open", "true"); const closeMenu = () => body.removeAttribute("data-menu-open"); const isMenuOpen = () => body.hasAttribute("data-menu-open"); document.addEventListener("click", (e) => { const t = e.target; // Open if (t.closest("#burger-menu") || t.matches("#burger-menu")) { openMenu(); return; } // Close (explicit button) if (t.closest("#close") || t.matches("#close")) { closeMenu(); return; } // Click outside wrapper -> close if (isMenuOpen() && !t.closest("#aside__wrapper")) { closeMenu(); } }); document.addEventListener("keydown", (e) => { if (e.key === "Escape") closeMenu(); }); // --------------------------- // 2) Accordion blocks // --------------------------- document.addEventListener("click", (e) => { const btn = e.target.closest('[data-el="acc"] [data-el="acc-btn"]'); if (!btn) return; const acc = btn.closest('[data-el="acc"]'); const inner = acc?.querySelector('[data-el="acc-inner"]'); if (!inner) return; const isOpen = inner.getAttribute("data-open") === "true"; inner.setAttribute("data-open", isOpen ? "false" : "true"); }); // --------------------------- // 3) "More Info" buttons (table toggles) // --------------------------- document.addEventListener("click", (e) => { const btn = e.target.closest( 'button[aria-label="More Info"][aria-controls]' ); if (!btn) return; const panelId = btn.getAttribute("aria-controls"); if (!panelId) return; const panel = document.getElementById(panelId); if (!panel) return; const scope = btn.closest("[data-casinos-table]") || document; // close all others in same scope qsa('button[aria-label="More Info"][aria-controls]', scope).forEach((b) => { if (b === btn) return; const otherId = b.getAttribute("aria-controls"); const otherPanel = otherId ? document.getElementById(otherId) : null; if (otherPanel) { otherPanel.hidden = true; otherPanel.classList.remove("style"); // , // : hidden } b.setAttribute("aria-expanded", "false"); }); const expanded = btn.getAttribute("aria-expanded") === "true"; btn.setAttribute("aria-expanded", expanded ? "false" : "true"); if (expanded) { panel.hidden = true; panel.style.removeProperty("display"); } else { panel.hidden = false; panel.style.setProperty("display", "block", "important"); } }); // --------------------------- // 4) Go top button // --------------------------- const goTop = qs("#go-top-elem"); const updateGoTop = () => { if (!goTop) return; const y = window.scrollY || document.documentElement.scrollTop || 0; if (y >= 100) goTop.setAttribute("data-shown", "true"); else goTop.removeAttribute("data-shown"); }; document.addEventListener("scroll", updateGoTop, { passive: true }); updateGoTop(); window.scrollToStart = function () { const reduce = window.matchMedia?.("(prefers-reduced-motion: reduce)")?.matches; window.scrollTo({ top: 0, behavior: reduce ? "auto" : "smooth" }); }; // --------------------------- // 5) Nav dropdown buttons (#nav button) // --------------------------- qsa("#nav button[aria-haspopup='menu']").forEach((btn) => { btn.addEventListener("click", (e) => { e.stopPropagation(); // close others qsa("#nav button[aria-haspopup='menu']").forEach((b) => { if (b !== btn) { b.removeAttribute("data-open"); const ctl = b.querySelector("[aria-expanded]"); if (ctl) ctl.setAttribute("aria-expanded", "false"); } }); const open = btn.getAttribute("data-open") === "true"; btn.setAttribute("data-open", open ? "false" : "true"); const ctl = btn.querySelector("[aria-expanded]"); if (ctl) ctl.setAttribute("aria-expanded", open ? "false" : "true"); }); }); document.addEventListener("click", (e) => { if (!e.target.closest("#nav")) { qsa("#nav button[aria-haspopup='menu']").forEach((b) => { b.removeAttribute("data-open"); const ctl = b.querySelector("[aria-expanded]"); if (ctl) ctl.setAttribute("aria-expanded", "false"); }); } }); document.addEventListener("keydown", (e) => { if (e.key !== "Escape") return; qsa("#nav button[aria-haspopup='menu']").forEach((b) => { b.removeAttribute("data-open"); const ctl = b.querySelector("[aria-expanded]"); if (ctl) ctl.setAttribute("aria-expanded", "false"); }); }); // --------------------------- // NAVIGATION section (#nav) open/close // --------------------------- document.addEventListener("click", (e) => { const btn = e.target.closest("#nav button"); if (!btn) return; const nav = document.getElementById("nav"); if (!nav) return; const isOpen = nav.getAttribute("data-open") === "true"; nav.setAttribute("data-open", isOpen ? "false" : "true"); }); document.addEventListener("keydown", (e) => { if (e.key !== "Escape") return; const nav = document.getElementById("nav"); if (!nav) return; nav.setAttribute("data-open", "false"); }); // --------------------------- // 6) Form submit lock (data-submit) // --------------------------- const form = qs('[data-elem="form"]'); if (form) { form.addEventListener("submit", (e) => { e.preventDefault(); form.setAttribute("data-submit", "true"); }); } // ? : footer-svg.txt loader });