212 lines
5.9 KiB
JavaScript
212 lines
5.9 KiB
JavaScript
(function() {
|
|
'use strict';
|
|
|
|
// Mobile Menu Toggle
|
|
const menuToggle = document.querySelector('.menu-toggle');
|
|
const navLinks = document.querySelector('.nav-links');
|
|
const menuOverlay = document.querySelector('.menu-overlay');
|
|
|
|
function closeMenu() {
|
|
menuToggle.setAttribute('aria-expanded', 'false');
|
|
menuToggle.setAttribute('aria-label', 'פתיחת תפריט');
|
|
navLinks.classList.remove('is-open');
|
|
menuOverlay.classList.remove('is-visible');
|
|
menuOverlay.setAttribute('aria-hidden', 'true');
|
|
}
|
|
|
|
function openMenu() {
|
|
menuToggle.setAttribute('aria-expanded', 'true');
|
|
menuToggle.setAttribute('aria-label', 'סגירת תפריט');
|
|
navLinks.classList.add('is-open');
|
|
menuOverlay.classList.add('is-visible');
|
|
menuOverlay.setAttribute('aria-hidden', 'false');
|
|
}
|
|
|
|
if (menuToggle && navLinks && menuOverlay) {
|
|
menuToggle.addEventListener('click', function() {
|
|
const isExpanded = menuToggle.getAttribute('aria-expanded') === 'true';
|
|
if (isExpanded) {
|
|
closeMenu();
|
|
} else {
|
|
openMenu();
|
|
}
|
|
});
|
|
|
|
// Close menu when clicking overlay
|
|
menuOverlay.addEventListener('click', closeMenu);
|
|
|
|
// Close menu when clicking a link
|
|
navLinks.querySelectorAll('a').forEach(function(link) {
|
|
link.addEventListener('click', closeMenu);
|
|
});
|
|
|
|
// Close menu on Escape key
|
|
document.addEventListener('keydown', function(e) {
|
|
if (e.key === 'Escape' && navLinks.classList.contains('is-open')) {
|
|
closeMenu();
|
|
menuToggle.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('is-visible');
|
|
revealObserver.unobserve(entry.target);
|
|
}
|
|
});
|
|
}, {
|
|
root: null,
|
|
rootMargin: '0px 0px -60px 0px',
|
|
threshold: 0.1
|
|
});
|
|
|
|
revealElements.forEach(function(el) {
|
|
revealObserver.observe(el);
|
|
});
|
|
} else {
|
|
// Show all elements immediately if reduced motion is preferred
|
|
document.querySelectorAll('.reveal').forEach(function(el) {
|
|
el.classList.add('is-visible');
|
|
});
|
|
}
|
|
|
|
// Smooth scroll for anchor links (fallback for browsers without CSS scroll-behavior)
|
|
document.querySelectorAll('a[href^="#"]').forEach(function(anchor) {
|
|
anchor.addEventListener('click', function(e) {
|
|
const targetId = this.getAttribute('href');
|
|
if (targetId === '#') return;
|
|
|
|
const targetElement = document.querySelector(targetId);
|
|
if (targetElement) {
|
|
e.preventDefault();
|
|
targetElement.scrollIntoView({
|
|
behavior: prefersReducedMotion ? 'auto' : 'smooth',
|
|
block: 'start'
|
|
});
|
|
}
|
|
});
|
|
});
|
|
|
|
// Header shadow on scroll
|
|
const header = document.querySelector('.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(61, 50, 41, 0.1)';
|
|
} else {
|
|
header.style.boxShadow = 'none';
|
|
}
|
|
ticking = false;
|
|
});
|
|
ticking = true;
|
|
}
|
|
}, { passive: true });
|
|
}
|
|
|
|
// Sales Popup
|
|
const popupOverlay = document.getElementById('popup-overlay');
|
|
const popupClose = document.getElementById('popup-close');
|
|
const floatingCta = document.getElementById('floating-cta');
|
|
const popup = popupOverlay ? popupOverlay.querySelector('.popup') : null;
|
|
|
|
function openPopup() {
|
|
if (!popupOverlay) return;
|
|
popupOverlay.classList.add('is-visible');
|
|
popupOverlay.setAttribute('aria-hidden', 'false');
|
|
document.body.classList.add('popup-open');
|
|
// Focus the close button for accessibility
|
|
if (popupClose) {
|
|
setTimeout(function() {
|
|
popupClose.focus();
|
|
}, 100);
|
|
}
|
|
}
|
|
|
|
function closePopup() {
|
|
if (!popupOverlay) return;
|
|
popupOverlay.classList.remove('is-visible');
|
|
popupOverlay.setAttribute('aria-hidden', 'true');
|
|
document.body.classList.remove('popup-open');
|
|
}
|
|
|
|
// Auto-open popup after 5 seconds
|
|
let popupShown = false;
|
|
setTimeout(function() {
|
|
if (!popupShown) {
|
|
popupShown = true;
|
|
openPopup();
|
|
}
|
|
}, 5000);
|
|
|
|
// Floating CTA click
|
|
if (floatingCta) {
|
|
floatingCta.addEventListener('click', function() {
|
|
openPopup();
|
|
});
|
|
}
|
|
|
|
// Close button click
|
|
if (popupClose) {
|
|
popupClose.addEventListener('click', function() {
|
|
closePopup();
|
|
});
|
|
}
|
|
|
|
// Click outside popup to close
|
|
if (popupOverlay) {
|
|
popupOverlay.addEventListener('click', function(e) {
|
|
if (e.target === popupOverlay) {
|
|
closePopup();
|
|
}
|
|
});
|
|
}
|
|
|
|
// Escape key to close popup
|
|
document.addEventListener('keydown', function(e) {
|
|
if (e.key === 'Escape' && popupOverlay && popupOverlay.classList.contains('is-visible')) {
|
|
closePopup();
|
|
if (floatingCta) {
|
|
floatingCta.focus();
|
|
}
|
|
}
|
|
});
|
|
|
|
// Trap focus inside popup when open
|
|
if (popup) {
|
|
popup.addEventListener('keydown', function(e) {
|
|
if (e.key !== 'Tab') return;
|
|
|
|
const focusableElements = popup.querySelectorAll(
|
|
'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'
|
|
);
|
|
const firstElement = focusableElements[0];
|
|
const lastElement = focusableElements[focusableElements.length - 1];
|
|
|
|
if (e.shiftKey) {
|
|
if (document.activeElement === firstElement) {
|
|
lastElement.focus();
|
|
e.preventDefault();
|
|
}
|
|
} else {
|
|
if (document.activeElement === lastElement) {
|
|
firstElement.focus();
|
|
e.preventDefault();
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
})(); |