Barbara Broda
Rybeńka
21/07/2023
<script> document.addEventListener("DOMContentLoaded", function() { const menuItems = document.querySelectorAll(".bricks-menu-item"); menuItems.forEach((menuItem) => { const subMenuToggle = menuItem.querySelector("a"); const subMenu = menuItem.querySelector(".sub-menu"); if (subMenuToggle && subMenu) { subMenuToggle.addEventListener("click", (e) => { e.preventDefault(); e.stopPropagation(); const parent = subMenuToggle.parentNode; const isVisible = parent.getAttribute("aria-expanded") === "true"; parent.setAttribute("aria-expanded", !isVisible); }); } }); document.addEventListener("click", () => { closeAllSubMenus(null); }); function closeAllSubMenus(excludeMenuItem) { menuItems.forEach((menuItem) => { if (menuItem !== excludeMenuItem) { const subMenu = menuItem.querySelector(".sub-menu"); if (subMenu) { const isDirectChild = excludeMenuItem && excludeMenuItem.contains(menuItem); const isAncestor = menuItem.contains(excludeMenuItem); if (!isDirectChild && !isAncestor) { menuItem.setAttribute("aria-expanded", "false"); } } } }); } }); </script>