185 lines
5.3 KiB
JavaScript
185 lines
5.3 KiB
JavaScript
(function() {
|
|
'use strict';
|
|
|
|
// Navigation scroll effect
|
|
const nav = document.querySelector('.nav');
|
|
|
|
function handleNavScroll() {
|
|
if (window.pageYOffset > 100) {
|
|
nav.classList.add('scrolled');
|
|
} else {
|
|
nav.classList.remove('scrolled');
|
|
}
|
|
}
|
|
|
|
// Mobile menu toggle
|
|
const navToggle = document.querySelector('.nav__toggle');
|
|
const navMenu = document.querySelector('.nav__menu');
|
|
|
|
function toggleMenu() {
|
|
const isExpanded = navToggle.getAttribute('aria-expanded') === 'true';
|
|
navToggle.setAttribute('aria-expanded', !isExpanded);
|
|
navMenu.classList.toggle('active');
|
|
document.body.style.overflow = !isExpanded ? 'hidden' : '';
|
|
|
|
if (!isExpanded) {
|
|
navToggle.setAttribute('aria-label', 'סגור תפריט ניווט');
|
|
} else {
|
|
navToggle.setAttribute('aria-label', 'פתח תפריט ניווט');
|
|
}
|
|
}
|
|
|
|
navToggle.addEventListener('click', toggleMenu);
|
|
|
|
// Close menu on link click
|
|
navMenu.querySelectorAll('a').forEach(link => {
|
|
link.addEventListener('click', () => {
|
|
if (navMenu.classList.contains('active')) {
|
|
toggleMenu();
|
|
}
|
|
});
|
|
});
|
|
|
|
// Close menu on escape
|
|
document.addEventListener('keydown', (e) => {
|
|
if (e.key === 'Escape' && navMenu.classList.contains('active')) {
|
|
toggleMenu();
|
|
navToggle.focus();
|
|
}
|
|
});
|
|
|
|
// Trap focus in mobile menu
|
|
navMenu.addEventListener('keydown', (e) => {
|
|
if (!navMenu.classList.contains('active')) return;
|
|
|
|
const focusable = navMenu.querySelectorAll('a');
|
|
const first = focusable[0];
|
|
const last = focusable[focusable.length - 1];
|
|
|
|
if (e.key === 'Tab') {
|
|
if (e.shiftKey && document.activeElement === first) {
|
|
e.preventDefault();
|
|
last.focus();
|
|
} else if (!e.shiftKey && document.activeElement === last) {
|
|
e.preventDefault();
|
|
first.focus();
|
|
}
|
|
}
|
|
});
|
|
|
|
// Scroll reveal
|
|
function initReveal() {
|
|
const revealElements = document.querySelectorAll('[data-reveal]');
|
|
const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
|
|
if (prefersReducedMotion) {
|
|
revealElements.forEach(el => el.classList.add('revealed'));
|
|
return;
|
|
}
|
|
|
|
const observer = new IntersectionObserver((entries) => {
|
|
entries.forEach(entry => {
|
|
if (entry.isIntersecting) {
|
|
entry.target.classList.add('revealed');
|
|
observer.unobserve(entry.target);
|
|
}
|
|
});
|
|
}, {
|
|
threshold: 0.1,
|
|
rootMargin: '0px 0px -50px 0px'
|
|
});
|
|
|
|
revealElements.forEach(el => observer.observe(el));
|
|
}
|
|
|
|
// Form handling
|
|
function initForms() {
|
|
const forms = document.querySelectorAll('.booking__form, .contact__form');
|
|
|
|
forms.forEach(form => {
|
|
form.addEventListener('submit', (e) => {
|
|
e.preventDefault();
|
|
|
|
const btn = form.querySelector('button[type="submit"]');
|
|
const originalText = btn.textContent;
|
|
|
|
btn.textContent = 'שולח...';
|
|
btn.disabled = true;
|
|
btn.setAttribute('aria-busy', 'true');
|
|
|
|
// Simulate form submission
|
|
setTimeout(() => {
|
|
btn.textContent = 'נשלח בהצלחה!';
|
|
btn.style.background = '#4a9c6d';
|
|
btn.setAttribute('aria-busy', 'false');
|
|
|
|
// Announce to screen readers
|
|
const announcement = document.createElement('div');
|
|
announcement.setAttribute('role', 'status');
|
|
announcement.setAttribute('aria-live', 'polite');
|
|
announcement.className = 'sr-only';
|
|
announcement.textContent = 'הטופס נשלח בהצלחה';
|
|
form.appendChild(announcement);
|
|
|
|
setTimeout(() => {
|
|
form.reset();
|
|
btn.textContent = originalText;
|
|
btn.style.background = '';
|
|
btn.disabled = false;
|
|
announcement.remove();
|
|
}, 2000);
|
|
}, 1000);
|
|
});
|
|
});
|
|
}
|
|
|
|
// Set minimum date for booking
|
|
function initDateInput() {
|
|
const dateInput = document.querySelector('#book-date');
|
|
if (dateInput) {
|
|
const today = new Date();
|
|
const tomorrow = new Date(today);
|
|
tomorrow.setDate(tomorrow.getDate() + 1);
|
|
dateInput.min = tomorrow.toISOString().split('T')[0];
|
|
}
|
|
}
|
|
|
|
// Smooth scroll for anchor links
|
|
function initSmoothScroll() {
|
|
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
|
|
anchor.addEventListener('click', function(e) {
|
|
const targetId = this.getAttribute('href');
|
|
if (targetId === '#') return;
|
|
|
|
const target = document.querySelector(targetId);
|
|
if (target) {
|
|
e.preventDefault();
|
|
const navHeight = nav.offsetHeight;
|
|
const targetPosition = target.getBoundingClientRect().top + window.pageYOffset - navHeight;
|
|
|
|
window.scrollTo({
|
|
top: targetPosition,
|
|
behavior: 'smooth'
|
|
});
|
|
|
|
// Set focus for accessibility
|
|
target.setAttribute('tabindex', '-1');
|
|
target.focus({ preventScroll: true });
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
// Initialize
|
|
window.addEventListener('scroll', handleNavScroll, { passive: true });
|
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
handleNavScroll();
|
|
initReveal();
|
|
initForms();
|
|
initDateInput();
|
|
initSmoothScroll();
|
|
});
|
|
|
|
})();
|