document.addEventListener("DOMContentLoaded", function () { // MODAL JS const openModalButtons = document.querySelectorAll(".open-modal"); const closeModalButtons = document.querySelectorAll(".close-modal"); const modals = document.querySelectorAll(".modal"); let lastFocusedButton = null; openModalButtons.forEach(button => { button.addEventListener("click", (e) => { e.preventDefault(); const modalId = button.getAttribute("data-modal"); const modal = document.querySelector(modalId); modal.style.display = "block"; lastFocusedButton = button; const closeBtn = modal.querySelector(".close-modal"); if (closeBtn) closeBtn.focus(); }); }); closeModalButtons.forEach(button => { button.addEventListener("click", () => { const modal = button.closest(".modal"); modal.style.display = "none"; if (lastFocusedButton) lastFocusedButton.focus(); }); button.addEventListener("keydown", (e) => { if (e.key === "Enter" || e.key === " " || e.key === "Spacebar") { e.preventDefault(); const modal = button.closest(".modal"); modal.style.display = "none"; if (lastFocusedButton) lastFocusedButton.focus(); } }); }); window.addEventListener("click", (e) => { if (e.target.classList.contains("modal")) { e.target.style.display = "none"; if (lastFocusedButton) lastFocusedButton.focus(); } }); // PAGINATION JS let currentSlide = 0; const slides = document.querySelectorAll(".slide"); const dots = document.querySelectorAll(".dot"); function showSlide(index) { slides.forEach((slide, i) => { slide.classList.toggle("active", i === index); dots[i].classList.toggle("active", i === index); }); currentSlide = index; } setInterval(() => { let nextSlide = (currentSlide + 1) % slides.length; showSlide(nextSlide); }, 5000); // CONTACT US BUTTON - ALERT const contactForm = document.getElementById("contact-form"); if (contactForm) { contactForm.removeEventListener("submit", handleFormSubmit); contactForm.addEventListener("submit", handleFormSubmit); } }); function handleFormSubmit(event) { event.preventDefault(); alert(beanheavenStrings.contactSuccess); document.getElementById("contact-form").reset(); } document.querySelectorAll('a[href^="#"]').forEach(anchor => { anchor.addEventListener('click', function (e) { e.preventDefault(); const targetId = this.getAttribute('href'); const targetSection = document.querySelector(targetId); if (targetSection) { targetSection.scrollIntoView({ behavior: 'smooth', block: 'start' }); } }); });