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, 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 23 menu.setAttribute( 'aria-expanded', 'false' ); 24 if ( -1 === menu.className.indexOf( 'nav-menu' ) ) { 25 menu.className += ' nav-menu'; 26 } 27 28 button.onclick = function() { 29 if ( -1 !== container.className.indexOf( 'toggled' ) ) { 30 container.className = container.className.replace( ' toggled', '' ); 31 button.setAttribute( 'aria-expanded', 'false' ); 32 menu.setAttribute( 'aria-expanded', 'false' ); 33 } else { 34 container.className += ' toggled'; 35 button.setAttribute( 'aria-expanded', 'true' ); 36 menu.setAttribute( 'aria-expanded', 'true' ); 37 } 38 }; 39 40 // Get all the link elements within the menu. 41 links = menu.getElementsByTagName( 'a' ); 42 43 // Each time a menu link is focused or blurred, toggle focus. 44 for ( i = 0, len = links.length; i < len; i++ ) { 45 links[i].addEventListener( 'focus', toggleFocus, true ); 46 links[i].addEventListener( 'blur', toggleFocus, true ); 47 } 48 49 /** 50 * Sets or removes .focus class on an element. 51 */ 52 function toggleFocus() { 53 var self = this; 54 55 // Move up through the ancestors of the current link until we hit .nav-menu. 56 while ( -1 === self.className.indexOf( 'nav-menu' ) ) { 57 58 // On li elements toggle the class .focus. 59 if ( 'li' === self.tagName.toLowerCase() ) { 60 if ( -1 !== self.className.indexOf( 'focus' ) ) { 61 self.className = self.className.replace( ' focus', '' ); 62 } else { 63 self.className += ' focus'; 64 } 65 } 66 67 self = self.parentElement; 68 } 69 } 70 71 /** 72 * Toggles `focus` class to allow submenu access on tablets. 73 */ 74 ( function( container ) { 75 var touchStartFn, i, 76 parentLink = container.querySelectorAll( '.menu-item-has-children > a, .page_item_has_children > a' ); 77 78 if ( 'ontouchstart' in window ) { 79 touchStartFn = function( e ) { 80 var menuItem = this.parentNode, i; 81 82 if ( ! menuItem.classList.contains( 'focus' ) ) { 83 e.preventDefault(); 84 for ( i = 0; i < menuItem.parentNode.children.length; ++i ) { 85 if ( menuItem === menuItem.parentNode.children[i] ) { 86 continue; 87 } 88 menuItem.parentNode.children[i].classList.remove( 'focus' ); 89 } 90 menuItem.classList.add( 'focus' ); 91 } else { 92 menuItem.classList.remove( 'focus' ); 93 } 94 }; 95 96 for ( i = 0; i < parentLink.length; ++i ) { 97 parentLink[i].addEventListener( 'touchstart', touchStartFn, false ); 98 } 99 } 100 }( container ) ); 101} )();
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.