147 lines
4.3 KiB
JavaScript
147 lines
4.3 KiB
JavaScript
(function() {
|
|
'use strict';
|
|
|
|
// Scroll reveal with staggered animations
|
|
const revealElements = document.querySelectorAll('.reveal');
|
|
|
|
if ('IntersectionObserver' in window) {
|
|
const revealObserver = new IntersectionObserver((entries) => {
|
|
entries.forEach((entry) => {
|
|
if (entry.isIntersecting) {
|
|
entry.target.classList.add('visible');
|
|
revealObserver.unobserve(entry.target);
|
|
}
|
|
});
|
|
}, {
|
|
threshold: 0.1,
|
|
rootMargin: '0px 0px -40px 0px'
|
|
});
|
|
|
|
revealElements.forEach((el) => {
|
|
revealObserver.observe(el);
|
|
});
|
|
} else {
|
|
// Fallback for browsers without IntersectionObserver
|
|
revealElements.forEach((el) => {
|
|
el.classList.add('visible');
|
|
});
|
|
}
|
|
|
|
// 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();
|
|
const header = document.querySelector('.site-header');
|
|
const headerHeight = header ? header.offsetHeight : 0;
|
|
const targetPosition = target.getBoundingClientRect().top + window.pageYOffset - headerHeight - 20;
|
|
|
|
window.scrollTo({
|
|
top: targetPosition,
|
|
behavior: 'smooth'
|
|
});
|
|
|
|
// Set focus to target for accessibility
|
|
target.setAttribute('tabindex', '-1');
|
|
target.focus({ preventScroll: true });
|
|
}
|
|
});
|
|
});
|
|
|
|
// Form handling
|
|
const contactForm = document.getElementById('contactForm');
|
|
const formFeedback = document.getElementById('formFeedback');
|
|
|
|
function showFeedback(message, isSuccess) {
|
|
formFeedback.textContent = message;
|
|
formFeedback.className = 'form-feedback ' + (isSuccess ? 'success' : 'error');
|
|
}
|
|
|
|
function clearFeedback() {
|
|
formFeedback.textContent = '';
|
|
formFeedback.className = 'form-feedback';
|
|
}
|
|
|
|
if (contactForm) {
|
|
contactForm.addEventListener('submit', function(e) {
|
|
e.preventDefault();
|
|
clearFeedback();
|
|
|
|
const formData = new FormData(this);
|
|
const name = formData.get('name').trim();
|
|
const phone = formData.get('phone').trim();
|
|
|
|
// Validation
|
|
if (!name) {
|
|
showFeedback('אנא הזינו את שמכם', false);
|
|
document.getElementById('name').focus();
|
|
return;
|
|
}
|
|
|
|
if (!phone) {
|
|
showFeedback('אנא הזינו מספר טלפון', false);
|
|
document.getElementById('phone').focus();
|
|
return;
|
|
}
|
|
|
|
// Phone validation (Israeli format)
|
|
const phoneRegex = /^0[0-9]{8,9}$/;
|
|
const cleanPhone = phone.replace(/[-\s]/g, '');
|
|
|
|
if (!phoneRegex.test(cleanPhone)) {
|
|
showFeedback('אנא הזינו מספר טלפון ישראלי תקין', false);
|
|
document.getElementById('phone').focus();
|
|
return;
|
|
}
|
|
|
|
// Simulate form submission
|
|
const submitBtn = this.querySelector('button[type="submit"]');
|
|
const originalText = submitBtn.textContent;
|
|
|
|
submitBtn.disabled = true;
|
|
submitBtn.textContent = 'שולח...';
|
|
|
|
// In production, replace with actual form submission
|
|
setTimeout(() => {
|
|
contactForm.reset();
|
|
submitBtn.disabled = false;
|
|
submitBtn.textContent = originalText;
|
|
|
|
showFeedback('תודה! פנייתכם התקבלה. אחזור אליכם בהקדם.', true);
|
|
|
|
setTimeout(() => {
|
|
clearFeedback();
|
|
}, 5000);
|
|
}, 1000);
|
|
});
|
|
|
|
// Clear feedback when user starts typing
|
|
contactForm.querySelectorAll('input, textarea').forEach(function(field) {
|
|
field.addEventListener('input', clearFeedback);
|
|
});
|
|
}
|
|
|
|
// Header scroll effect
|
|
const header = document.querySelector('.site-header');
|
|
let lastScrollY = 0;
|
|
|
|
if (header) {
|
|
function updateHeaderShadow() {
|
|
if (window.pageYOffset > 100) {
|
|
header.style.boxShadow = 'var(--shadow)';
|
|
} else {
|
|
header.style.boxShadow = 'none';
|
|
}
|
|
lastScrollY = window.pageYOffset;
|
|
}
|
|
|
|
window.addEventListener('scroll', updateHeaderShadow, { passive: true });
|
|
updateHeaderShadow();
|
|
}
|
|
|
|
})();
|