Initial AI-generated site
This commit is contained in:
@@ -0,0 +1,196 @@
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
||||
|
||||
// Header scroll effect
|
||||
const header = document.querySelector('.site-header');
|
||||
|
||||
function handleHeaderScroll() {
|
||||
if (window.scrollY > 50) {
|
||||
header.classList.add('scrolled');
|
||||
} else {
|
||||
header.classList.remove('scrolled');
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener('scroll', handleHeaderScroll, { passive: true });
|
||||
|
||||
// Mobile navigation
|
||||
const mobileToggle = document.querySelector('.mobile-toggle');
|
||||
const navLinks = document.querySelector('.nav-links');
|
||||
|
||||
function closeMobileNav() {
|
||||
navLinks.classList.remove('open');
|
||||
mobileToggle.classList.remove('open');
|
||||
mobileToggle.setAttribute('aria-expanded', 'false');
|
||||
mobileToggle.setAttribute('aria-label', 'פתח תפריט ניווט');
|
||||
}
|
||||
|
||||
function openMobileNav() {
|
||||
navLinks.classList.add('open');
|
||||
mobileToggle.classList.add('open');
|
||||
mobileToggle.setAttribute('aria-expanded', 'true');
|
||||
mobileToggle.setAttribute('aria-label', 'סגור תפריט ניווט');
|
||||
}
|
||||
|
||||
mobileToggle.addEventListener('click', function() {
|
||||
const isOpen = navLinks.classList.contains('open');
|
||||
if (isOpen) {
|
||||
closeMobileNav();
|
||||
} else {
|
||||
openMobileNav();
|
||||
}
|
||||
});
|
||||
|
||||
navLinks.querySelectorAll('a').forEach(function(link) {
|
||||
link.addEventListener('click', closeMobileNav);
|
||||
});
|
||||
|
||||
// Close mobile nav on escape
|
||||
document.addEventListener('keydown', function(e) {
|
||||
if (e.key === 'Escape' && navLinks.classList.contains('open')) {
|
||||
closeMobileNav();
|
||||
mobileToggle.focus();
|
||||
}
|
||||
});
|
||||
|
||||
// Smooth scroll for anchor links
|
||||
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.scrollY - headerOffset;
|
||||
|
||||
window.scrollTo({
|
||||
top: offsetPosition,
|
||||
behavior: prefersReducedMotion ? 'auto' : 'smooth'
|
||||
});
|
||||
|
||||
// Set focus to target for accessibility
|
||||
target.setAttribute('tabindex', '-1');
|
||||
target.focus({ preventScroll: true });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Contact form handling
|
||||
const contactForm = document.getElementById('contactForm');
|
||||
const formSuccess = document.getElementById('formSuccess');
|
||||
const successClose = document.getElementById('successClose');
|
||||
const nameInput = document.getElementById('name');
|
||||
const phoneInput = document.getElementById('phone');
|
||||
const nameError = document.getElementById('nameError');
|
||||
const phoneError = document.getElementById('phoneError');
|
||||
|
||||
function validateName() {
|
||||
const value = nameInput.value.trim();
|
||||
if (!value) {
|
||||
nameInput.classList.add('error');
|
||||
nameError.textContent = 'נא להזין שם';
|
||||
return false;
|
||||
}
|
||||
nameInput.classList.remove('error');
|
||||
nameError.textContent = '';
|
||||
return true;
|
||||
}
|
||||
|
||||
function validatePhone() {
|
||||
const value = phoneInput.value.replace(/\D/g, '');
|
||||
if (!value || value.length < 9) {
|
||||
phoneInput.classList.add('error');
|
||||
phoneError.textContent = 'נא להזין מספר טלפון תקין';
|
||||
return false;
|
||||
}
|
||||
phoneInput.classList.remove('error');
|
||||
phoneError.textContent = '';
|
||||
return true;
|
||||
}
|
||||
|
||||
nameInput.addEventListener('blur', validateName);
|
||||
phoneInput.addEventListener('blur', validatePhone);
|
||||
|
||||
contactForm.addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
const isNameValid = validateName();
|
||||
const isPhoneValid = validatePhone();
|
||||
|
||||
if (!isNameValid || !isPhoneValid) {
|
||||
if (!isNameValid) {
|
||||
nameInput.focus();
|
||||
} else {
|
||||
phoneInput.focus();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const submitBtn = contactForm.querySelector('.btn-submit');
|
||||
const originalText = submitBtn.innerHTML;
|
||||
submitBtn.innerHTML = '<span>שולח...</span>';
|
||||
submitBtn.disabled = true;
|
||||
|
||||
// Simulate form submission
|
||||
setTimeout(function() {
|
||||
submitBtn.innerHTML = originalText;
|
||||
submitBtn.disabled = false;
|
||||
formSuccess.hidden = false;
|
||||
contactForm.reset();
|
||||
|
||||
successClose.focus();
|
||||
}, 1200);
|
||||
});
|
||||
|
||||
function closeSuccessModal() {
|
||||
formSuccess.hidden = true;
|
||||
}
|
||||
|
||||
successClose.addEventListener('click', closeSuccessModal);
|
||||
|
||||
formSuccess.addEventListener('click', function(e) {
|
||||
if (e.target === formSuccess) {
|
||||
closeSuccessModal();
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener('keydown', function(e) {
|
||||
if (e.key === 'Escape' && !formSuccess.hidden) {
|
||||
closeSuccessModal();
|
||||
}
|
||||
});
|
||||
|
||||
// Phone number formatting
|
||||
phoneInput.addEventListener('input', function(e) {
|
||||
let value = e.target.value.replace(/\D/g, '');
|
||||
|
||||
if (value.length > 10) {
|
||||
value = value.slice(0, 10);
|
||||
}
|
||||
|
||||
if (value.length > 3 && value.length <= 6) {
|
||||
value = value.slice(0, 3) + '-' + value.slice(3);
|
||||
} else if (value.length > 6) {
|
||||
value = value.slice(0, 3) + '-' + value.slice(3, 6) + '-' + value.slice(6);
|
||||
}
|
||||
|
||||
e.target.value = value;
|
||||
});
|
||||
|
||||
// Keyboard navigation detection
|
||||
document.body.addEventListener('keydown', function(e) {
|
||||
if (e.key === 'Tab') {
|
||||
document.body.classList.add('keyboard-nav');
|
||||
}
|
||||
});
|
||||
|
||||
document.body.addEventListener('mousedown', function() {
|
||||
document.body.classList.remove('keyboard-nav');
|
||||
});
|
||||
|
||||
})();
|
||||
Reference in New Issue
Block a user