1 2const siteHeader = document.querySelector('.site-header'); 3 siteMobileNavToggle = document.querySelector('.site-header__toggle-nav'), 4 siteMainWrapper = document.querySelector('.site-header__nav-wrapper'); 5 6siteMobileNavToggle.addEventListener('click', function(e){ 7 siteHeader.classList.toggle('site-header--toggle'); 8 siteMobileNavToggle.classList.toggle('site-header__toggle-nav--open'); 9 siteMainWrapper.classList.toggle('site-header__nav-wrapper--toggle'); 10}); 11 12 13// Add element for mobile toggle 14var li_links = document.querySelectorAll('.site-header .menu-item-has-children > a'); 15 16li_links.forEach(function(el) { 17 el.innerHTML = el.innerHTML + '<a href="#" class="menu-item-link-arrow" aria-label="Toggle menu"></a>'; 18 el.setAttribute('aria-expanded','false'); 19}); 20 21// Mobile arrows toggle 22var arrows = document.querySelectorAll('.site-header .menu-item-has-children > a > .menu-item-link-arrow'); 23arrows.forEach(function(el) { 24 el.onclick = function(event) { 25 // Add toggle class to button 26 event.preventDefault(); 27 el.classList.toggle('menu-item-link-arrow--toggle'); 28 el.parentElement.classList.toggle('menu-item--toggle'); 29 var aria = el.parentElement.getAttribute('aria-expanded'); 30 if(aria == 'false'){ 31 el.parentElement.setAttribute('aria-expanded','true'); 32 } 33 if(aria == 'true'){ 34 el.parentElement.setAttribute('aria-expanded','false'); 35 } 36 } 37}); 38 39 40/** 41 * File navigation.js. 42 * 43 * Handles toggling the navigation menu for small screens and enables TAB key 44 * navigation support for dropdown menus. 45 */ 46( function() { 47 const siteNavigation = document.getElementById( 'site-navigation' ); 48 49 // Return early if the navigation doesn't exist. 50 if ( ! siteNavigation ) { 51 return; 52 } 53 54 const button = siteNavigation.getElementsByTagName( 'button' )[ 0 ]; 55 56 // Return early if the button doesn't exist. 57 if ( 'undefined' === typeof button ) { 58 return; 59 } 60 61 const menu = siteNavigation.getElementsByTagName( 'ul' )[ 0 ]; 62 63 // Hide menu toggle button if menu is empty and return early. 64 if ( 'undefined' === typeof menu ) { 65 button.style.display = 'none'; 66 return; 67 } 68 69 if ( ! menu.classList.contains( 'nav-menu' ) ) { 70 menu.classList.add( 'nav-menu' ); 71 } 72 73 // Toggle the .toggled class and the aria-expanded value each time the button is clicked. 74 button.addEventListener( 'click', function() { 75 siteNavigation.classList.toggle( 'toggled' ); 76 77 if ( button.getAttribute( 'aria-expanded' ) === 'true' ) { 78 button.setAttribute( 'aria-expanded', 'false' ); 79 } else { 80 button.setAttribute( 'aria-expanded', 'true' ); 81 } 82 } ); 83 84 // Remove the .toggled class and set aria-expanded to false when the user clicks outside the navigation. 85 document.addEventListener( 'click', function( event ) { 86 const isClickInside = siteNavigation.contains( event.target ); 87 88 if ( ! isClickInside ) { 89 siteNavigation.classList.remove( 'toggled' ); 90 button.setAttribute( 'aria-expanded', 'false' ); 91 } 92 } ); 93 94 // Get all the link elements within the menu. 95 const links = menu.getElementsByTagName( 'a' ); 96 97 // Get all the link elements with children within the menu. 98 const linksWithChildren = menu.querySelectorAll( '.menu-item-has-children > a, .page_item_has_children > a' ); 99 100 // Toggle focus each time a menu link is focused or blurred. 101 for ( const link of links ) { 102 link.addEventListener( 'focus', toggleFocus, true ); 103 link.addEventListener( 'blur', toggleFocus, true ); 104 } 105 106 // Toggle focus each time a menu link with children receive a touch event. 107 for ( const link of linksWithChildren ) { 108 link.addEventListener( 'touchstart', toggleFocus, false ); 109 } 110 111 /** 112 * Sets or removes .focus class on an element. 113 */ 114 function toggleFocus() { 115 if ( event.type === 'focus' || event.type === 'blur' ) { 116 let self = this; 117 // Move up through the ancestors of the current link until we hit .nav-menu. 118 while ( ! self.classList.contains( 'nav-menu' ) ) { 119 // On li elements toggle the class .focus. 120 if ( 'li' === self.tagName.toLowerCase() ) { 121 self.classList.toggle( 'focus' ); 122 } 123 self = self.parentNode; 124 } 125 } 126 127 if ( event.type === 'touchstart' ) { 128 const menuItem = this.parentNode; 129 event.preventDefault(); 130 for ( const link of menuItem.parentNode.children ) { 131 if ( menuItem !== link ) { 132 link.classList.remove( 'focus' ); 133 } 134 } 135 menuItem.classList.toggle( 'focus' ); 136 } 137 } 138}() );
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.