Commit 0a397e4f authored by David Suissa's avatar David Suissa
Browse files

Issue #3564892 by dydave: Fixed eslint validation errors in 'admin_toolbar.js' and minor clean-up.

parent 40fc5b84
Loading
Loading
Loading
Loading
Loading
+0 −11
Original line number Diff line number Diff line
@@ -202,13 +202,6 @@
            searchInputField.addEventListener('focus', () => {
              // Populate only when links array is empty (only the first time).
              if (menuLinks.length === 0) {
                // Exclude certain paths from the search results, such as the
                // front page.
                const getUrl = window.location;
                const baseUrl = `${getUrl.protocol}//${getUrl.host}/`;
                // Define paths to be excluded from the search results.
                const excludedPaths = [Drupal.url(''), baseUrl];

                // Collect all the links available in the admin toolbar trays
                // ('.toolbar-tray') with the drupal custom data attribute:
                // - 'data-drupal-link-system-path'.
@@ -217,10 +210,6 @@
                    `.toolbar-tray a[data-drupal-link-system-path]`,
                  )
                  .forEach((element) => {
                    // Exclude links with URLs matching the excluded paths.
                    if (excludedPaths.includes(element.href)) {
                      return;
                    }
                    // Save each link in the menuLinks array for filtering with
                    // autocomplete.
                    menuLinks.push({
+59 −27
Original line number Diff line number Diff line
(function ($, Drupal) {
/**
 * @file
 * Behaviors for the admin toolbar module.
 *
 * @param {Function} once
 *   The once library used to ensure behaviors are attached only once.
 * @param {Drupal} Drupal
 *   The Drupal global used to define behaviors.
 * @param {jQuery} $
 *   The jQuery library.
 */
((once, Drupal, $) => {
  /**
   * Initialize custom logic for the Admin Toolbar.
   *
   * @namespace Drupal.behaviors.adminToolbar
   *
   * @type {Object}
   *   More specifically, a Drupal behavior.
   *
   * @prop {Function} attach
   *   Attaches the behavior to add any custom logic to the initialization of
   *   the Admin Toolbar:
   *  - Remove the title attribute from menu links to avoid tooltip conflicts.
   *  - Add a very basic keyboard navigation to the toolbar menu.
   */
  Drupal.behaviors.adminToolbar = {
    attach: function (context, settings) {

      $('a.toolbar-icon', context).removeAttr('title');
    attach: (context) => {
      // Attach only when the whole document is loaded.
      if (context !== document) {
        return;
      }
      // Ensure this behavior is only called once, when the toolbar is loaded.
      once('admin-toolbar-default', 'body', context).forEach((element) => {
        // Avoid tooltip visual conflicts with toolbar menu items (#2630724).
        element
          .querySelectorAll('#toolbar-bar a.toolbar-icon')
          .forEach((item) => {
            item.removeAttribute('title');
          });

        // Make the toolbar menu navigable with keyboard.
      $('ul.toolbar-menu li.menu-item--expanded a', context).on('focusin', function () {
        $('li.menu-item--expanded', context).removeClass('hover-intent');
        $('ul.toolbar-menu li.menu-item--expanded a', element).on(
          'focusin',
          function focusIn() {
            $('li.menu-item--expanded', element).removeClass('hover-intent');
            $(this).parents('li.menu-item--expanded').addClass('hover-intent');
      });
          },
        );

      $('ul.toolbar-menu li.menu-item a', context).keydown(function (e) {
        if ((e.shiftKey && (e.keyCode || e.which) == 9)) {
          if ($(this).parent('.menu-item').prev().hasClass('menu-item--expanded')) {
        $('ul.toolbar-menu li.menu-item a', element).keydown(
          function keyDown(e) {
            if (e.shiftKey && (e.keyCode || e.which) === 9) {
              if (
                $(this)
                  .parent('.menu-item')
                  .prev()
                  .hasClass('menu-item--expanded')
              ) {
                $(this).parent('.menu-item').prev().addClass('hover-intent');
              }
            }
      });
          },
        );

      $('.toolbar-menu:first-child > .menu-item:not(.menu-item--expanded) a, .toolbar-tab > a', context).on('focusin', function () {
        $('.menu-item--expanded').removeClass('hover-intent');
        $('.toolbar-tab > a', element).on('focusin', () => {
          $('li.menu-item--expanded', element).removeClass('hover-intent');
        });

      $('.toolbar-menu:first-child > .menu-item', context).on('hover', function () {
        $(this, 'a').css("background: #fff;");
      });

      $('ul:not(.toolbar-menu)', context).on({
        mousemove: function () {
          $('li.menu-item--expanded').removeClass('hover-intent');
    },
        hover: function () {
          $('li.menu-item--expanded').removeClass('hover-intent');
        }
      });

    }
  };
})(jQuery, Drupal);
})(once, Drupal, jQuery);