1/** 2 * File navigation.js. 3 * 4 * Handles toggling the navigation menu for small screens and enables TAB key 5 * navigation support for dropdown menus. 6 */ 7(function () { 8 var container, button, menu, links, subMenus, i, len; 9 10 container = document.getElementById('site-navigation'); 11 if ( !container ) { 12 return; 13 } 14 15 button = container.getElementsByTagName('button')[ 0 ]; 16 if ( 'undefined' === typeof button ) { 17 return; 18 } 19 20 menu = container.getElementsByTagName('ul')[ 0 ]; 21 22 // Hide menu toggle button if menu is empty and return early. 23 if ( 'undefined' === typeof menu ) { 24 button.style.display = 'none'; 25 return; 26 } 27 28 menu.setAttribute('aria-expanded', 'false'); 29 if ( -1 === menu.className.indexOf('nav-menu') ) { 30 menu.className += ' nav-menu'; 31 } 32 33 button.onclick = function () { 34 if ( -1 !== container.className.indexOf('toggled') ) { 35 container.className = container.className.replace(' toggled', ''); 36 button.setAttribute('aria-expanded', 'false'); 37 menu.setAttribute('aria-expanded', 'false'); 38 } else { 39 container.className += ' toggled'; 40 button.setAttribute('aria-expanded', 'true'); 41 menu.setAttribute('aria-expanded', 'true'); 42 } 43 }; 44 45 window.addEventListener('resize', function () { 46 var width = window.innerWidth; 47 if ( width > 600 && -1 !== container.className.indexOf('toggled') ) { 48 container.className = container.className.replace(' toggled', ''); 49 button.setAttribute('aria-expanded', 'false'); 50 menu.setAttribute('aria-expanded', 'false'); 51 } 52 }, true); 53 54 // Get all the link elements within the menu. 55 links = menu.getElementsByTagName('a'); 56 subMenus = menu.getElementsByTagName('ul'); 57 58 // Set menu items with submenus to aria-haspopup="true". 59 for ( i = 0, len = subMenus.length; i < len; i++ ) { 60 subMenus[ i ].parentNode.setAttribute('aria-haspopup', 'true'); 61 } 62 63 // Each time a menu link is focused or blurred, toggle focus. 64 for ( i = 0, len = links.length; i < len; i++ ) { 65 links[ i ].addEventListener('focus', toggleFocus, true); 66 links[ i ].addEventListener('blur', toggleFocus, true); 67 } 68 69 /** 70 * Sets or removes .focus class on an element. 71 */ 72 function toggleFocus() { 73 var self = this; 74 75 // Move up through the ancestors of the current link until we hit .nav-menu. 76 while ( -1 === self.className.indexOf('nav-menu') ) { 77 78 // On li elements toggle the class .focus. 79 if ( 'li' === self.tagName.toLowerCase() ) { 80 if ( -1 !== self.className.indexOf('focus') ) { 81 self.className = self.className.replace(' focus', ''); 82 } else { 83 self.className += ' focus'; 84 } 85 } 86 87 self = self.parentElement; 88 } 89 } 90})();
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.