1(function () { 2 3 'use strict'; 4 5 /** 6 * Provides the off-canvas menu. 7 * 8 * @type {Drupal~behavior} 9 * 10 * @prop {Drupal~behaviorAttach} attach 11 * Attaches the behavior for the bootstrap modifications. 12 */ 13 Drupal.behaviors.responsive_menu_bootstrap = { 14 attach: function (context) { 15 // Hijack the Bootstrap toggler so it expands the mmenu rather than the 16 // bootstrap dropdown menu. 17 let parent = document.querySelector('#navbar-main'); 18 let offCanvas = document.querySelector('#off-canvas'); 19 20 if (parent && offCanvas.hasOwnProperty('mmApi') && typeof (Mmenu) !== 'undefined' && !parent.classList.contains('mmenu-bootstrap')) { 21 // Add a class to the parent so that this code is only triggered once. 22 parent.classList.add('mmenu-bootstrap') 23 24 // Remove bootstrap classes from the off-canvas menu. 25 _removeClasses(offCanvas.getElementsByTagName('a')); 26 _removeClasses(offCanvas.getElementsByTagName('li')); 27 _removeClasses(offCanvas.getElementsByTagName('ul')); 28 29 let toggler = parent.querySelector('.navbar-toggler'); 30 31 if (toggler) { 32 toggler.removeAttribute('data-target'); 33 // delete toggler.dataset.target; // IE10 has no dataset :( 34 toggler.removeAttribute('aria-controls'); 35 36 // Remove all bound events. 37 toggler.outerHTML = toggler.outerHTML; 38 toggler = parent.querySelector('.navbar-toggler'); 39 40 // Get the mmenu API. 41 const mmenuApi = offCanvas.mmApi; 42 43 // Open the menu on-click. 44 toggler.addEventListener('click', function(e) { 45 e.preventDefault(); 46 e.stopImmediatePropagation(); 47 // Check if the menu needs to open or close. 48 let opened = offCanvas.classList.contains('mm-menu_opened'); 49 // Trigger the open or close method. 50 mmenuApi[opened ? 'close' : 'open'](); 51 }); 52 } 53 54 // Removes bootstrap classes. 55 function _removeClasses(els) { 56 [].forEach.call(els, function(el) { 57 el.classList.remove('nav', 'nav-link', 'nav-item') 58 }) 59 } 60 } 61 62 } 63 64 } 65 66})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.