1/** 2 * navigation.js 3 * 4 * Handles toggling the navigation menu for small screens. 5 */ 6( function() { 7 var container, button, menu; 8 9 container = document.getElementById( 'site-navigation' ); 10 if ( ! container ) { 11 return; 12 } 13 14 button = container.getElementsByTagName( 'button' )[0]; 15 if ( 'undefined' === typeof button ) { 16 return; 17 } 18 19 menu = container.getElementsByTagName( 'ul' )[0]; 20 21 // Hide menu toggle button if menu is empty and return early. 22 if ( 'undefined' === typeof menu ) { 23 button.style.display = 'none'; 24 return; 25 } 26 27 menu.setAttribute( 'aria-expanded', 'false' ); 28 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 // Fix child menus for touch devices. 46 function fixMenuTouchTaps( container ) { 47 var touchStartFn, 48 parentLink = container.querySelectorAll( '.menu-item-has-children > a, .page_item_has_children > a' ); 49 50 if ( 'ontouchstart' in window ) { 51 touchStartFn = function( e ) { 52 var menuItem = this.parentNode; 53 54 if ( ! menuItem.classList.contains( 'focus' ) ) { 55 e.preventDefault(); 56 for( var i = 0; i < menuItem.parentNode.children.length; ++i ) { 57 if ( menuItem === menuItem.parentNode.children[i] ) { 58 continue; 59 } 60 menuItem.parentNode.children[i].classList.remove( 'focus' ); 61 } 62 menuItem.classList.add( 'focus' ); 63 } else { 64 menuItem.classList.remove( 'focus' ); 65 } 66 }; 67 68 for ( var i = 0; i < parentLink.length; ++i ) { 69 parentLink[i].addEventListener( 'touchstart', touchStartFn, false ) 70 } 71 } 72 } 73 74 fixMenuTouchTaps( container ); 75} )();
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.