Files
2026-07-30 18:59:14 +00:00

190 lines
6.0 KiB
JavaScript

(function() {
'use strict';
// Respect reduced motion preference
const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
// Cursor glow effect (only on devices with fine pointer)
const cursorGlow = document.querySelector('.cursor-glow');
const hasFinePointer = window.matchMedia('(pointer: fine)').matches;
if (cursorGlow && !prefersReducedMotion && hasFinePointer) {
let mouseX = 0, mouseY = 0;
let glowX = 0, glowY = 0;
let rafId = null;
document.addEventListener('mousemove', (e) => {
mouseX = e.clientX;
mouseY = e.clientY;
});
function animateCursor() {
glowX += (mouseX - glowX) * 0.1;
glowY += (mouseY - glowY) * 0.1;
cursorGlow.style.left = glowX + 'px';
cursorGlow.style.top = glowY + 'px';
rafId = requestAnimationFrame(animateCursor);
}
animateCursor();
// Cleanup on page hide
document.addEventListener('visibilitychange', () => {
if (document.hidden && rafId) {
cancelAnimationFrame(rafId);
} else if (!document.hidden) {
animateCursor();
}
});
}
// Header scroll effect
const header = document.querySelector('.site-header');
let ticking = false;
function handleScroll() {
if (!ticking) {
requestAnimationFrame(() => {
const currentScrollY = window.scrollY;
if (currentScrollY > 50) {
header.classList.add('scrolled');
} else {
header.classList.remove('scrolled');
}
ticking = false;
});
ticking = true;
}
}
window.addEventListener('scroll', handleScroll, { passive: true });
// Mobile navigation
const navToggle = document.querySelector('.nav-toggle');
const navLinks = document.querySelector('.nav-links');
if (navToggle && navLinks) {
navToggle.addEventListener('click', () => {
const isExpanded = navToggle.getAttribute('aria-expanded') === 'true';
navToggle.setAttribute('aria-expanded', !isExpanded);
navLinks.classList.toggle('active');
document.body.style.overflow = isExpanded ? '' : 'hidden';
// Update label
navToggle.setAttribute('aria-label', isExpanded ? 'פתיחת תפריט ניווט' : 'סגירת תפריט ניווט');
});
navLinks.querySelectorAll('a').forEach(link => {
link.addEventListener('click', () => {
navToggle.setAttribute('aria-expanded', 'false');
navToggle.setAttribute('aria-label', 'פתיחת תפריט ניווט');
navLinks.classList.remove('active');
document.body.style.overflow = '';
});
});
// Close on escape
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape' && navLinks.classList.contains('active')) {
navToggle.setAttribute('aria-expanded', 'false');
navToggle.setAttribute('aria-label', 'פתיחת תפריט ניווט');
navLinks.classList.remove('active');
document.body.style.overflow = '';
navToggle.focus();
}
});
}
// Reveal on scroll
const revealElements = document.querySelectorAll('.reveal');
if (!prefersReducedMotion && revealElements.length > 0) {
const observerOptions = {
root: null,
rootMargin: '0px 0px -80px 0px',
threshold: 0.1
};
const revealObserver = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
revealObserver.unobserve(entry.target);
}
});
}, observerOptions);
revealElements.forEach(el => revealObserver.observe(el));
} else {
revealElements.forEach(el => el.classList.add('visible'));
}
// Smooth scroll for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', (e) => {
const href = anchor.getAttribute('href');
if (href === '#') return;
const target = document.querySelector(href);
if (target) {
e.preventDefault();
target.scrollIntoView({
behavior: prefersReducedMotion ? 'auto' : 'smooth'
});
// Set focus for accessibility
target.setAttribute('tabindex', '-1');
target.focus({ preventScroll: true });
}
});
});
// Form submission handling with feedback
const contactForm = document.getElementById('contact-form');
const formStatus = document.getElementById('form-status');
if (contactForm && formStatus) {
contactForm.addEventListener('submit', function(e) {
const submitBtn = contactForm.querySelector('button[type="submit"]');
const originalText = submitBtn.querySelector('span').textContent;
// Show loading state
submitBtn.disabled = true;
submitBtn.querySelector('span').textContent = 'שולח...';
// FormSubmit handles the actual submission
// We add a listener for successful redirect or show error after timeout
// Since FormSubmit redirects by default, we'll use fetch for better UX
e.preventDefault();
const formData = new FormData(contactForm);
fetch(contactForm.action, {
method: 'POST',
body: formData,
headers: {
'Accept': 'application/json'
}
})
.then(response => {
if (response.ok) {
formStatus.textContent = 'ההודעה נשלחה בהצלחה! נחזור אליכם בהקדם.';
formStatus.className = 'form-status success';
contactForm.reset();
} else {
throw new Error('Network response was not ok');
}
})
.catch(error => {
formStatus.textContent = 'אירעה שגיאה בשליחת ההודעה. אנא נסו שוב או צרו קשר במייל.';
formStatus.className = 'form-status error';
})
.finally(() => {
submitBtn.disabled = false;
submitBtn.querySelector('span').textContent = originalText;
});
});
}
})();