X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Ftoolbar%2Fjs%2Ftoolbar.menu.es6.js;fp=web%2Fcore%2Fmodules%2Ftoolbar%2Fjs%2Ftoolbar.menu.es6.js;h=614574ef72640d6167b07ab13a9e7976f51220a4;hp=03fd41f371dff0e8c61d48fa195f8217852dd6cd;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hpb=74df008bdbb3a11eeea356744f39b802369bda3c diff --git a/web/core/modules/toolbar/js/toolbar.menu.es6.js b/web/core/modules/toolbar/js/toolbar.menu.es6.js index 03fd41f37..614574ef7 100644 --- a/web/core/modules/toolbar/js/toolbar.menu.es6.js +++ b/web/core/modules/toolbar/js/toolbar.menu.es6.js @@ -8,18 +8,45 @@ * $('.toolbar-menu').drupalToolbarMenu(); */ -(function ($, Drupal, drupalSettings) { +(function($, Drupal, drupalSettings) { /** * Store the open menu tray. */ let activeItem = Drupal.url(drupalSettings.path.currentPath); - $.fn.drupalToolbarMenu = function () { + $.fn.drupalToolbarMenu = function() { const ui = { handleOpen: Drupal.t('Extend'), handleClose: Drupal.t('Collapse'), }; + /** + * Toggle the open/close state of a list is a menu. + * + * @param {jQuery} $item + * The li item to be toggled. + * + * @param {Boolean} switcher + * A flag that forces toggleClass to add or a remove a class, rather than + * simply toggling its presence. + */ + function toggleList($item, switcher) { + const $toggle = $item + .children('.toolbar-box') + .children('.toolbar-handle'); + switcher = + typeof switcher !== 'undefined' ? switcher : !$item.hasClass('open'); + // Toggle the item open state. + $item.toggleClass('open', switcher); + // Twist the toggle. + $toggle.toggleClass('open', switcher); + // Adjust the toggle text. + $toggle + .find('.action') + // Expand Structure, Collapse Structure. + .text(switcher ? ui.handleClose : ui.handleOpen); + } + /** * Handle clicks from the disclosure button on an item with sub-items. * @@ -56,30 +83,6 @@ event.stopPropagation(); } - /** - * Toggle the open/close state of a list is a menu. - * - * @param {jQuery} $item - * The li item to be toggled. - * - * @param {Boolean} switcher - * A flag that forces toggleClass to add or a remove a class, rather than - * simply toggling its presence. - */ - function toggleList($item, switcher) { - const $toggle = $item.children('.toolbar-box').children('.toolbar-handle'); - switcher = (typeof switcher !== 'undefined') ? switcher : !$item.hasClass('open'); - // Toggle the item open state. - $item.toggleClass('open', switcher); - // Twist the toggle. - $toggle.toggleClass('open', switcher); - // Adjust the toggle text. - $toggle - .find('.action') - // Expand Structure, Collapse Structure. - .text((switcher) ? ui.handleClose : ui.handleOpen); - } - /** * Add markup to the menu elements. * @@ -104,8 +107,11 @@ const $item = $(element); if ($item.children('ul.toolbar-menu').length) { const $box = $item.children('.toolbar-box'); - options.text = Drupal.t('@label', { '@label': $box.find('a').text() }); - $item.children('.toolbar-box') + options.text = Drupal.t('@label', { + '@label': $box.find('a').text(), + }); + $item + .children('.toolbar-box') .append(Drupal.theme('toolbarMenuItemToggle', options)); } }); @@ -124,7 +130,7 @@ * The current level number to be assigned to the list elements. */ function markListLevels($lists, level) { - level = (!level) ? 1 : level; + level = !level ? 1 : level; const $lis = $lists.children('li').addClass(`level-${level}`); $lists = $lis.children('ul'); if ($lists.length) { @@ -142,19 +148,23 @@ * The root of the menu. */ function openActiveItem($menu) { - const pathItem = $menu.find(`a[href="${location.pathname}"]`); + const pathItem = $menu.find(`a[href="${window.location.pathname}"]`); if (pathItem.length && !activeItem) { - activeItem = location.pathname; + activeItem = window.location.pathname; } if (activeItem) { - const $activeItem = $menu.find(`a[href="${activeItem}"]`).addClass('menu-item--active'); - const $activeTrail = $activeItem.parentsUntil('.root', 'li').addClass('menu-item--active-trail'); + const $activeItem = $menu + .find(`a[href="${activeItem}"]`) + .addClass('menu-item--active'); + const $activeTrail = $activeItem + .parentsUntil('.root', 'li') + .addClass('menu-item--active-trail'); toggleList($activeTrail, true); } } // Return the jQuery object. - return this.each(function (selector) { + return this.each(function(selector) { const $menu = $(this).once('toolbar-menu'); if ($menu.length) { // Bind event handlers. @@ -186,7 +196,9 @@ * @return {string} * A string representing a DOM fragment. */ - Drupal.theme.toolbarMenuItemToggle = function (options) { - return ``; + Drupal.theme.toolbarMenuItemToggle = function(options) { + return ``; }; -}(jQuery, Drupal, drupalSettings)); +})(jQuery, Drupal, drupalSettings);