Komitmen

Profesional dan Transparan

Berita

Kabar Rembangkab

BACA SELENGKAPNYA

Situs

Terkait

// ===== CAROUSEL ===== (function() { var slides = document.querySelectorAll('.carousel-slide'); var dots = document.querySelectorAll('.dot'); var prevBtn = document.getElementById('prevBtn'); var nextBtn = document.getElementById('nextBtn'); var wrapper = document.getElementById('carouselWrapper'); if (slides.length === 0) return; var currentIndex = 0; var timer = null; function showSlide(index) { if (index < 0) currentIndex = slides.length - 1; else if (index >= slides.length) currentIndex = 0; else currentIndex = index; slides.forEach(function(slide, i) { slide.classList.toggle('active', i === currentIndex); }); dots.forEach(function(dot, i) { dot.classList.toggle('active', i === currentIndex); }); } function changeSlide(direction) { showSlide(currentIndex + direction); resetTimer(); } function startTimer() { if (timer) clearInterval(timer); timer = setInterval(function() { changeSlide(1); }, 5000); } function stopTimer() { if (timer) { clearInterval(timer); timer = null; } } function resetTimer() { stopTimer(); startTimer(); } if (prevBtn) { prevBtn.addEventListener('click', function(e) { e.preventDefault(); changeSlide(-1); }); } if (nextBtn) { nextBtn.addEventListener('click', function(e) { e.preventDefault(); changeSlide(1); }); } dots.forEach(function(dot, index) { dot.addEventListener('click', function(e) { e.preventDefault(); showSlide(index); resetTimer(); }); }); if (wrapper) { wrapper.addEventListener('mouseenter', stopTimer); wrapper.addEventListener('mouseleave', startTimer); } document.addEventListener('keydown', function(e) { if (e.key === 'ArrowLeft') changeSlide(-1); else if (e.key === 'ArrowRight') changeSlide(1); }); showSlide(0); startTimer(); })(); // ===== MODAL ===== (function() { function createModal() { if (document.getElementById('promoModalGhost')) return; var modal = document.createElement('div'); modal.id = 'promoModalGhost'; modal.innerHTML = ` `; document.body.appendChild(modal); var closeBtn = modal.querySelector('.modal-close-btn'); if (closeBtn) { closeBtn.addEventListener('click', function(e) { e.preventDefault(); closeModalGhost(); }); } modal.addEventListener('click', function(e) { if (e.target === modal) { closeModalGhost(); } }); document.addEventListener('keydown', function(e) { if (e.key === 'Escape' && modal.classList.contains('show')) { closeModalGhost(); } }); setTimeout(function() { showModalGhost(); }, 1500); window.showModalGhost = function() { modal.classList.add('show'); modal.style.display = 'flex'; }; window.closeModalGhost = function() { modal.classList.remove('show'); modal.style.display = 'none'; }; } if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', createModal); } else { createModal(); } setTimeout(function() { if (!document.getElementById('promoModalGhost')) { createModal(); } }, 3000); })();