CoreFiles by mySites.guru
menu.es6.js175 lines, 5,029 bytes, from Joomla_4.0.0-alpha9-Alpha-Full_Package.zip
Raw History Compare with 4.0.0-alpha8
md5
28fc788b86e31ee14a28698bc59b9dbb
sha1
4f4f11edb43210d87b9721122732f825e340ee43
sha256
bfcfb06c834f6a700cab85e4dcf0cb652f28457444094b37c7b44d98960c9b4f
/**
* PLEASE DO NOT MODIFY THIS FILE. WORK ON THE ES6 VERSION.
* OTHERWISE YOUR CHANGES WILL BE REPLACED ON THE NEXT BUILD.
**/

/**
 * @copyright  Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
 * @license    GNU General Public License version 2 or later; see LICENSE.txt
 */
(() => {
  'use strict';

  function topLevelMouseOver(el, settings) {
    const ulChild = el.querySelector('ul');

    if (ulChild) {
      ulChild.setAttribute('aria-hidden', 'false');
      ulChild.classList.add(settings.menuHoverClass);
    }
  }

  function topLevelMouseOut(el, settings) {
    const ulChild = el.querySelector('ul');

    if (ulChild) {
      ulChild.setAttribute('aria-hidden', 'true');
      ulChild.classList.remove(settings.menuHoverClass);
    }
  }

  function setupNavigation(nav) {
    const settings = {
      menuHoverClass: 'show-menu',
      dir: 'ltr'
    };
    const topLevelChilds = nav.querySelectorAll(':scope > li'); // Set tabIndex to -1 so that top_level_childs can't receive focus until menu is open

    topLevelChilds.forEach(topLevelEl => {
      const linkEl = topLevelEl.querySelector('a');

      if (linkEl) {
        linkEl.tabIndex = '0';
        linkEl.addEventListener('mouseover', topLevelMouseOver(topLevelEl, settings));
        linkEl.addEventListener('mouseout', topLevelMouseOut(topLevelEl, settings));
      }

      const spanEl = topLevelEl.querySelector('span');

      if (spanEl) {
        spanEl.tabIndex = '0';
        spanEl.addEventListener('mouseover', topLevelMouseOver(topLevelEl, settings));
        spanEl.addEventListener('mouseout', topLevelMouseOut(topLevelEl, settings));
      }

      topLevelEl.addEventListener('mouseover', event => {
        const curEl = event.target;
        const ulChild = curEl.querySelector('ul');

        if (ulChild) {
          ulChild.setAttribute('aria-hidden', 'false');
          ulChild.classList.add(settings.menuHoverClass);
        }
      });
      topLevelEl.addEventListener('mouseout', event => {
        const curEl = event.target;
        const ulChild = curEl.querySelector('ul');

        if (ulChild) {
          ulChild.setAttribute('aria-hidden', 'true');
          ulChild.classList.remove(settings.menuHoverClass);
        }
      });
      topLevelEl.addEventListener('focus', event => {
        const curEl = event.target;
        const ulChild = curEl.querySelector('ul');

        if (ulChild) {
          ulChild.setAttribute('aria-hidden', 'true');
          ulChild.classList.add(settings.menuHoverClass);
        }
      });
      topLevelEl.addEventListener('blur', event => {
        const curEl = event.target;
        const ulChild = curEl.querySelector('ul');

        if (ulChild) {
          ulChild.setAttribute('aria-hidden', 'false');
          ulChild.classList.remove(settings.menuHoverClass);
        }
      });
      topLevelEl.addEventListener('keydown', event => {
        const keyName = event.key;
        const curEl = event.target;
        const curLiEl = curEl.parentElement;
        const curUlEl = curLiEl.parentElement;
        let prevLiEl = curLiEl.previousElementSibling;
        let nextLiEl = curLiEl.nextElementSibling;

        if (!prevLiEl) {
          prevLiEl = curUlEl.children[curUlEl.children.length - 1];
        }

        if (!nextLiEl) {
          [nextLiEl] = curUlEl.children;
        }

        switch (keyName) {
          case 'ArrowLeft':
            event.preventDefault();

            if (settings.dir === 'rtl') {
              nextLiEl.children[0].focus();
            } else {
              prevLiEl.children[0].focus();
            }

            break;

          case 'ArrowRight':
            event.preventDefault();

            if (settings.dir === 'rtl') {
              prevLiEl.children[0].focus();
            } else {
              nextLiEl.children[0].focus();
            }

            break;

          case 'ArrowUp':
            {
              event.preventDefault();
              const parent = curLiEl.parentElement.parentElement;

              if (parent.nodeName === 'LI') {
                parent.children[0].focus();
              } else {
                prevLiEl.children[0].focus();
              }

              break;
            }

          case 'ArrowDown':
            event.preventDefault();

            if (curLiEl.classList.contains('parent')) {
              const child = curLiEl.querySelector('ul');

              if (child != null) {
                const childLi = child.querySelector('li');
                childLi.children[0].focus();
              } else {
                nextLiEl.children[0].focus();
              }
            } else {
              nextLiEl.children[0].focus();
            }

            break;

          default:
            break;
        }
      });
    });
  }

  document.addEventListener('DOMContentLoaded', () => {
    const navs = document.querySelectorAll('.nav');
    [].forEach.call(navs, nav => {
      setupNavigation(nav);
    });
  });
})();

The same content is in 5 releases, Joomla 4.0.0-alpha8 to 4.0.0-alpha12. See them all, or every version of this file.