(function() { 'use strict'; // Mobile navigation toggle const navToggle = document.querySelector('.nav-toggle'); const navLinks = document.querySelector('.nav-links'); if (navToggle && navLinks) { navToggle.addEventListener('click', function() { const isActive = navLinks.classList.toggle('active'); navToggle.classList.toggle('active'); navToggle.setAttribute('aria-expanded', isActive); // Trap focus in mobile menu when open if (isActive) { navLinks.querySelector('a').focus(); } }); // Close menu on link click navLinks.querySelectorAll('a').forEach(function(link) { link.addEventListener('click', function() { navLinks.classList.remove('active'); navToggle.classList.remove('active'); navToggle.setAttribute('aria-expanded', 'false'); }); }); // Close menu on outside click document.addEventListener('click', function(e) { if (!navToggle.contains(e.target) && !navLinks.contains(e.target)) { navLinks.classList.remove('active'); navToggle.classList.remove('active'); navToggle.setAttribute('aria-expanded', 'false'); } }); // Close menu on Escape document.addEventListener('keydown', function(e) { if (e.key === 'Escape' && navLinks.classList.contains('active')) { navLinks.classList.remove('active'); navToggle.classList.remove('active'); navToggle.setAttribute('aria-expanded', 'false'); navToggle.focus(); } }); } // Scroll reveal animation const revealElements = document.querySelectorAll('.reveal'); if (revealElements.length > 0 && 'IntersectionObserver' in window) { const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches; if (prefersReducedMotion) { revealElements.forEach(function(el) { el.classList.add('visible'); }); } else { const revealObserver = new IntersectionObserver(function(entries) { entries.forEach(function(entry) { if (entry.isIntersecting) { entry.target.classList.add('visible'); revealObserver.unobserve(entry.target); } }); }, { threshold: 0.15, rootMargin: '0px 0px -40px 0px' }); revealElements.forEach(function(el) { revealObserver.observe(el); }); } } else { revealElements.forEach(function(el) { el.classList.add('visible'); }); } // 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(); const header = document.querySelector('.site-header'); const headerHeight = header ? header.offsetHeight : 0; const targetPosition = target.getBoundingClientRect().top + window.pageYOffset - headerHeight - 20; window.scrollTo({ top: targetPosition, behavior: 'smooth' }); // Set focus for accessibility target.setAttribute('tabindex', '-1'); target.focus({ preventScroll: true }); } }); }); // Form handling (demo only) const contactForm = document.getElementById('contact-form'); if (contactForm) { contactForm.addEventListener('submit', function(e) { e.preventDefault(); const submitBtn = this.querySelector('button[type="submit"]'); const originalText = submitBtn.textContent; // Basic validation const name = this.querySelector('#name'); const phone = this.querySelector('#phone'); if (!name.value.trim() || !phone.value.trim()) { return; } submitBtn.textContent = 'שולח...'; submitBtn.disabled = true; // Simulate submission setTimeout(function() { submitBtn.textContent = 'נשלח בהצלחה ✓'; submitBtn.style.background = '#4a7c59'; setTimeout(function() { submitBtn.textContent = originalText; submitBtn.style.background = ''; submitBtn.disabled = false; contactForm.reset(); }, 2500); }, 800); }); } // Header shadow on scroll const header = document.querySelector('.site-header'); if (header) { let ticking = false; window.addEventListener('scroll', function() { if (!ticking) { window.requestAnimationFrame(function() { if (window.pageYOffset > 50) { header.style.boxShadow = '0 2px 20px rgba(0,0,0,0.08)'; } else { header.style.boxShadow = 'none'; } ticking = false; }); ticking = true; } }, { passive: true }); } })();