Skip to content
document.addEventListener('DOMContentLoaded', function () {
const wpmlItems = document.querySelectorAll(
'.menu-item-wpml-ls-item.menu-item-has-children'
);
wpmlItems.forEach(function (item) {
const link = item.querySelector(':scope > a.has-submenu');
if (!link) return;
link.addEventListener('click', function (e) {
// Only change behavior on desktop
if (window.innerWidth <= 1024) {
return;
}
e.preventDefault();
e.stopPropagation();
const isOpen = item.classList.contains('wpml-click-open');
// Close other WPML language dropdowns
wpmlItems.forEach(function (otherItem) {
otherItem.classList.remove('wpml-click-open');
const otherLink = otherItem.querySelector(':scope > a.has-submenu');
if (otherLink) {
otherLink.setAttribute('aria-expanded', 'false');
}
});
// Open this one
if (!isOpen) {
item.classList.add('wpml-click-open');
link.setAttribute('aria-expanded', 'true');
}
});
});
// Close when clicking somewhere else
document.addEventListener('click', function (e) {
if (!e.target.closest('.menu-item-wpml-ls-item.menu-item-has-children')) {
wpmlItems.forEach(function (item) {
item.classList.remove('wpml-click-open');
const link = item.querySelector(':scope > a.has-submenu');
if (link) {
link.setAttribute('aria-expanded', 'false');
}
});
}
});
});