235 lines
7.0 KiB
JavaScript
235 lines
7.0 KiB
JavaScript
(function() {
|
|
'use strict';
|
|
|
|
// Header scroll effect
|
|
var header = document.querySelector('.header');
|
|
|
|
function handleScroll() {
|
|
var currentScroll = window.pageYOffset;
|
|
|
|
if (currentScroll > 50) {
|
|
header.classList.add('scrolled');
|
|
} else {
|
|
header.classList.remove('scrolled');
|
|
}
|
|
}
|
|
|
|
window.addEventListener('scroll', handleScroll, { passive: true });
|
|
|
|
// Mobile navigation toggle
|
|
var navToggle = document.querySelector('.nav-toggle');
|
|
var navLinks = document.querySelector('.nav-links');
|
|
|
|
if (navToggle && navLinks) {
|
|
navToggle.addEventListener('click', function() {
|
|
var isExpanded = navToggle.getAttribute('aria-expanded') === 'true';
|
|
navToggle.setAttribute('aria-expanded', !isExpanded);
|
|
navToggle.setAttribute('aria-label', isExpanded ? 'פתיחת תפריט ניווט' : 'סגירת תפריט ניווט');
|
|
navLinks.classList.toggle('active');
|
|
|
|
// Animate hamburger
|
|
var spans = navToggle.querySelectorAll('span');
|
|
if (!isExpanded) {
|
|
spans[0].style.transform = 'rotate(45deg) translate(5px, 5px)';
|
|
spans[1].style.opacity = '0';
|
|
spans[2].style.transform = 'rotate(-45deg) translate(5px, -5px)';
|
|
} else {
|
|
spans[0].style.transform = '';
|
|
spans[1].style.opacity = '';
|
|
spans[2].style.transform = '';
|
|
}
|
|
});
|
|
|
|
// Close menu on link click
|
|
navLinks.querySelectorAll('a').forEach(function(link) {
|
|
link.addEventListener('click', function() {
|
|
navLinks.classList.remove('active');
|
|
navToggle.setAttribute('aria-expanded', 'false');
|
|
navToggle.setAttribute('aria-label', 'פתיחת תפריט ניווט');
|
|
var spans = navToggle.querySelectorAll('span');
|
|
spans[0].style.transform = '';
|
|
spans[1].style.opacity = '';
|
|
spans[2].style.transform = '';
|
|
});
|
|
});
|
|
}
|
|
|
|
// Reveal on scroll
|
|
var revealElements = document.querySelectorAll('.reveal');
|
|
|
|
if ('IntersectionObserver' in window) {
|
|
var revealObserver = new IntersectionObserver(function(entries) {
|
|
entries.forEach(function(entry) {
|
|
if (entry.isIntersecting) {
|
|
entry.target.classList.add('visible');
|
|
revealObserver.unobserve(entry.target);
|
|
}
|
|
});
|
|
}, {
|
|
threshold: 0.1,
|
|
rootMargin: '0px 0px -50px 0px'
|
|
});
|
|
|
|
revealElements.forEach(function(el) {
|
|
revealObserver.observe(el);
|
|
});
|
|
} else {
|
|
// Fallback for browsers without IntersectionObserver
|
|
revealElements.forEach(function(el) {
|
|
el.classList.add('visible');
|
|
});
|
|
}
|
|
|
|
// 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 targetElement = document.querySelector(targetId);
|
|
if (targetElement) {
|
|
e.preventDefault();
|
|
var headerOffset = 80;
|
|
var elementPosition = targetElement.getBoundingClientRect().top;
|
|
var offsetPosition = elementPosition + window.pageYOffset - headerOffset;
|
|
|
|
window.scrollTo({
|
|
top: offsetPosition,
|
|
behavior: 'smooth'
|
|
});
|
|
}
|
|
});
|
|
});
|
|
|
|
// Add subtle parallax to hero elements (only if motion is allowed)
|
|
var heroContent = document.querySelector('.hero-content');
|
|
var heroLines = document.querySelector('.hero-lines');
|
|
var prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
|
|
if (heroContent && heroLines && !prefersReducedMotion) {
|
|
window.addEventListener('scroll', function() {
|
|
var scrolled = window.pageYOffset;
|
|
var heroSection = document.querySelector('.hero');
|
|
if (!heroSection) return;
|
|
var heroHeight = heroSection.offsetHeight;
|
|
|
|
if (scrolled < heroHeight) {
|
|
var rate = scrolled * 0.3;
|
|
heroContent.style.transform = 'translateY(' + rate + 'px)';
|
|
heroLines.style.transform = 'translateY(' + (rate * 0.5) + 'px)';
|
|
}
|
|
}, { passive: true });
|
|
}
|
|
|
|
// Gallery hover effect enhancement
|
|
var galleryItems = document.querySelectorAll('.gallery-item');
|
|
|
|
galleryItems.forEach(function(item) {
|
|
item.addEventListener('mouseenter', function() {
|
|
galleryItems.forEach(function(otherItem) {
|
|
if (otherItem !== item) {
|
|
otherItem.style.opacity = '0.6';
|
|
}
|
|
});
|
|
});
|
|
|
|
item.addEventListener('mouseleave', function() {
|
|
galleryItems.forEach(function(otherItem) {
|
|
otherItem.style.opacity = '';
|
|
});
|
|
});
|
|
});
|
|
|
|
// Demo Popup functionality
|
|
var popup = document.getElementById('demoPopup');
|
|
var popupCloseBtn = popup ? popup.querySelector('.popup-close') : null;
|
|
var popupBackdrop = popup ? popup.querySelector('.popup-backdrop') : null;
|
|
var POPUP_DELAY = 5000; // 5 seconds
|
|
var POPUP_STORAGE_KEY = 'demoPopupShown';
|
|
|
|
function showPopup() {
|
|
if (!popup) return;
|
|
popup.classList.add('active');
|
|
document.body.classList.add('popup-open');
|
|
// Focus the close button for accessibility
|
|
if (popupCloseBtn) {
|
|
popupCloseBtn.focus();
|
|
}
|
|
}
|
|
|
|
function hidePopup() {
|
|
if (!popup) return;
|
|
popup.classList.remove('active');
|
|
document.body.classList.remove('popup-open');
|
|
// Mark as shown in session storage
|
|
try {
|
|
sessionStorage.setItem(POPUP_STORAGE_KEY, 'true');
|
|
} catch (e) {
|
|
// Session storage not available
|
|
}
|
|
}
|
|
|
|
function initPopup() {
|
|
if (!popup) return;
|
|
|
|
// Check if popup was already shown this session
|
|
try {
|
|
if (sessionStorage.getItem(POPUP_STORAGE_KEY) === 'true') {
|
|
return;
|
|
}
|
|
} catch (e) {
|
|
// Session storage not available, continue
|
|
}
|
|
|
|
// Show popup after delay (only if motion is not reduced)
|
|
if (!prefersReducedMotion) {
|
|
setTimeout(showPopup, POPUP_DELAY);
|
|
} else {
|
|
showPopup();
|
|
}
|
|
}
|
|
|
|
// Close popup on close button click
|
|
if (popupCloseBtn) {
|
|
popupCloseBtn.addEventListener('click', hidePopup);
|
|
}
|
|
|
|
// Close popup on backdrop click
|
|
if (popupBackdrop) {
|
|
popupBackdrop.addEventListener('click', hidePopup);
|
|
}
|
|
|
|
// Close popup on Escape key
|
|
document.addEventListener('keydown', function(e) {
|
|
if (e.key === 'Escape' && popup && popup.classList.contains('active')) {
|
|
hidePopup();
|
|
}
|
|
});
|
|
|
|
// Trap focus inside popup when open
|
|
if (popup) {
|
|
popup.addEventListener('keydown', function(e) {
|
|
if (e.key !== 'Tab') return;
|
|
|
|
var focusableElements = popup.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');
|
|
var firstElement = focusableElements[0];
|
|
var lastElement = focusableElements[focusableElements.length - 1];
|
|
|
|
if (e.shiftKey) {
|
|
if (document.activeElement === firstElement) {
|
|
lastElement.focus();
|
|
e.preventDefault();
|
|
}
|
|
} else {
|
|
if (document.activeElement === lastElement) {
|
|
firstElement.focus();
|
|
e.preventDefault();
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
// Initialize popup
|
|
initPopup();
|
|
|
|
})(); |