153 lines
4.6 KiB
JavaScript
153 lines
4.6 KiB
JavaScript
(function() {
|
|
'use strict';
|
|
|
|
// Mobile Navigation Toggle
|
|
const navToggle = document.querySelector('.nav-toggle');
|
|
const navMenu = document.querySelector('.nav-menu');
|
|
|
|
if (navToggle && navMenu) {
|
|
navToggle.addEventListener('click', function() {
|
|
const isExpanded = navToggle.getAttribute('aria-expanded') === 'true';
|
|
navToggle.setAttribute('aria-expanded', !isExpanded);
|
|
navMenu.classList.toggle('active');
|
|
});
|
|
|
|
// Close menu when clicking a link
|
|
navMenu.querySelectorAll('a').forEach(function(link) {
|
|
link.addEventListener('click', function() {
|
|
navMenu.classList.remove('active');
|
|
navToggle.setAttribute('aria-expanded', 'false');
|
|
});
|
|
});
|
|
|
|
// Close menu on escape key
|
|
document.addEventListener('keydown', function(e) {
|
|
if (e.key === 'Escape' && navMenu.classList.contains('active')) {
|
|
navMenu.classList.remove('active');
|
|
navToggle.setAttribute('aria-expanded', 'false');
|
|
navToggle.focus();
|
|
}
|
|
});
|
|
}
|
|
|
|
// Catalog Filtering
|
|
const filterButtons = document.querySelectorAll('.filter-btn');
|
|
const productCards = document.querySelectorAll('.product-card');
|
|
|
|
filterButtons.forEach(function(button) {
|
|
button.addEventListener('click', function() {
|
|
const filter = this.dataset.filter;
|
|
|
|
// Update active button
|
|
filterButtons.forEach(function(btn) {
|
|
btn.classList.remove('active');
|
|
btn.setAttribute('aria-pressed', 'false');
|
|
});
|
|
this.classList.add('active');
|
|
this.setAttribute('aria-pressed', 'true');
|
|
|
|
// Filter products
|
|
productCards.forEach(function(card) {
|
|
if (filter === 'all' || card.dataset.category === filter) {
|
|
card.classList.remove('hidden');
|
|
} else {
|
|
card.classList.add('hidden');
|
|
}
|
|
});
|
|
});
|
|
});
|
|
|
|
// Form Handling
|
|
const contactForm = document.getElementById('contactForm');
|
|
|
|
if (contactForm) {
|
|
contactForm.addEventListener('submit', function(e) {
|
|
e.preventDefault();
|
|
|
|
const formData = new FormData(contactForm);
|
|
const data = {};
|
|
formData.forEach(function(value, key) {
|
|
data[key] = value;
|
|
});
|
|
|
|
// Simulate form submission
|
|
const submitBtn = contactForm.querySelector('.btn-submit');
|
|
const originalText = submitBtn.textContent;
|
|
submitBtn.textContent = 'שולח...';
|
|
submitBtn.disabled = true;
|
|
submitBtn.style.opacity = '0.7';
|
|
|
|
setTimeout(function() {
|
|
submitBtn.textContent = 'נשלח בהצלחה!';
|
|
submitBtn.style.background = '#38a169';
|
|
submitBtn.style.opacity = '1';
|
|
|
|
setTimeout(function() {
|
|
contactForm.reset();
|
|
submitBtn.textContent = originalText;
|
|
submitBtn.style.background = '';
|
|
submitBtn.disabled = false;
|
|
}, 2500);
|
|
}, 1200);
|
|
});
|
|
}
|
|
|
|
// Scroll Reveal Animation
|
|
const revealElements = document.querySelectorAll('.reveal');
|
|
const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)');
|
|
|
|
if (prefersReducedMotion.matches) {
|
|
// Immediately show all elements if user prefers reduced motion
|
|
revealElements.forEach(function(el) {
|
|
el.classList.add('visible');
|
|
});
|
|
} else if ('IntersectionObserver' in window) {
|
|
const revealObserver = new IntersectionObserver(function(entries) {
|
|
entries.forEach(function(entry) {
|
|
if (entry.isIntersecting) {
|
|
entry.target.classList.add('visible');
|
|
revealObserver.unobserve(entry.target);
|
|
}
|
|
});
|
|
}, {
|
|
threshold: 0.1,
|
|
rootMargin: '0px 0px -40px 0px'
|
|
});
|
|
|
|
revealElements.forEach(function(el) {
|
|
revealObserver.observe(el);
|
|
});
|
|
} else {
|
|
// Fallback for browsers without IntersectionObserver
|
|
revealElements.forEach(function(el) {
|
|
el.classList.add('visible');
|
|
});
|
|
}
|
|
|
|
// Smooth scroll offset for fixed header
|
|
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 headerOffset = 80;
|
|
const elementPosition = target.getBoundingClientRect().top;
|
|
const offsetPosition = elementPosition + window.pageYOffset - headerOffset;
|
|
|
|
if (prefersReducedMotion.matches) {
|
|
window.scrollTo(0, offsetPosition);
|
|
} else {
|
|
window.scrollTo({
|
|
top: offsetPosition,
|
|
behavior: 'smooth'
|
|
});
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
})();
|