test1

/** * WordPress-Compatible Website Template * This JavaScript is designed to be easily integrated with WordPress */ document.addEventListener("DOMContentLoaded", () => { // Mobile Menu Toggle const menuToggle = document.querySelector(".menu-toggle") const primaryMenu = document.querySelector(".primary-menu") if (menuToggle && primaryMenu) { menuToggle.addEventListener("click", () => { primaryMenu.classList.toggle("active") menuToggle.setAttribute("aria-expanded", menuToggle.getAttribute("aria-expanded") === "true" ? "false" : "true") }) } // Back to Top Button const backToTopButton = document.querySelector(".back-to-top") if (backToTopButton) { window.addEventListener("scroll", () => { if (window.pageYOffset > 300) { backToTopButton.classList.add("active") } else { backToTopButton.classList.remove("active") } }) backToTopButton.addEventListener("click", (e) => { e.preventDefault() window.scrollTo({ top: 0, behavior: "smooth" }) }) } // Contact Form Submission - Added null checks const contactForm = document.getElementById("contactForm") if (contactForm) { contactForm.addEventListener("submit", (e) => { e.preventDefault() // Get form values with null checks const nameInput = document.getElementById("name") const emailInput = document.getElementById("email") const subjectInput = document.getElementById("subject") const messageInput = document.getElementById("message") const name = nameInput ? nameInput.value : "" const email = emailInput ? emailInput.value : "" const subject = subjectInput ? subjectInput.value : "" const message = messageInput ? messageInput.value : "" // In a real implementation, you would send this data to your server console.log("Form submitted:", { name, email, subject, message }) // Show success message (in a real implementation) alert("Thank you for your message. We will get back to you soon!") // Reset form contactForm.reset() }) } // Newsletter Form Submission - Added null checks const newsletterForm = document.querySelector(".newsletter-form") if (newsletterForm) { newsletterForm.addEventListener("submit", (e) => { e.preventDefault() // Get email value with null check const emailInput = newsletterForm.querySelector('input[type="email"]') const email = emailInput ? emailInput.value : "" // In a real implementation, you would send this data to your server console.log("Newsletter subscription:", email) // Show success message (in a real implementation) alert("Thank you for subscribing to our newsletter!") // Reset form newsletterForm.reset() }) } // Simple Testimonial Slider - Completely rewritten with proper null checks const testimonialContainer = document.querySelector(".testimonials-slider") if (testimonialContainer) { const testimonialCards = testimonialContainer.querySelectorAll(".testimonial-card") let currentTestimonial = 0 // Only proceed if we have testimonial cards if (testimonialCards && testimonialCards.length > 0) { // Function to show current testimonial on mobile function showCurrentTestimonial() { if (window.innerWidth < 768) { testimonialCards.forEach((card, index) => { if (card) { if (index === currentTestimonial) { card.style.display = "block" } else { card.style.display = "none" } } }) } else { // On desktop, show all testimonials testimonialCards.forEach((card) => { if (card) { card.style.display = "block" } }) } } // Initialize testimonial display showCurrentTestimonial() // Set up auto-rotation for mobile only if (window.innerWidth < 768 && testimonialCards.length > 1) { setInterval(() => { currentTestimonial = (currentTestimonial + 1) % testimonialCards.length showCurrentTestimonial() }, 5000) } // Handle window resize window.addEventListener("resize", showCurrentTestimonial) } } })

Comments