<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>

Nowy

Wyświetlanie 1–16 z 598 wyników