| |
| |
| |
| |
|
|
| (function() { |
| 'use strict'; |
| |
| let initialized = false; |
| |
| function hideAllSiblingMenus(currentMenuItem, parentMenu) { |
| if (!parentMenu) return; |
| |
| |
| const siblings = Array.from(parentMenu.children); |
| |
| siblings.forEach(sibling => { |
| if (sibling !== currentMenuItem) { |
| |
| const directUlChildren = Array.from(sibling.children).filter(child => child.tagName === 'UL'); |
| directUlChildren.forEach(submenu => { |
| submenu.style.opacity = '0'; |
| submenu.style.visibility = 'hidden'; |
| }); |
| } |
| }); |
| } |
| |
| function initMenuHoverControl() { |
| |
| if (initialized) return; |
| initialized = true; |
| |
| |
| const allMenuItems = document.querySelectorAll('.dropdown-menu > li:has(> ul), .dropdown-menu ul > li:has(> ul), li:has(> ul) > ul > li:has(> ul)'); |
| |
| allMenuItems.forEach(menuItem => { |
| |
| const submenu = Array.from(menuItem.children).find(child => child.tagName === 'UL'); |
| if (!submenu) return; |
| |
| |
| if (menuItem.dataset.hoverControlInitialized) return; |
| menuItem.dataset.hoverControlInitialized = 'true'; |
| |
| |
| const parentMenu = menuItem.parentElement; |
| if (!parentMenu) return; |
| |
| |
| menuItem.addEventListener('mouseenter', function(e) { |
| |
| hideAllSiblingMenus(menuItem, parentMenu); |
| |
| |
| submenu.style.opacity = '1'; |
| submenu.style.visibility = 'visible'; |
| submenu.style.transform = 'translateX(0)'; |
| }); |
| |
| |
| submenu.addEventListener('mouseenter', function(e) { |
| |
| submenu.style.opacity = '1'; |
| submenu.style.visibility = 'visible'; |
| }); |
| |
| |
| submenu.addEventListener('mouseleave', function(e) { |
| setTimeout(() => { |
| |
| if (!menuItem.matches(':hover') && !submenu.matches(':hover')) { |
| submenu.style.opacity = '0'; |
| submenu.style.visibility = 'hidden'; |
| } |
| }, 150); |
| }); |
| |
| |
| menuItem.addEventListener('mouseleave', function(e) { |
| setTimeout(() => { |
| |
| if (!menuItem.matches(':hover') && !submenu.matches(':hover')) { |
| submenu.style.opacity = '0'; |
| submenu.style.visibility = 'hidden'; |
| } |
| }, 150); |
| }); |
| }); |
| |
| |
| const topLevelDropdowns = document.querySelectorAll('.nav-menu > .dropdown'); |
| |
| topLevelDropdowns.forEach(dropdown => { |
| const dropdownMenu = dropdown.querySelector('.dropdown-menu'); |
| if (!dropdownMenu) return; |
| |
| |
| if (dropdown.dataset.hoverControlInitialized) return; |
| dropdown.dataset.hoverControlInitialized = 'true'; |
| |
| dropdown.addEventListener('mouseenter', function() { |
| |
| topLevelDropdowns.forEach(otherDropdown => { |
| if (otherDropdown !== dropdown) { |
| const otherMenu = otherDropdown.querySelector('.dropdown-menu'); |
| if (otherMenu) { |
| otherMenu.style.opacity = '0'; |
| otherMenu.style.visibility = 'hidden'; |
| } |
| } |
| }); |
| |
| |
| dropdownMenu.style.opacity = '1'; |
| dropdownMenu.style.visibility = 'visible'; |
| dropdownMenu.style.transform = 'translateY(0)'; |
| }); |
| |
| dropdown.addEventListener('mouseleave', function() { |
| setTimeout(() => { |
| if (!dropdown.matches(':hover') && !dropdownMenu.matches(':hover')) { |
| dropdownMenu.style.opacity = '0'; |
| dropdownMenu.style.visibility = 'hidden'; |
| } |
| }, 150); |
| }); |
| }); |
| } |
| |
| function reinitMenuHoverControl() { |
| initialized = false; |
| initMenuHoverControl(); |
| } |
| |
| |
| if (document.readyState === 'loading') { |
| document.addEventListener('DOMContentLoaded', initMenuHoverControl); |
| } else { |
| initMenuHoverControl(); |
| } |
| |
| |
| setTimeout(reinitMenuHoverControl, 600); |
| setTimeout(reinitMenuHoverControl, 1000); |
| |
| |
| if (typeof MutationObserver !== 'undefined') { |
| const observer = new MutationObserver(function(mutations) { |
| let shouldUpdate = false; |
| mutations.forEach(function(mutation) { |
| if (mutation.addedNodes.length > 0) { |
| mutation.addedNodes.forEach(function(node) { |
| if (node.nodeType === 1 && ( |
| (node.classList && ( |
| node.classList.contains('dropdown-menu') || |
| node.classList.contains('dropdown') |
| )) || |
| node.querySelector('.dropdown-menu') || |
| node.querySelector('.dropdown') |
| )) { |
| shouldUpdate = true; |
| } |
| }); |
| } |
| }); |
| if (shouldUpdate) { |
| setTimeout(reinitMenuHoverControl, 100); |
| } |
| }); |
| |
| if (document.body) { |
| observer.observe(document.body, { |
| childList: true, |
| subtree: true |
| }); |
| } |
| } |
| })(); |
|
|