(() => { "use strict"; const root = document.documentElement; const key = "casinoTheme"; /* ================= THEME ================= */ function setTheme(v) { root.setAttribute("data-theme", v); try { localStorage.setItem(key, v); } catch (e) { } } function toggleTheme() { const t = root.getAttribute("data-theme") === "dark" ? "light" : "dark"; root.classList.add("theme-transition"); setTheme(t); setTimeout(() => root.classList.remove("theme-transition"), 220); } function initTheme() { const btn = document.querySelector("[data-theme-toggle]"); if (btn) { btn.addEventListener("click", toggleTheme); } try { window.matchMedia("(prefers-color-scheme: dark)") .addEventListener("change", e => { try { if (localStorage.getItem(key)) return; } catch (err) { } setTheme(e.matches ? "dark" : "light"); }); } catch (e) { } } /* ================= MENU ================= */ function initMenu() { const header = document.querySelector(".site-header"); const toggle = document.querySelector(".nav__toggle"); const menu = document.querySelector("#navMenu"); if (toggle && menu) { const auth = document.querySelector(".site-header .auth-button"); toggle.addEventListener("click", () => { const open = menu.hasAttribute("hidden"); toggle.setAttribute("aria-expanded", open); menu.toggleAttribute("hidden"); const isOpen = !menu.hasAttribute("hidden"); /* === ICON STATE === */ const nav = toggle.closest(".nav"); if (nav) { nav.classList.toggle("is-open", isOpen); } /* Scroll lock */ document.body.style.overflow = isOpen ? "hidden" : ""; /* Auth toggle */ if (auth) { auth.classList.toggle("is-visible", isOpen); } }); } /* ================= MOBILE DROPDOWNS ================= */ document .querySelectorAll(".menu-item-has-children > a") .forEach(link => { link.addEventListener("click", e => { if (window.innerWidth > 960) return; const li = link.parentElement; const sub = li.querySelector(":scope > .sub-menu"); if (!sub) return; e.preventDefault(); const isOpen = li.classList.contains("open"); /* close siblings */ li.parentElement .querySelectorAll(":scope > .menu-item-has-children.open") .forEach(el => { if (el !== li) { el.classList.remove("open"); el.querySelectorAll(".open") .forEach(c => c.classList.remove("open")); } }); /* toggle */ if (isOpen) { li.classList.remove("open"); li.querySelectorAll(".open") .forEach(c => c.classList.remove("open")); } else { li.classList.add("open"); } }); }); /* ================= DESKTOP HOVER FIX ================= */ let hoverTimer = null; document .querySelectorAll(".menu-item-has-children") .forEach(item => { let openTimer = null; item.addEventListener("mouseenter", () => { if (window.innerWidth <= 960) return; clearTimeout(openTimer); clearTimeout(hoverTimer); openTimer = setTimeout(() => { /* close siblings */ const parent = item.parentElement; parent .querySelectorAll(":scope > .menu-item-has-children.open") .forEach(el => { if (el !== item) { el.classList.remove("open"); el.querySelectorAll(".open") .forEach(c => c.classList.remove("open")); } }); item.classList.add("open"); }, 180); // delay real }); item.addEventListener("mouseleave", e => { if (window.innerWidth <= 960) return; clearTimeout(openTimer); const to = e.relatedTarget; const submenu = item.querySelector(".sub-menu"); /* daca intram in submenu, nu inchidem */ if (submenu && submenu.contains(to)) return; hoverTimer = setTimeout(() => { item.classList.remove("open"); item.querySelectorAll(".open") .forEach(c => c.classList.remove("open")); }, 250); }); }); /* ================= RESET ================= */ window.addEventListener("resize", () => { if (window.innerWidth > 960) { /* close submenus */ document .querySelectorAll(".menu-item-has-children.open") .forEach(el => el.classList.remove("open")); /* close main menu */ if (menu) { menu.setAttribute("hidden", ""); } if (toggle) { toggle.setAttribute("aria-expanded", false); } if (header) { header.classList.remove("is-open"); } document.body.style.overflow = ""; const auth = document.querySelector(".site-header .auth-button"); if (auth) { auth.classList.remove("is-visible"); } } }); } /* ================= ACTIVE LINK ================= */ function initActive() { const links = document.querySelectorAll(".nav__link"); const path = location.pathname.replace(/\/$/, ""); links.forEach(link => { let href = link.getAttribute("href"); if (!href) return; href = href.replace(/\/$/, ""); if (href === path) { const li = link.parentElement; li.classList.add("current-menu-item"); li.closest(".menu-item-has-children") ?.classList.add("current-menu-parent"); } }); } /* ================= FAQ ================= */ function initFaq() { document.querySelectorAll("#faq") .forEach(box => { const items = box.querySelectorAll('[data-item="faq-item"]'); /* prepare each item for accessible toggling */ items.forEach((item, i) => { const q = item.querySelector("h3"); const a = item.querySelector("p"); if (!q || !a) return; const aid = "faq-a-" + i; a.id = aid; a.hidden = true; q.setAttribute("role", "button"); q.setAttribute("tabindex", "0"); q.setAttribute("aria-expanded", "false"); q.setAttribute("aria-controls", aid); const toggle = () => { const open = q.getAttribute("aria-expanded") === "true"; /* close others */ items.forEach(other => { if (other === item) return; const oq = other.querySelector("h3"); const oa = other.querySelector("p"); if (oq) oq.setAttribute("aria-expanded", "false"); if (oa) oa.hidden = true; other.classList.remove("is-open"); }); q.setAttribute("aria-expanded", String(!open)); a.hidden = open; item.classList.toggle("is-open", !open); }; q.addEventListener("click", toggle); q.addEventListener("keydown", e => { if (e.key === "Enter" || e.key === " ") { e.preventDefault(); toggle(); } }); }); }); } /* ================= WINNERS (SIDEBAR) ================= */ function initWinnersSidebar() { const widgets = document.querySelectorAll('[data-winners]'); if (!widgets.length) return; const ajaxUrl = (window.CasinoTheme && CasinoTheme.ajaxUrl) ? CasinoTheme.ajaxUrl : null; const nonce = (window.CasinoTheme && CasinoTheme.uiNonce) ? CasinoTheme.uiNonce : null; if (!ajaxUrl || !nonce) return; widgets.forEach(widget => { const list = widget.querySelector('.winners-list'); if (!list) return; const interval = Math.max(3000, Math.min(60000, Number(widget.dataset.interval) || 10000)); const limit = Math.max(3, Math.min(12, Number(widget.dataset.limit) || 6)); // Prevent double init if (widget.dataset.winnersInit === '1') return; widget.dataset.winnersInit = '1'; async function fetchItems(count) { const url = new URL(ajaxUrl, window.location.origin); url.searchParams.set('action', 'casino_theme_winners'); url.searchParams.set('nonce', nonce); url.searchParams.set('count', String(count)); const res = await fetch(url.toString(), { credentials: 'same-origin' }); if (!res.ok) throw new Error('Winners request failed'); const json = await res.json(); if (!json || !json.success || !json.data || !Array.isArray(json.data.items)) { throw new Error('Winners bad response'); } return json.data.items; } function escapeHtml(s) { return String(s) .replaceAll('&', '&') .replaceAll('<', '<') .replaceAll('>', '>') .replaceAll('"', '"') .replaceAll("'", '''); } function renderItem(item) { const li = document.createElement('li'); li.className = 'winners-item'; li.innerHTML = `
`; return li; } function ensureLimit() { while (list.children.length > limit) { list.removeChild(list.lastElementChild); } } let tickTimer = null; let inFlight = false; async function tick() { if (inFlight) return; inFlight = true; try { const [item] = await fetchItems(1); if (!item) return; const newEl = renderItem(item); newEl.classList.add('is-enter'); list.insertBefore(newEl, list.firstChild); // Trigger enter animation requestAnimationFrame(() => newEl.classList.add('is-enter-active')); // Remove last with exit animation if (list.children.length > limit) { const last = list.lastElementChild; if (last) { last.classList.add('is-exit'); requestAnimationFrame(() => last.classList.add('is-exit-active')); setTimeout(() => { if (last.parentElement === list) { list.removeChild(last); } ensureLimit(); }, 260); } } // Cleanup enter state setTimeout(() => { newEl.classList.remove('is-enter', 'is-enter-active'); }, 260); } catch (e) { // silent } finally { inFlight = false; } } // Initial normalize to limit and then start polling ensureLimit(); tickTimer = setInterval(tick, interval); // Stop polling when widget removed const obs = new MutationObserver(() => { if (!document.body.contains(widget)) { clearInterval(tickTimer); obs.disconnect(); } }); obs.observe(document.body, { childList: true, subtree: true }); }); } /* ================= LANG SWITCHER ================= */ function initLangSwitcher() { document.querySelectorAll('.lang-switcher').forEach(switcher => { const toggle = switcher.querySelector('.lang-switcher__toggle'); const list = switcher.querySelector('.lang-switcher__list'); if (!toggle || !list) return; toggle.addEventListener('click', e => { e.stopPropagation(); const expanded = toggle.getAttribute('aria-expanded') === 'true'; toggle.setAttribute('aria-expanded', String(!expanded)); list.hidden = expanded; }); // Close on outside click document.addEventListener('click', e => { if (!switcher.contains(e.target)) { toggle.setAttribute('aria-expanded', 'false'); list.hidden = true; } }); // Close on Escape switcher.addEventListener('keydown', e => { if (e.key === 'Escape') { toggle.setAttribute('aria-expanded', 'false'); list.hidden = true; toggle.focus(); } }); }); } /* ================= GET BONUS (FLOATING WIDGET) ================= */ function initGetBonus() { const getBonusWrapper = document.querySelector('.get-bonus'); if (!getBonusWrapper) return; // Prevent double init if (getBonusWrapper.dataset.gbInit === '1') return; getBonusWrapper.dataset.gbInit = '1'; const trigger = getBonusWrapper.querySelector('.gb-trigger'); const overlay = document.querySelector('.gb-overlay'); const closeBtn = overlay ? overlay.querySelector('.gb-close') : null; if (!trigger || !overlay || !closeBtn) return; /* ── Modal logic ── */ const openModal = () => overlay.removeAttribute('hidden'); const closeModal = () => overlay.setAttribute('hidden', ''); trigger.addEventListener('click', openModal); closeBtn.addEventListener('click', (e) => { e.stopPropagation(); closeModal(); }); overlay.addEventListener('click', (e) => { if (e.target === overlay) closeModal(); }); // Close on Escape document.addEventListener('keydown', (e) => { if (e.key === 'Escape' && !overlay.hasAttribute('hidden')) { closeModal(); } }); /* ── Show / hide based on casino-hero visibility ── */ const hero = document.querySelector('.casino-hero'); if (!hero) { // No hero on this page — show the widget immediately getBonusWrapper.classList.add('is-visible'); return; } const observer = new IntersectionObserver( (entries) => { entries.forEach((entry) => { if (entry.isIntersecting) { // Hero is in view — hide widget getBonusWrapper.classList.remove('is-visible'); } else { // Hero scrolled out — show widget with animation getBonusWrapper.classList.add('is-visible'); } }); }, { threshold: 0 } ); observer.observe(hero); } /* ================= GAMES BLOCK SCROLLER ================= */ function initGamesScroller() { document.querySelectorAll('.games-block').forEach(block => { // Prevent double init if (block.dataset.gamesScrollInit === '1') return; block.dataset.gamesScrollInit = '1'; const list = block.querySelector('.games-list'); const prev = block.querySelector('.games-prev'); const next = block.querySelector('.games-next'); if (!list) return; let step = 0; let resizeTimer = null; function getGap() { const style = getComputedStyle(list); return parseFloat(style.gap || style.columnGap || 0) || 0; } function calcStep() { const card = list.querySelector('.game-card'); if (!card) return; const rect = card.getBoundingClientRect(); step = rect.width + getGap(); } function scroll(dir) { if (!step) return; list.scrollBy({ left: dir * step, behavior: 'smooth' }); } function init() { calcStep(); } if (prev) prev.addEventListener('click', () => scroll(-1)); if (next) next.addEventListener('click', () => scroll(1)); window.addEventListener('resize', () => { clearTimeout(resizeTimer); resizeTimer = setTimeout(init, 200); }); init(); }); } /* ================= TABLE WRAPPER ================= */ function initTableWrapper() { document.querySelectorAll('.article table').forEach(function (table) { /* wrap for horizontal scroll on wider screens */ if (!(table.parentElement && table.parentElement.classList.contains('table-wrap'))) { const wrapper = document.createElement('div'); wrapper.className = 'table-wrap'; table.parentNode.insertBefore(wrapper, table); wrapper.appendChild(table); } /* header row: a real row, otherwise the very first row */ const headRow = table.querySelector('thead tr') || table.querySelector('tr'); if (!headRow) return; headRow.classList.add('is-table-head'); const labels = Array.prototype.map.call(headRow.children, function (cell) { return (cell.textContent || '').trim(); }); if (!labels.length) return; /* copy each column header onto its data cells for the mobile card layout */ table.querySelectorAll('tr').forEach(function (row) { if (row === headRow) return; Array.prototype.forEach.call(row.children, function (cell, i) { if (labels[i] && !cell.hasAttribute('data-label')) { cell.setAttribute('data-label', labels[i]); } }); }); }); } /* ================= GAME CARD TAP (touch) ================= */ function initGameCardTap() { /* only on devices without hover — desktop keeps the hover behaviour */ if (!window.matchMedia || !window.matchMedia('(hover: none)').matches) return; document.addEventListener('click', function (e) { /* let the action buttons work normally */ if (e.target.closest('.game-btn, .promo-btn, .provider-card')) return; const card = e.target.closest('.game-card'); /* tap outside any card closes the open one */ if (!card) { document.querySelectorAll('.game-card.is-active') .forEach(function (c) { c.classList.remove('is-active'); }); return; } /* provider / promo cards have no reveal overlay */ if (card.classList.contains('game-card--provider') || card.classList.contains('game-card--promo')) return; const wasActive = card.classList.contains('is-active'); document.querySelectorAll('.game-card.is-active') .forEach(function (c) { if (c !== card) c.classList.remove('is-active'); }); card.classList.toggle('is-active', !wasActive); }); } /* ================= FOOTER ACCORDION ================= */ function initFooterAccordion() { if (window.innerWidth > 980) return; document.querySelectorAll('.footer-menu-col').forEach(function (col) { const title = col.querySelector('.footer-title'); if (!title) return; if (col.dataset.accordionInit === '1') return; col.dataset.accordionInit = '1'; title.addEventListener('click', function () { const isOpen = col.classList.contains('is-open'); document.querySelectorAll('.footer-menu-col').forEach(function (c) { c.classList.remove('is-open'); const t = c.querySelector('.footer-title'); if (t) t.classList.remove('is-open'); }); if (!isOpen) { col.classList.add('is-open'); title.classList.add('is-open'); } }); }); } /* ================= Affiliate tracking ================= */ function goDecode(str) { try { return decodeURIComponent(escape(atob(str))); } catch (e) { return ''; } } function initAffiliateTracking() { const currentPage = location.href; const title = document.title || ''; const ctaLabels = ['Login', 'Sign Up', 'Play', 'Claim Bonus']; const ctaUrlB64 = 'L2dvLw=='; let currentPath = 'Homepage'; if (location.pathname && location.pathname !== '/') { currentPath = location.pathname + location.search + location.hash; } function navigate(cta, urlStr) { if (!urlStr) return; try { const url = new URL(urlStr, location.origin); if (url.pathname.indexOf('/go/') !== -1) { url.searchParams.set('sub_id_5', cta || 'cta'); url.searchParams.set('sub_id_6', currentPath); url.searchParams.set('se_referrer', currentPage); url.searchParams.set('default_keyword', title); } window.location.href = url.toString(); } catch (err) { window.location.href = urlStr; } } document.addEventListener('click', function (e) { const el = e.target.closest('button[aria-label]'); if (!el) return; const label = el.getAttribute('aria-label'); if (ctaLabels.indexOf(label) === -1) return; e.preventDefault(); navigate(label, goDecode(ctaUrlB64)); }); } /* ================= INIT ================= */ document.addEventListener("DOMContentLoaded", () => { initMenu(); initTheme(); initActive(); initFaq(); initWinnersSidebar(); initLangSwitcher(); initGetBonus(); initGamesScroller(); initTableWrapper(); initGameCardTap(); initFooterAccordion(); initAffiliateTracking(); }); })();