(function () { 'use strict'; const config = window.COSPLAY_CONFIG || {}; const swiper = document.getElementById('swiper'); const dots = document.getElementById('dots'); const slides = swiper ? Array.from(swiper.querySelectorAll('.slide')) : []; let active = 0; let timer = null; function track(eventName, source) { const body = new URLSearchParams({ event: eventName, source: source || '' }); if (navigator.sendBeacon) { navigator.sendBeacon('track.php', body); } else { fetch('track.php', { method: 'POST', body, keepalive: true, credentials: 'same-origin' }).catch(function () {}); } } function renderDots() { if (!dots) return; dots.innerHTML = ''; slides.forEach(function (_, index) { const dot = document.createElement('i'); dot.className = index === active ? 'on' : ''; dot.addEventListener('click', function () { active = index; renderSlider(); restartTimer(); }); dots.appendChild(dot); }); } function renderSlider() { slides.forEach(function (slide, index) { slide.classList.toggle('is-active', index === active); slide.classList.toggle('is-prev', index === (active - 1 + slides.length) % slides.length); slide.classList.toggle('is-next', index === (active + 1) % slides.length); }); renderDots(); } function nextSlide() { if (!slides.length) return; active = (active + 1) % slides.length; renderSlider(); } function restartTimer() { window.clearInterval(timer); timer = window.setInterval(nextSlide, 3200); } function goDownload(source, clickType) { try { track(clickType || 'cta_click', source); } catch (e) {} var path = (window.__DOWNLOAD_URL || (window.APP_CONFIG && window.APP_CONFIG.downloadPath) || '').trim(); if (!path || path.indexOf('{{') === 0) path = '#'; window.location.href = path; } document.addEventListener('click', function (event) { const cta = event.target.closest('#ctaBtn'); if (cta) { event.preventDefault(); goDownload(cta.dataset.source || 'sticky-cta', 'cta_click'); return; } const downloadTarget = event.target.closest('[data-download]'); if (downloadTarget) { event.preventDefault(); goDownload(downloadTarget.dataset.source || 'content', 'card_click'); } }); // Local page-view statistics. track('view', 'landing-page'); // Online number gently changes to keep the header lively. const onlineNum = document.getElementById('onlineNum'); if (onlineNum) { let value = 12870; window.setInterval(function () { value += Math.floor(Math.random() * 9) - 3; value = Math.max(12680, Math.min(13280, value)); onlineNum.textContent = value.toLocaleString('es-MX'); }, 2600); } // Simple touch swipe support. let startX = 0; if (swiper) { swiper.addEventListener('touchstart', function (event) { startX = event.touches[0].clientX; }, { passive: true }); swiper.addEventListener('touchend', function (event) { const diff = event.changedTouches[0].clientX - startX; if (Math.abs(diff) > 45) { active = diff < 0 ? (active + 1) % slides.length : (active - 1 + slides.length) % slides.length; renderSlider(); restartTimer(); } }, { passive: true }); } renderSlider(); restartTimer(); })();