CoreFiles by mySites.guru
admin-help.js113 lines, 3,862 bytes, from Joomla_6.2.0-Stable-Full_Package.zip
Raw History Compare with 6.1.4
md5
941b6a7d23a9c5159cfeb31d658d618a
sha1
be29722102d6759e929b938693398996d816f43b
sha256
4d6be12ca0bc16f010286d09ce4223f120d5c159942e2d81205f2638d7a0e43a
/**
  * @copyright   (C) 2021 Open Source Matters, Inc. <https://www.joomla.org>
  * @license     GNU General Public License version 2 or later; see LICENSE.txt
  */

document.addEventListener('DOMContentLoaded', function (event) {
  new MetisMenu('#helpmenu', {
    toggle: true
  });
  const helpIndex = document.getElementById('helpmenu');
  if (helpIndex) {
    helpIndex.querySelectorAll('a').forEach(element => element.addEventListener('click', () => {
      if (element.classList.contains('has-arrow')) {
        // 🔸 Action for a link to a folder, where <a class="has-arrow">
        helpIndex.querySelectorAll('a.has-arrow').forEach(a => {
          // Remove 'active' from all collapsed folders.
          if (element.classList.contains('mm-collapsed')) {
            element.classList.remove('active');
          }
        });
      } else {
        // Action for a link to an article.
        const id = element.dataset.id;
        if (id) {
          // First, reset all other links to default state
          helpIndex.querySelectorAll('a:not(has-arrow)').forEach(a => {
            if (a.dataset.id !== id) {
              a.classList.remove('active');
              a.removeAttribute('aria-current');
            } else {
              element.classList.add('active');
              a.setAttribute('aria-current', 'page');
            }
          });
          window.scroll(0, 0);
        }
        localStorage.setItem('helpIndex.lastClick', id);

        // In narrow screens, close the help menu after selecting an item.
        const btn = document.querySelector('button[data-bs-target="#help-index"]');
        const isVisible = !!(btn && btn.offsetParent !== null);
        if (isVisible) {
          document.querySelector('nav#help-index').classList.add('collapse');
          document.querySelector('nav#help-index').classList.remove('show');
        }
      }
    }));
  }

  // Async restore function
  function restoreMenu() {
    let lastClick = localStorage.getItem('helpIndex.lastClick');
    if (!lastClick) {
      lastClick = 'start-here';
    }
    const selectedLink = helpIndex.querySelector(`a[data-id="${lastClick}"]`);
    if (!selectedLink) return;

    // Collect parent list items top-down
    const lists = [];
    let parentLi = selectedLink.closest('li');
    while (parentLi && parentLi !== helpIndex) {
      const parentUl = parentLi.parentElement;
      const parentLiOfUl = parentUl.closest('li');
      if (parentLiOfUl) {
        const li = parentLiOfUl;
        if (li) lists.unshift(li);
      }
      parentLi = parentLiOfUl;
    }

    // Trigger clicks in sequence
    for (const li of lists) {
      li.classList.add('mm-active');
      li.querySelector('ul').classList.add('mm-show');
      li.querySelector('a').classList.add('active');
      li.querySelector('a').setAttribute('aria-expanded', true);
    }

    // Optional: highlight selected link
    selectedLink.classList.add('active');
    selectedLink.setAttribute('aria-current', 'page');

    // Give the submenu a moment to fully render before clicking
    selectedLink.click();
  }

  // Run restore after MetisMenu setup delay
  restoreMenu();
});

// Define Bootstrap breakpoints (in pixels)
const breakpoints = {
  md: 768};

// Collapse the Help menu on small screens (sm) by causing a page reload
function getCurrentBreakpoint() {
  const width = window.innerWidth;
  if (width < breakpoints.md) return 'sm';
  return 'xxl';
}
let currentBreakpoint = getCurrentBreakpoint();
let resizeTimeout;
window.addEventListener('resize', () => {
  clearTimeout(resizeTimeout);
  resizeTimeout = setTimeout(() => {
    const newBreakpoint = getCurrentBreakpoint();
    if (newBreakpoint !== currentBreakpoint) {
      // Breakpoint changed — reload the page
      location.reload();
    }
  }, 300); // delay in ms after resizing stops
});

The same content is in 8 releases, Joomla 6.2.0-alpha3 to 6.2.1-rc1. See them all, or every version of this file.