(function () {
// ── Desktop Dropdowns (hover) ──────────────────────────────────────────
document.querySelectorAll('[nav="dropdown"]').forEach(function (li) {
var panel = li.querySelector('[dropdown="open"]');
if (!panel) return;
var closeTimer;
var CLOSE_DELAY = 300;
function scheduleClose() {
closeTimer = setTimeout(function () {
panel.style.display = 'none';
}, CLOSE_DELAY);
}
function cancelClose() {
clearTimeout(closeTimer);
}
li.addEventListener('mouseenter', function () {
cancelClose();
panel.style.display = 'flex';
});
li.addEventListener('mouseleave', function (e) {
// If cursor moves directly into the panel (abs. positioned child outside li bbox),
// don't start the close timer at all.
if (e.relatedTarget && (panel === e.relatedTarget || panel.contains(e.relatedTarget))) {
return;
}
scheduleClose();
});
panel.addEventListener('mouseenter', cancelClose);
panel.addEventListener('mouseleave', function (e) {
// Don't close if re-entering the parent li trigger area
if (e.relatedTarget && (li === e.relatedTarget || li.contains(e.relatedTarget))) {
return;
}
scheduleClose();
});
});
// Close all dropdowns when clicking outside
document.addEventListener('click', function (e) {
if (!e.target.closest('[nav="dropdown"]')) {
document.querySelectorAll('[dropdown="open"]').forEach(function (p) {
p.style.display = 'none';
});
}
});
// ── Mobile Nav Accordion ───────────────────────────────────────────────
// Runs after DOMContentLoaded so the mobile menu is in the DOM.
// Groups flat li.mobile_navbar_item siblings under their li.mobile_navbar_link
// header and makes each header a clickable accordion trigger.
var mobileHeaders = document.querySelectorAll('#menu > .mobile_navbar_list > .mobile_navbar_link');
mobileHeaders.forEach(function (header) {
// Collect all following siblings that are items (not headers)
var items = [];
var sibling = header.nextElementSibling;
while (sibling && !sibling.classList.contains('mobile_navbar_link')) {
items.push(sibling);
sibling = sibling.nextElementSibling;
}
if (items.length === 0) return;
// Wrap items in collapsible container
var body = document.createElement('ul');
body.className = 'mobile-accordion-body w-list-unstyled';
body.setAttribute('role', 'list');
header.parentNode.insertBefore(body, items[0]);
items.forEach(function (item) { body.appendChild(item); });
// Add chevron arrow to header
var arrow = document.createElement('span');
arrow.className = 'mobile-accordion-arrow';
arrow.setAttribute('aria-hidden', 'true');
arrow.innerHTML = '';
header.appendChild(arrow);
header.classList.add('mobile-accordion-trigger');
// Click: toggle this section, close others
header.addEventListener('click', function () {
var isOpen = header.classList.contains('is-open');
document.querySelectorAll('#menu .mobile_navbar_link.is-open').forEach(function (h) {
h.classList.remove('is-open');
});
document.querySelectorAll('#menu .mobile-accordion-body.is-open').forEach(function (b) {
b.classList.remove('is-open');
});
if (!isOpen) {
header.classList.add('is-open');
body.classList.add('is-open');
}
});
});
// ── Footer Mobile Accordion ────────────────────────────────────────────
var footerHeaders = document.querySelectorAll('.mobile-footer_links .mobile_navbar_link');
footerHeaders.forEach(function (header) {
var items = [];
var sibling = header.nextElementSibling;
while (sibling && !sibling.classList.contains('mobile_navbar_link')) {
items.push(sibling);
sibling = sibling.nextElementSibling;
}
if (items.length === 0) return;
var body = document.createElement('ul');
body.className = 'footer-accordion-body w-list-unstyled';
body.setAttribute('role', 'list');
header.parentNode.insertBefore(body, items[0]);
items.forEach(function (item) { body.appendChild(item); });
var arrow = document.createElement('span');
arrow.className = 'mobile-accordion-arrow';
arrow.setAttribute('aria-hidden', 'true');
arrow.innerHTML = '';
header.appendChild(arrow);
header.classList.add('footer-accordion-trigger');
header.addEventListener('click', function () {
var isOpen = header.classList.contains('is-open');
document.querySelectorAll('.mobile-footer_links .mobile_navbar_link.is-open').forEach(function (h) {
h.classList.remove('is-open');
});
document.querySelectorAll('.mobile-footer_links .footer-accordion-body.is-open').forEach(function (b) {
b.classList.remove('is-open');
});
if (!isOpen) {
header.classList.add('is-open');
body.classList.add('is-open');
}
});
});
// ── Mobile Menu Toggle ─────────────────────────────────────────────────
var menuBtn = document.querySelector('[menu="open"]');
var mobilePanel = document.getElementById('menu');
var line1 = document.getElementById('linie1');
var line2 = document.getElementById('linie2');
var line3 = document.getElementById('linie3');
var menuOpen = false;
if (menuBtn && mobilePanel) {
// Prepare transition
mobilePanel.style.transition = 'inset 0.3s ease';
menuBtn.addEventListener('click', function () {
menuOpen = !menuOpen;
if (menuOpen) {
mobilePanel.style.display = 'block';
// Small delay so display:block is applied before inset transition
requestAnimationFrame(function () {
mobilePanel.style.inset = '0 0 0 auto';
});
if (line1) line1.style.transform = 'translateY(7px) rotate(45deg)';
if (line2) line2.style.opacity = '0';
if (line3) line3.style.transform = 'translateY(-7px) rotate(-45deg)';
} else {
mobilePanel.style.inset = '0 -50rem 0 auto';
if (line1) line1.style.transform = '';
if (line2) line2.style.opacity = '';
if (line3) line3.style.transform = '';
setTimeout(function () {
if (!menuOpen) mobilePanel.style.display = 'none';
}, 300);
}
});
}
})();