226 lines
6.5 KiB
JavaScript
226 lines
6.5 KiB
JavaScript
// Navigation Toggle
|
|
const navToggle = document.querySelector('.nav-toggle');
|
|
const navMenu = document.querySelector('.nav-menu');
|
|
|
|
if (navToggle && navMenu) {
|
|
navToggle.addEventListener('click', () => {
|
|
const isExpanded = navToggle.getAttribute('aria-expanded') === 'true';
|
|
navToggle.setAttribute('aria-expanded', !isExpanded);
|
|
navMenu.classList.toggle('active');
|
|
});
|
|
|
|
// Close menu when clicking outside
|
|
document.addEventListener('click', (e) => {
|
|
if (!navToggle.contains(e.target) && !navMenu.contains(e.target)) {
|
|
navToggle.setAttribute('aria-expanded', 'false');
|
|
navMenu.classList.remove('active');
|
|
}
|
|
});
|
|
|
|
// Close menu on escape key
|
|
document.addEventListener('keydown', (e) => {
|
|
if (e.key === 'Escape' && navMenu.classList.contains('active')) {
|
|
navToggle.setAttribute('aria-expanded', 'false');
|
|
navMenu.classList.remove('active');
|
|
navToggle.focus();
|
|
}
|
|
});
|
|
}
|
|
|
|
// Reveal on Scroll
|
|
const revealElements = document.querySelectorAll('[data-reveal]');
|
|
|
|
const revealObserver = new IntersectionObserver((entries) => {
|
|
entries.forEach((entry, index) => {
|
|
if (entry.isIntersecting) {
|
|
// Stagger the reveal animation
|
|
setTimeout(() => {
|
|
entry.target.classList.add('revealed');
|
|
}, index * 100);
|
|
revealObserver.unobserve(entry.target);
|
|
}
|
|
});
|
|
}, {
|
|
threshold: 0.1,
|
|
rootMargin: '0px 0px -50px 0px'
|
|
});
|
|
|
|
// Check for reduced motion preference
|
|
const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
|
|
if (!prefersReducedMotion) {
|
|
revealElements.forEach(el => revealObserver.observe(el));
|
|
} else {
|
|
// If user prefers reduced motion, reveal everything immediately
|
|
revealElements.forEach(el => el.classList.add('revealed'));
|
|
}
|
|
|
|
// Animated Counter
|
|
const counters = document.querySelectorAll('[data-count]');
|
|
|
|
const counterObserver = new IntersectionObserver((entries) => {
|
|
entries.forEach(entry => {
|
|
if (entry.isIntersecting) {
|
|
const counter = entry.target;
|
|
const target = parseInt(counter.getAttribute('data-count'));
|
|
const duration = 2000;
|
|
const step = target / (duration / 16);
|
|
let current = 0;
|
|
|
|
const updateCounter = () => {
|
|
current += step;
|
|
if (current < target) {
|
|
counter.textContent = Math.floor(current).toLocaleString('he-IL');
|
|
requestAnimationFrame(updateCounter);
|
|
} else {
|
|
counter.textContent = target.toLocaleString('he-IL');
|
|
}
|
|
};
|
|
|
|
if (!prefersReducedMotion) {
|
|
updateCounter();
|
|
} else {
|
|
counter.textContent = target.toLocaleString('he-IL');
|
|
}
|
|
|
|
counterObserver.unobserve(counter);
|
|
}
|
|
});
|
|
}, {
|
|
threshold: 0.5
|
|
});
|
|
|
|
counters.forEach(counter => counterObserver.observe(counter));
|
|
|
|
// Pricing Toggle
|
|
const pricingToggle = document.querySelector('.toggle-switch');
|
|
const monthlyLabel = document.querySelector('[data-pricing="monthly"]');
|
|
const annualLabel = document.querySelector('[data-pricing="annual"]');
|
|
const prices = document.querySelectorAll('[data-price-monthly]');
|
|
|
|
if (pricingToggle && prices.length > 0) {
|
|
pricingToggle.addEventListener('click', () => {
|
|
pricingToggle.classList.toggle('active');
|
|
const isAnnual = pricingToggle.classList.contains('active');
|
|
|
|
if (monthlyLabel) monthlyLabel.classList.toggle('active', !isAnnual);
|
|
if (annualLabel) annualLabel.classList.toggle('active', isAnnual);
|
|
|
|
prices.forEach(price => {
|
|
const monthly = price.getAttribute('data-price-monthly');
|
|
const annual = price.getAttribute('data-price-annual');
|
|
price.innerHTML = isAnnual ? annual : monthly;
|
|
});
|
|
});
|
|
}
|
|
|
|
// Form Validation and Submission
|
|
const contactForm = document.querySelector('.contact-form');
|
|
|
|
if (contactForm) {
|
|
contactForm.addEventListener('submit', (e) => {
|
|
e.preventDefault();
|
|
|
|
// Basic validation
|
|
const required = contactForm.querySelectorAll('[required]');
|
|
let isValid = true;
|
|
|
|
required.forEach(field => {
|
|
if (!field.value.trim()) {
|
|
isValid = false;
|
|
field.classList.add('error');
|
|
} else {
|
|
field.classList.remove('error');
|
|
}
|
|
});
|
|
|
|
// Email validation
|
|
const email = contactForm.querySelector('[type="email"]');
|
|
if (email && email.value) {
|
|
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
if (!emailRegex.test(email.value)) {
|
|
isValid = false;
|
|
email.classList.add('error');
|
|
}
|
|
}
|
|
|
|
if (isValid) {
|
|
// Simulate form submission
|
|
const submitBtn = contactForm.querySelector('button[type="submit"]');
|
|
const originalText = submitBtn.textContent;
|
|
submitBtn.textContent = 'שולח...';
|
|
submitBtn.disabled = true;
|
|
|
|
setTimeout(() => {
|
|
submitBtn.textContent = 'נשלח בהצלחה!';
|
|
submitBtn.classList.add('success');
|
|
|
|
setTimeout(() => {
|
|
contactForm.reset();
|
|
submitBtn.textContent = originalText;
|
|
submitBtn.disabled = false;
|
|
submitBtn.classList.remove('success');
|
|
}, 3000);
|
|
}, 1500);
|
|
}
|
|
});
|
|
}
|
|
|
|
// Newsletter Form
|
|
const newsletterForm = document.querySelector('.newsletter-form');
|
|
|
|
if (newsletterForm) {
|
|
newsletterForm.addEventListener('submit', (e) => {
|
|
e.preventDefault();
|
|
|
|
const email = newsletterForm.querySelector('input[type="email"]');
|
|
const submitBtn = newsletterForm.querySelector('button');
|
|
|
|
if (email && email.value) {
|
|
const originalText = submitBtn.textContent;
|
|
submitBtn.textContent = 'נרשמת!';
|
|
submitBtn.disabled = true;
|
|
|
|
setTimeout(() => {
|
|
email.value = '';
|
|
submitBtn.textContent = originalText;
|
|
submitBtn.disabled = false;
|
|
}, 3000);
|
|
}
|
|
});
|
|
}
|
|
|
|
// Smooth scroll for anchor links
|
|
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();
|
|
target.scrollIntoView({
|
|
behavior: prefersReducedMotion ? 'auto' : 'smooth'
|
|
});
|
|
}
|
|
});
|
|
});
|
|
|
|
// Header scroll effect
|
|
const header = document.querySelector('.site-header');
|
|
|
|
if (header) {
|
|
let lastScroll = 0;
|
|
|
|
window.addEventListener('scroll', () => {
|
|
const currentScroll = window.pageYOffset;
|
|
|
|
if (currentScroll > 100) {
|
|
header.style.boxShadow = 'var(--shadow-md)';
|
|
} else {
|
|
header.style.boxShadow = 'none';
|
|
}
|
|
|
|
lastScroll = currentScroll;
|
|
}, { passive: true });
|
|
} |