1/** 2 * navigation.js 3 * 4 * Handles toggling the navigation menu for small screens. 5 */ 6( function() { 7 8 container = document.getElementById( 'site-navigation' ); 9 10 // Fix child menus for touch devices. 11 function fixMenuTouchTaps( container ) { 12 var touchStartFn, 13 parentLink = container.querySelectorAll( '.menu-item-has-children > a, .page_item_has_children > a' ); 14 15 if ( 'ontouchstart' in window ) { 16 touchStartFn = function( e ) { 17 var menuItem = this.parentNode; 18 19 if ( ! menuItem.classList.contains( 'focus' ) ) { 20 e.preventDefault(); 21 for( var i = 0; i < menuItem.parentNode.children.length; ++i ) { 22 if ( menuItem === menuItem.parentNode.children[i] ) { 23 continue; 24 } 25 menuItem.parentNode.children[i].classList.remove( 'focus' ); 26 } 27 menuItem.classList.add( 'focus' ); 28 } else { 29 menuItem.classList.remove( 'focus' ); 30 } 31 }; 32 33 for ( var i = 0; i < parentLink.length; ++i ) { 34 parentLink[i].addEventListener( 'touchstart', touchStartFn, false ) 35 } 36 } 37 } 38 39 fixMenuTouchTaps( container ); 40 41} )();