176 lines
5.7 KiB
JavaScript
176 lines
5.7 KiB
JavaScript
(function() {
|
|
'use strict';
|
|
|
|
// Mobile Menu Toggle
|
|
var mobileMenuToggle = document.querySelector('.mobile-menu-toggle');
|
|
var mobileMenu = document.getElementById('mobile-menu');
|
|
|
|
if (mobileMenuToggle && mobileMenu) {
|
|
mobileMenuToggle.addEventListener('click', function() {
|
|
var isExpanded = this.getAttribute('aria-expanded') === 'true';
|
|
this.setAttribute('aria-expanded', !isExpanded);
|
|
mobileMenu.hidden = isExpanded;
|
|
|
|
// Animate hamburger
|
|
var lines = this.querySelectorAll('.hamburger-line');
|
|
if (!isExpanded) {
|
|
lines[0].style.transform = 'rotate(45deg) translate(5px, 5px)';
|
|
lines[1].style.opacity = '0';
|
|
lines[2].style.transform = 'rotate(-45deg) translate(5px, -5px)';
|
|
} else {
|
|
lines[0].style.transform = '';
|
|
lines[1].style.opacity = '';
|
|
lines[2].style.transform = '';
|
|
}
|
|
});
|
|
|
|
// Close menu when clicking a link
|
|
mobileMenu.querySelectorAll('a').forEach(function(link) {
|
|
link.addEventListener('click', function() {
|
|
mobileMenuToggle.setAttribute('aria-expanded', 'false');
|
|
mobileMenu.hidden = true;
|
|
var lines = mobileMenuToggle.querySelectorAll('.hamburger-line');
|
|
lines[0].style.transform = '';
|
|
lines[1].style.opacity = '';
|
|
lines[2].style.transform = '';
|
|
});
|
|
});
|
|
}
|
|
|
|
// Scroll Reveal
|
|
var revealElements = document.querySelectorAll('.service-card, .benefit-item, .stat-card, .section-header');
|
|
|
|
if ('IntersectionObserver' in window) {
|
|
var revealObserver = new IntersectionObserver(function(entries) {
|
|
entries.forEach(function(entry) {
|
|
if (entry.isIntersecting) {
|
|
entry.target.classList.add('reveal', 'revealed');
|
|
revealObserver.unobserve(entry.target);
|
|
}
|
|
});
|
|
}, {
|
|
threshold: 0.1,
|
|
rootMargin: '0px 0px -50px 0px'
|
|
});
|
|
|
|
revealElements.forEach(function(el, index) {
|
|
el.classList.add('reveal');
|
|
el.style.transitionDelay = Math.min((index % 4) * 0.08, 0.3) + 's';
|
|
revealObserver.observe(el);
|
|
});
|
|
} else {
|
|
revealElements.forEach(function(el) {
|
|
el.classList.add('reveal', 'revealed');
|
|
});
|
|
}
|
|
|
|
// Form Validation
|
|
var contactForm = document.getElementById('contact-form');
|
|
var formStatus = document.getElementById('form-status');
|
|
|
|
if (contactForm) {
|
|
contactForm.addEventListener('submit', function(e) {
|
|
e.preventDefault();
|
|
|
|
var isValid = true;
|
|
var formGroups = this.querySelectorAll('.form-group');
|
|
|
|
formGroups.forEach(function(group) {
|
|
group.classList.remove('has-error');
|
|
});
|
|
|
|
// Validate name
|
|
var nameInput = this.querySelector('#name');
|
|
if (nameInput && nameInput.value.trim().length < 2) {
|
|
nameInput.closest('.form-group').classList.add('has-error');
|
|
isValid = false;
|
|
}
|
|
|
|
// Validate phone
|
|
var phoneInput = this.querySelector('#phone');
|
|
var phoneRegex = /^[\d\-+\s()]{9,}$/;
|
|
if (phoneInput && !phoneRegex.test(phoneInput.value.trim())) {
|
|
phoneInput.closest('.form-group').classList.add('has-error');
|
|
isValid = false;
|
|
}
|
|
|
|
// Validate service selection
|
|
var serviceSelect = this.querySelector('#service');
|
|
if (serviceSelect && !serviceSelect.value) {
|
|
serviceSelect.closest('.form-group').classList.add('has-error');
|
|
isValid = false;
|
|
}
|
|
|
|
if (isValid) {
|
|
// Announce to screen readers
|
|
if (formStatus) {
|
|
formStatus.textContent = 'הבקשה נשלחה בהצלחה. ניצור איתכם קשר בהקדם.';
|
|
}
|
|
|
|
// Show success message
|
|
contactForm.innerHTML =
|
|
'<div class="form-success">' +
|
|
'<svg class="form-success-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">' +
|
|
'<circle cx="12" cy="12" r="10"/>' +
|
|
'<path d="M8 12l3 3 5-6"/>' +
|
|
'</svg>' +
|
|
'<h3>הבקשה נשלחה בהצלחה!</h3>' +
|
|
'<p>ניצור איתכם קשר בהקדם האפשרי</p>' +
|
|
'</div>';
|
|
}
|
|
});
|
|
|
|
// Real-time validation feedback
|
|
var inputs = contactForm.querySelectorAll('.form-input');
|
|
inputs.forEach(function(input) {
|
|
input.addEventListener('blur', function() {
|
|
var group = this.closest('.form-group');
|
|
if (this.required && !this.value.trim()) {
|
|
group.classList.add('has-error');
|
|
} else {
|
|
group.classList.remove('has-error');
|
|
}
|
|
});
|
|
|
|
input.addEventListener('input', function() {
|
|
this.closest('.form-group').classList.remove('has-error');
|
|
});
|
|
});
|
|
}
|
|
|
|
// Smooth scroll for anchor links
|
|
document.querySelectorAll('a[href^="#"]').forEach(function(anchor) {
|
|
anchor.addEventListener('click', function(e) {
|
|
var targetId = this.getAttribute('href');
|
|
if (targetId === '#') return;
|
|
|
|
var target = document.querySelector(targetId);
|
|
if (target) {
|
|
e.preventDefault();
|
|
var headerOffset = 80;
|
|
var elementPosition = target.getBoundingClientRect().top;
|
|
var offsetPosition = elementPosition + window.pageYOffset - headerOffset;
|
|
|
|
window.scrollTo({
|
|
top: offsetPosition,
|
|
behavior: 'smooth'
|
|
});
|
|
}
|
|
});
|
|
});
|
|
|
|
// Header background on scroll
|
|
var header = document.querySelector('.site-header');
|
|
if (header) {
|
|
window.addEventListener('scroll', function() {
|
|
var currentScroll = window.pageYOffset;
|
|
|
|
if (currentScroll > 100) {
|
|
header.style.background = 'rgba(10, 22, 40, 0.98)';
|
|
} else {
|
|
header.style.background = 'rgba(10, 22, 40, 0.9)';
|
|
}
|
|
}, { passive: true });
|
|
}
|
|
})();
|