/* TROK Mobilya — frontend interactions (vanilla, no dependencies) */ (function () { "use strict"; /* --- Mobile menu --- */ var toggle = document.querySelector(".nav-toggle"); var menu = document.querySelector(".mobile-menu"); if (toggle && menu) { toggle.addEventListener("click", function () { var open = menu.classList.toggle("open"); toggle.classList.toggle("is-open", open); toggle.setAttribute("aria-expanded", open ? "true" : "false"); document.body.style.overflow = open ? "hidden" : ""; }); menu.querySelectorAll("a").forEach(function (a) { a.addEventListener("click", function () { menu.classList.remove("open"); document.body.style.overflow = ""; }); }); } /* --- Scroll reveal --- */ var reveals = document.querySelectorAll(".reveal"); if ("IntersectionObserver" in window && reveals.length) { var io = new IntersectionObserver( function (entries) { entries.forEach(function (e) { if (e.isIntersecting) { e.target.classList.add("in"); io.unobserve(e.target); } }); }, { threshold: 0.12, rootMargin: "0px 0px -8% 0px" } ); reveals.forEach(function (el) { io.observe(el); }); } else { reveals.forEach(function (el) { el.classList.add("in"); }); } /* --- Hero slider --- */ var hero = document.querySelector("[data-slider]"); if (hero) { var slides = hero.querySelectorAll(".hero-slide"); var dots = hero.querySelectorAll(".hero-dots button"); var i = 0, timer = null; if (slides.length > 1) { var go = function (n) { slides[i].classList.remove("active"); if (dots[i]) dots[i].classList.remove("active"); i = (n + slides.length) % slides.length; slides[i].classList.add("active"); if (dots[i]) dots[i].classList.add("active"); }; var start = function () { timer = setInterval(function () { go(i + 1); }, 6000); }; var reset = function () { clearInterval(timer); start(); }; dots.forEach(function (d, n) { d.addEventListener("click", function () { go(n); reset(); }); }); start(); } } /* --- Product gallery thumbnails --- */ var main = document.querySelector("[data-pd-main]"); if (main) { document.querySelectorAll("[data-pd-thumb]").forEach(function (t) { t.addEventListener("click", function () { main.src = t.getAttribute("data-full") || t.src; }); }); } })();