// Optimized JavaScript – Event Delegation & Performance-focused
document.addEventListener('DOMContentLoaded', () => {
const navContainer = document.querySelector('.header-nav');
// Set data-text attribute once
document.querySelectorAll('.header-nav-item a').forEach(link => {
link.setAttribute('data-text', link.textContent);
});
if(navContainer){
navContainer.addEventListener('mouseover', (e) => {
const targetLink = e.target.closest('.header-nav-item a');
if(targetLink){
document.querySelectorAll('.header-nav-item a').forEach(otherLink => {
if(otherLink !== targetLink){
otherLink.classList.add('nav-neighbor-wobble');
}
});
}
});
navContainer.addEventListener('mouseout', (e) => {
const targetLink = e.target.closest('.header-nav-item a');
if(targetLink){
document.querySelectorAll('.header-nav-item a').forEach(link => {
link.classList.remove('nav-neighbor-wobble');
});
}
});
}
});