Files
2026-08-09 11:26:55 +00:00

222 lines
6.6 KiB
JavaScript

(function() {
'use strict';
const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
// Navigation scroll effect
const nav = document.querySelector('.nav');
function handleScroll() {
if (window.scrollY > 40) {
nav.classList.add('scrolled');
} else {
nav.classList.remove('scrolled');
}
}
window.addEventListener('scroll', handleScroll, { passive: true });
handleScroll();
// Mobile menu toggle
const mobileMenuBtn = document.querySelector('.mobile-menu-btn');
const mobileMenu = document.querySelector('.mobile-menu');
const mobileLinks = document.querySelectorAll('.mobile-link');
if (mobileMenuBtn && mobileMenu) {
mobileMenuBtn.addEventListener('click', function() {
const isExpanded = this.getAttribute('aria-expanded') === 'true';
this.setAttribute('aria-expanded', String(!isExpanded));
mobileMenu.setAttribute('aria-hidden', String(isExpanded));
});
mobileLinks.forEach(function(link) {
link.addEventListener('click', function() {
mobileMenuBtn.setAttribute('aria-expanded', 'false');
mobileMenu.setAttribute('aria-hidden', 'true');
});
});
}
// Scroll reveal
if (!prefersReducedMotion) {
const revealElements = document.querySelectorAll('.reveal');
const revealObserver = new IntersectionObserver(function(entries) {
entries.forEach(function(entry) {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
revealObserver.unobserve(entry.target);
}
});
}, {
threshold: 0.15,
rootMargin: '0px 0px -40px 0px'
});
revealElements.forEach(function(el) {
revealObserver.observe(el);
});
} else {
document.querySelectorAll('.reveal').forEach(function(el) {
el.classList.add('visible');
});
}
// 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 targetElement = document.querySelector(targetId);
if (targetElement) {
e.preventDefault();
const navHeight = nav ? nav.offsetHeight : 0;
const targetPosition = targetElement.getBoundingClientRect().top + window.pageYOffset - navHeight - 16;
if (prefersReducedMotion) {
window.scrollTo(0, targetPosition);
} else {
window.scrollTo({
top: targetPosition,
behavior: 'smooth'
});
}
}
});
});
// Form handling
const form = document.getElementById('contact-form');
const formSuccess = document.querySelector('.form-success');
if (form) {
const nameInput = document.getElementById('name');
const contactInput = document.getElementById('contact');
const nameError = nameInput.parentElement.querySelector('.form-error');
const contactError = contactInput.parentElement.querySelector('.form-error');
function validateField(input, errorEl, message) {
if (!input.value.trim()) {
input.classList.add('error');
errorEl.textContent = message;
return false;
}
input.classList.remove('error');
errorEl.textContent = '';
return true;
}
form.addEventListener('submit', function(e) {
e.preventDefault();
const nameValid = validateField(nameInput, nameError, 'נא להזין שם');
const contactValid = validateField(contactInput, contactError, 'נא להזין אימייל או טלפון');
if (!nameValid || !contactValid) {
return;
}
const submitBtn = form.querySelector('button[type="submit"]');
submitBtn.disabled = true;
submitBtn.innerHTML = '<span>שולח...</span>';
// Simulate submission
setTimeout(function() {
form.querySelectorAll('.form-group, .form-row, button[type="submit"]').forEach(function(el) {
el.style.display = 'none';
});
formSuccess.hidden = false;
console.log('Form submitted:', {
name: nameInput.value.trim(),
contact: contactInput.value.trim(),
business: document.getElementById('business').value.trim()
});
}, 800);
});
// Clear errors on input
[nameInput, contactInput].forEach(function(input) {
input.addEventListener('input', function() {
if (this.classList.contains('error')) {
this.classList.remove('error');
this.parentElement.querySelector('.form-error').textContent = '';
}
});
});
}
// Demo: Approval buttons
const approveBtn = document.querySelector('.approve-btn');
const rejectBtn = document.querySelector('.reject-btn');
const approvalCard = document.querySelector('.approval-card');
if (approveBtn && approvalCard) {
approveBtn.addEventListener('click', function() {
const textSpan = this.querySelector('.approve-btn-text');
if (textSpan) {
textSpan.textContent = 'בוצע!';
}
this.classList.add('approved');
approvalCard.style.borderColor = '#10b981';
setTimeout(function() {
if (textSpan) {
textSpan.textContent = 'אשר ובצע';
}
approveBtn.classList.remove('approved');
approvalCard.style.borderColor = '';
}, 2000);
});
}
if (rejectBtn && approvalCard) {
rejectBtn.addEventListener('click', function() {
const textSpan = this.querySelector('.reject-btn-text');
const originalText = textSpan ? textSpan.textContent : 'דחה';
approvalCard.style.opacity = '0.5';
this.classList.add('rejected');
if (textSpan) {
textSpan.textContent = 'נדחה';
}
setTimeout(function() {
approvalCard.style.opacity = '';
rejectBtn.classList.remove('rejected');
if (textSpan) {
textSpan.textContent = originalText;
}
}, 2000);
});
}
// Keyboard: close mobile menu on Escape
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape' && mobileMenuBtn && mobileMenu) {
mobileMenuBtn.setAttribute('aria-expanded', 'false');
mobileMenu.setAttribute('aria-hidden', 'true');
}
});
// Mouse vs keyboard focus
document.addEventListener('mousedown', function() {
document.body.classList.add('using-mouse');
});
document.addEventListener('keydown', function(e) {
if (e.key === 'Tab') {
document.body.classList.remove('using-mouse');
}
});
// Dynamic year
const yearSpan = document.getElementById('year');
if (yearSpan) {
yearSpan.textContent = new Date().getFullYear();
}
})();