212 lines
6.0 KiB
JavaScript
212 lines
6.0 KiB
JavaScript
(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 isExpanded = navToggle.getAttribute('aria-expanded') === 'true';
|
|
navToggle.setAttribute('aria-expanded', !isExpanded);
|
|
navLinks.classList.toggle('active');
|
|
});
|
|
|
|
// Close menu when clicking a link
|
|
navLinks.querySelectorAll('a').forEach(function(link) {
|
|
link.addEventListener('click', function() {
|
|
navLinks.classList.remove('active');
|
|
navToggle.setAttribute('aria-expanded', 'false');
|
|
});
|
|
});
|
|
}
|
|
|
|
// Smooth scroll for anchor links
|
|
document.querySelectorAll('a[href^="#"]').forEach(function(anchor) {
|
|
anchor.addEventListener('click', function(e) {
|
|
e.preventDefault();
|
|
const target = document.querySelector(this.getAttribute('href'));
|
|
if (target) {
|
|
const headerHeight = document.querySelector('.site-header').offsetHeight;
|
|
const targetPosition = target.getBoundingClientRect().top + window.pageYOffset - headerHeight;
|
|
window.scrollTo({
|
|
top: targetPosition,
|
|
behavior: 'smooth'
|
|
});
|
|
}
|
|
});
|
|
});
|
|
|
|
// Intersection Observer for reveal animations
|
|
const observerOptions = {
|
|
root: null,
|
|
rootMargin: '0px',
|
|
threshold: 0.1
|
|
};
|
|
|
|
const revealObserver = new IntersectionObserver(function(entries) {
|
|
entries.forEach(function(entry) {
|
|
if (entry.isIntersecting) {
|
|
entry.target.classList.add('revealed');
|
|
revealObserver.unobserve(entry.target);
|
|
}
|
|
});
|
|
}, observerOptions);
|
|
|
|
// Add reveal class to elements
|
|
const revealElements = document.querySelectorAll(
|
|
'.category-card, .stat-card, .feature, .contact-item, .pwa-card'
|
|
);
|
|
|
|
revealElements.forEach(function(el, index) {
|
|
el.classList.add('reveal');
|
|
el.style.transitionDelay = (index % 4) * 0.1 + 's';
|
|
revealObserver.observe(el);
|
|
});
|
|
|
|
// Counter animation for statistics
|
|
function animateCounter(element) {
|
|
const target = parseInt(element.getAttribute('data-count'), 10);
|
|
if (!target) return;
|
|
|
|
const duration = 2000;
|
|
const step = target / (duration / 16);
|
|
let current = 0;
|
|
|
|
function update() {
|
|
current += step;
|
|
if (current < target) {
|
|
element.textContent = Math.floor(current).toLocaleString('he-IL');
|
|
requestAnimationFrame(update);
|
|
} else {
|
|
element.textContent = target.toLocaleString('he-IL') + '+';
|
|
}
|
|
}
|
|
|
|
update();
|
|
}
|
|
|
|
const statNumbers = document.querySelectorAll('.stat-number[data-count], .stat-big[data-count]');
|
|
|
|
const statsObserver = new IntersectionObserver(function(entries) {
|
|
entries.forEach(function(entry) {
|
|
if (entry.isIntersecting) {
|
|
animateCounter(entry.target);
|
|
statsObserver.unobserve(entry.target);
|
|
}
|
|
});
|
|
}, { threshold: 0.5 });
|
|
|
|
statNumbers.forEach(function(stat) {
|
|
statsObserver.observe(stat);
|
|
});
|
|
|
|
// Form submission handling
|
|
const orderForm = document.getElementById('orderForm');
|
|
const formSuccess = document.getElementById('formSuccess');
|
|
|
|
if (orderForm) {
|
|
orderForm.addEventListener('submit', function(e) {
|
|
e.preventDefault();
|
|
|
|
// Simulate form submission
|
|
const submitBtn = orderForm.querySelector('button[type="submit"]');
|
|
submitBtn.disabled = true;
|
|
submitBtn.innerHTML = '<span>שולח...</span>';
|
|
|
|
setTimeout(function() {
|
|
orderForm.style.display = 'none';
|
|
formSuccess.hidden = false;
|
|
formSuccess.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
|
}, 1500);
|
|
});
|
|
}
|
|
|
|
const contactForm = document.getElementById('contactForm');
|
|
|
|
if (contactForm) {
|
|
contactForm.addEventListener('submit', function(e) {
|
|
e.preventDefault();
|
|
|
|
const submitBtn = contactForm.querySelector('button[type="submit"]');
|
|
const originalText = submitBtn.textContent;
|
|
submitBtn.disabled = true;
|
|
submitBtn.textContent = 'שולח...';
|
|
|
|
setTimeout(function() {
|
|
contactForm.reset();
|
|
submitBtn.disabled = false;
|
|
submitBtn.textContent = 'נשלח בהצלחה!';
|
|
|
|
setTimeout(function() {
|
|
submitBtn.textContent = originalText;
|
|
}, 2000);
|
|
}, 1500);
|
|
});
|
|
}
|
|
|
|
// PWA Install functionality
|
|
let deferredPrompt;
|
|
const installBtn = document.getElementById('installBtn');
|
|
const installBtnMain = document.getElementById('installBtnMain');
|
|
|
|
window.addEventListener('beforeinstallprompt', function(e) {
|
|
e.preventDefault();
|
|
deferredPrompt = e;
|
|
|
|
if (installBtn) {
|
|
installBtn.hidden = false;
|
|
}
|
|
});
|
|
|
|
function handleInstall() {
|
|
if (!deferredPrompt) {
|
|
alert('האפליקציה כבר מותקנת או שהדפדפן לא תומך בהתקנה.');
|
|
return;
|
|
}
|
|
|
|
deferredPrompt.prompt();
|
|
|
|
deferredPrompt.userChoice.then(function(choiceResult) {
|
|
if (choiceResult.outcome === 'accepted') {
|
|
console.log('User accepted PWA install');
|
|
}
|
|
deferredPrompt = null;
|
|
|
|
if (installBtn) installBtn.hidden = true;
|
|
});
|
|
}
|
|
|
|
if (installBtn) {
|
|
installBtn.addEventListener('click', handleInstall);
|
|
}
|
|
|
|
if (installBtnMain) {
|
|
installBtnMain.addEventListener('click', handleInstall);
|
|
}
|
|
|
|
// Header scroll effect
|
|
const header = document.querySelector('.site-header');
|
|
let lastScrollY = window.scrollY;
|
|
|
|
window.addEventListener('scroll', function() {
|
|
const currentScrollY = window.scrollY;
|
|
|
|
if (currentScrollY > 100) {
|
|
header.style.boxShadow = 'var(--shadow-md)';
|
|
} else {
|
|
header.style.boxShadow = 'none';
|
|
}
|
|
|
|
lastScrollY = currentScrollY;
|
|
}, { passive: true });
|
|
|
|
// Respect reduced motion preference
|
|
if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
|
|
document.querySelectorAll('.floating, .floating-delayed').forEach(function(el) {
|
|
el.style.animation = 'none';
|
|
});
|
|
}
|
|
|
|
})();
|