comparison core/modules/toolbar/js/toolbar.menu.js @ 4:a9cd425dd02b

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:11:55 +0000
parents c75dbcec494b
children
comparison
equal deleted inserted replaced
3:307d7a7fd348 4:a9cd425dd02b
11 $.fn.drupalToolbarMenu = function () { 11 $.fn.drupalToolbarMenu = function () {
12 var ui = { 12 var ui = {
13 handleOpen: Drupal.t('Extend'), 13 handleOpen: Drupal.t('Extend'),
14 handleClose: Drupal.t('Collapse') 14 handleClose: Drupal.t('Collapse')
15 }; 15 };
16
17 function toggleList($item, switcher) {
18 var $toggle = $item.children('.toolbar-box').children('.toolbar-handle');
19 switcher = typeof switcher !== 'undefined' ? switcher : !$item.hasClass('open');
20
21 $item.toggleClass('open', switcher);
22
23 $toggle.toggleClass('open', switcher);
24
25 $toggle.find('.action').text(switcher ? ui.handleClose : ui.handleOpen);
26 }
16 27
17 function toggleClickHandler(event) { 28 function toggleClickHandler(event) {
18 var $toggle = $(event.target); 29 var $toggle = $(event.target);
19 var $item = $toggle.closest('li'); 30 var $item = $toggle.closest('li');
20 31
30 } 41 }
31 42
32 event.stopPropagation(); 43 event.stopPropagation();
33 } 44 }
34 45
35 function toggleList($item, switcher) {
36 var $toggle = $item.children('.toolbar-box').children('.toolbar-handle');
37 switcher = typeof switcher !== 'undefined' ? switcher : !$item.hasClass('open');
38
39 $item.toggleClass('open', switcher);
40
41 $toggle.toggleClass('open', switcher);
42
43 $toggle.find('.action').text(switcher ? ui.handleClose : ui.handleOpen);
44 }
45
46 function initItems($menu) { 46 function initItems($menu) {
47 var options = { 47 var options = {
48 class: 'toolbar-icon toolbar-handle', 48 class: 'toolbar-icon toolbar-handle',
49 action: ui.handleOpen, 49 action: ui.handleOpen,
50 text: '' 50 text: ''
54 54
55 $menu.find('li').each(function (index, element) { 55 $menu.find('li').each(function (index, element) {
56 var $item = $(element); 56 var $item = $(element);
57 if ($item.children('ul.toolbar-menu').length) { 57 if ($item.children('ul.toolbar-menu').length) {
58 var $box = $item.children('.toolbar-box'); 58 var $box = $item.children('.toolbar-box');
59 options.text = Drupal.t('@label', { '@label': $box.find('a').text() }); 59 options.text = Drupal.t('@label', {
60 '@label': $box.find('a').text()
61 });
60 $item.children('.toolbar-box').append(Drupal.theme('toolbarMenuItemToggle', options)); 62 $item.children('.toolbar-box').append(Drupal.theme('toolbarMenuItemToggle', options));
61 } 63 }
62 }); 64 });
63 } 65 }
64 66
70 markListLevels($lists, level + 1); 72 markListLevels($lists, level + 1);
71 } 73 }
72 } 74 }
73 75
74 function openActiveItem($menu) { 76 function openActiveItem($menu) {
75 var pathItem = $menu.find('a[href="' + location.pathname + '"]'); 77 var pathItem = $menu.find('a[href="' + window.location.pathname + '"]');
76 if (pathItem.length && !activeItem) { 78 if (pathItem.length && !activeItem) {
77 activeItem = location.pathname; 79 activeItem = window.location.pathname;
78 } 80 }
79 if (activeItem) { 81 if (activeItem) {
80 var $activeItem = $menu.find('a[href="' + activeItem + '"]').addClass('menu-item--active'); 82 var $activeItem = $menu.find('a[href="' + activeItem + '"]').addClass('menu-item--active');
81 var $activeTrail = $activeItem.parentsUntil('.root', 'li').addClass('menu-item--active-trail'); 83 var $activeTrail = $activeItem.parentsUntil('.root', 'li').addClass('menu-item--active-trail');
82 toggleList($activeTrail, true); 84 toggleList($activeTrail, true);
96 } 98 }
97 }); 99 });
98 }; 100 };
99 101
100 Drupal.theme.toolbarMenuItemToggle = function (options) { 102 Drupal.theme.toolbarMenuItemToggle = function (options) {
101 return '<button class="' + options.class + '"><span class="action">' + options.action + '</span><span class="label">' + options.text + '</span></button>'; 103 return '<button class="' + options.class + '"><span class="action">' + options.action + '</span> <span class="label">' + options.text + '</span></button>';
102 }; 104 };
103 })(jQuery, Drupal, drupalSettings); 105 })(jQuery, Drupal, drupalSettings);