Files
2026-09-15 09:25:59 +00:00

124 lines
3.5 KiB
JavaScript

(function() {
'use strict';
// Check for reduced motion preference
const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
// Reveal on scroll
function initReveal() {
const reveals = document.querySelectorAll('.reveal');
if (prefersReducedMotion) {
reveals.forEach(el => el.classList.add('revealed'));
return;
}
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('revealed');
observer.unobserve(entry.target);
}
});
}, {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
});
reveals.forEach(el => observer.observe(el));
}
// Smooth scroll for anchor links
function initSmoothScroll() {
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 headerHeight = document.querySelector('.site-header').offsetHeight;
const targetPosition = target.getBoundingClientRect().top + window.pageYOffset - headerHeight;
window.scrollTo({
top: targetPosition,
behavior: prefersReducedMotion ? 'auto' : 'smooth'
});
}
});
});
}
// Header background on scroll
function initHeaderScroll() {
const header = document.querySelector('.site-header');
window.addEventListener('scroll', () => {
const currentScroll = window.pageYOffset;
if (currentScroll > 100) {
header.style.boxShadow = '0 2px 20px rgba(42, 37, 32, 0.08)';
} else {
header.style.boxShadow = 'none';
}
}, { passive: true });
}
// Form handling
function initForm() {
const form = document.getElementById('contactForm');
if (!form) return;
form.addEventListener('submit', function(e) {
e.preventDefault();
const formData = new FormData(form);
const data = Object.fromEntries(formData);
// Visual feedback
const button = form.querySelector('.btn-submit');
const originalText = button.textContent;
button.textContent = 'נשלח בהצלחה! ✓';
button.style.background = '#4a9d5a';
button.disabled = true;
// Reset form
setTimeout(() => {
form.reset();
button.textContent = originalText;
button.style.background = '';
button.disabled = false;
}, 3000);
// Log for demo purposes
console.log('Form submitted:', data);
});
}
// Gallery item keyboard interaction
function initGallery() {
const galleryItems = document.querySelectorAll('.gallery-item');
galleryItems.forEach(item => {
item.addEventListener('keydown', (e) => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
// Toggle expanded state for screen readers
const isExpanded = item.getAttribute('aria-expanded') === 'true';
item.setAttribute('aria-expanded', !isExpanded);
}
});
});
}
// Initialize all functions when DOM is ready
document.addEventListener('DOMContentLoaded', () => {
initReveal();
initSmoothScroll();
initHeaderScroll();
initForm();
initGallery();
});
})();