((Drupal, once, { computePosition, offset, arrow, shift, flip }) => { /** * The wrapping element for the navigation sidebar. */ let sidebar; // Gin Custom start --------------------- const breakpointLarge = 1280; // Gin Custom end ------------------------ /** * Collapsed toolbar keydown handling vars. */ let firstFocusableEl; const firstLevelToolbarItems = Array.from(document.querySelectorAll('.navigation__logo, .toolbar-menu > .toolbar-menu__item--level-1 > .toolbar-link')); // 1st level menu items. const keys = { tab: 9, esc: 27, space: 32, }; let currentIndex, subIndex; /** * Informs in the navigation is expanded. * * @returns {boolean} - If the navigation is expanded. */ function isNavExpanded() { return document.documentElement.classList.contains('admin-toolbar-expanded'); } /** * If active item is in the menu trail, then expand the navigation so it is * open, and then scroll to it. This happens on page load and when * transitioning between expanded and collapsed states. */ function autoExpandToActiveMenuItem() { const activeItems = sidebar.querySelectorAll('.is-active'); closeAllSubmenus(); activeItems.forEach(activeItem => { activeItem?.closest('.toolbar-menu__item.toolbar-menu__item--level-2')?.classList.add('toolbar-menu__item--expanded'); activeItem?.closest('.toolbar-menu__item.toolbar-menu__item--level-2')?.classList.add('active-path'); // Only expand level one if sidebar is in expanded state. // Gin Custom start --------------------- activeItem?.closest('.toolbar-menu__item.toolbar-menu__item--level-1')?.classList.add('active-path'); // Gin Custom end ------------------------ }); // Scroll to the open trays so they're in view. const expandedTray = sidebar.querySelector('.toolbar-menu__item.toolbar-menu__item--expanded'); expandedTray?.scrollIntoView({ behavior: 'smooth' }); // Gin Custom start --------------------- // checkOverflow(); // Gin Custom end ----------------------- } /** * Searches the sidebar for all menu items, and when it finds the menu item * for the link that it's currently on, it will add relevant CSS classes to it * so it can be styled and opened to. * * @todo once we move into the Drupal core menu system, we should be able to * remove this. */ function markCurrentPageInMenu() { // Check all links on the sidebar (that are not in the shortcutsNav //
) to see if they are the current page. If so, set a `current` // and `is-active` CSS class on the parent
  • . const sidebarLinks = sidebar.querySelectorAll('a.toolbar-link:not(.menu--shortcuts *)'); sidebarLinks.forEach(link => { if (link.href === document.URL) { link.parentElement.classList.add('current', 'is-active'); } }); // Gin Custom start --------------------- // Mark overview pages as active. const sidebarTitles = sidebar.querySelectorAll('.toolbar-menu__item--level-1[data-url]'); sidebarTitles.forEach(title => { if (title.getAttribute('data-url') === window.location.pathname) { title.querySelector('button.toolbar-link')?.classList.add('current', 'is-active'); } }); // Gin Custom end ------------------------ } /** * Expand / collapse sidebar * * @param {boolean} toState - the state which the sidebar will be * transitioning to (true if expanded, false if collapsed). */ function expandCollapseSidebar(toState) { const expandCollapseButton = sidebar.querySelector('[aria-controls="admin-toolbar"]'); if (toState) closeTooltip(); document.documentElement.classList.toggle('admin-toolbar-expanded', toState); Drupal.displace(true); sidebar.querySelector('#sidebar-state').textContent = toState ? Drupal.t('Collapse sidebar') : Drupal.t('Expand sidebar'); expandCollapseButton.setAttribute('aria-expanded', toState); localStorage.setItem('Drupal.navigation.sidebarExpanded', toState); autoExpandToActiveMenuItem(); if (toState) { flyoutTooltipDetach(); } else { flyoutTooltipInit(); } // Gin Custom start --------------------- if (toState === true && window.innerWidth < breakpointLarge) { Drupal.ginSidebar.collapseSidebar(); } // Gin Custom end ------------------------ } /** * Show shadow on sticky section only when expanded and content is * overflowing. * * @todo this should be using either CSS only or Intersection Observer instead * of getBoundingClientRect(). */ // Gin Custom start --------------------- // function checkOverflow() { // if (isNavExpanded()) { // const stickyMenu = sidebar.querySelector('.admin-toolbar__sticky-section'); // const mainMenu = sidebar.querySelector('#menu-builder'); // @todo why are we using ID here? // const stickyMenuTopPos = stickyMenu?.getBoundingClientRect().top; // const mainMenuBottomPos = mainMenu?.getBoundingClientRect().bottom; // stickyMenu?.classList.toggle('shadow', mainMenuBottomPos > stickyMenuTopPos); // } // } // Gin Custom end ------------------------ /** * Calculate and place flyouts relative to their parent links using the * floating UI library. * * @param {Element} hoveredEl -
  • element that was hovered over. */ function positionFlyout(hoveredEl) { const anchorEl = hoveredEl.querySelector('.toolbar-link'); // This is the