(function() { 'use strict'; // Mobile Navigation Toggle const navToggle = document.querySelector('.nav__toggle'); const navMenu = document.querySelector('.nav__menu'); if (navToggle && navMenu) { navToggle.addEventListener('click', function() { const isOpen = navMenu.classList.toggle('is-open'); navToggle.classList.toggle('is-open'); navToggle.setAttribute('aria-expanded', isOpen); }); // Close menu when clicking a link navMenu.querySelectorAll('a').forEach(function(link) { link.addEventListener('click', function() { navMenu.classList.remove('is-open'); navToggle.classList.remove('is-open'); navToggle.setAttribute('aria-expanded', 'false'); }); }); // Close menu on escape key document.addEventListener('keydown', function(e) { if (e.key === 'Escape' && navMenu.classList.contains('is-open')) { navMenu.classList.remove('is-open'); navToggle.classList.remove('is-open'); navToggle.setAttribute('aria-expanded', 'false'); navToggle.focus(); } }); } // Reveal on Scroll const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches; if (!prefersReducedMotion) { const revealElements = document.querySelectorAll('.reveal'); const revealObserver = new IntersectionObserver(function(entries) { entries.forEach(function(entry) { if (entry.isIntersecting) { entry.target.classList.add('revealed'); revealObserver.unobserve(entry.target); } }); }, { threshold: 0.1, rootMargin: '0px 0px -50px 0px' }); revealElements.forEach(function(el) { revealObserver.observe(el); }); } else { // If reduced motion is preferred, reveal all elements immediately document.querySelectorAll('.reveal').forEach(function(el) { el.classList.add('revealed'); }); } // Smooth scroll for anchor links document.querySelectorAll('a[href^="#"]').forEach(function(anchor) { anchor.addEventListener('click', function(e) { const targetId = this.getAttribute('href'); if (targetId === '#') return; const target = document.querySelector(targetId); if (target) { e.preventDefault(); target.scrollIntoView({ behavior: prefersReducedMotion ? 'auto' : 'smooth', block: 'start' }); // Set focus to target for accessibility target.setAttribute('tabindex', '-1'); target.focus({ preventScroll: true }); } }); }); // Form submission handling const bookingForm = document.querySelector('.booking__form'); if (bookingForm) { bookingForm.addEventListener('submit', function(e) { e.preventDefault(); // Get form data const formData = new FormData(this); const data = Object.fromEntries(formData.entries()); // Simple validation const requiredFields = ['name', 'phone', 'service', 'date', 'time']; const missingFields = requiredFields.filter(function(field) { return !data[field]; }); if (missingFields.length > 0) { const firstMissing = bookingForm.querySelector('[name="' + missingFields[0] + '"]'); if (firstMissing) { firstMissing.focus(); firstMissing.reportValidity(); } return; } // Simulate submission const submitBtn = this.querySelector('button[type="submit"]'); const originalText = submitBtn.textContent; submitBtn.textContent = 'שולח...'; submitBtn.disabled = true; setTimeout(function() { alert('תודה! הבקשה שלך התקבלה. ניצור איתך קשר בהקדם לאישור התור.'); bookingForm.reset(); submitBtn.textContent = originalText; submitBtn.disabled = false; }, 1500); }); } // Set minimum date to today for date input const dateInput = document.querySelector('input[type="date"]'); if (dateInput) { const today = new Date().toISOString().split('T')[0]; dateInput.setAttribute('min', today); } // Add scroll-based nav background const nav = document.querySelector('.nav'); let ticking = false; window.addEventListener('scroll', function() { if (!ticking) { window.requestAnimationFrame(function() { const currentScroll = window.pageYOffset; if (currentScroll > 100) { nav.style.background = 'rgba(13, 13, 13, 0.98)'; } else { nav.style.background = 'rgba(13, 13, 13, 0.9)'; } ticking = false; }); ticking = true; } }, { passive: true }); // Update copyright year const yearSpan = document.getElementById('current-year'); if (yearSpan) { yearSpan.textContent = new Date().getFullYear(); } })();