1/** 2 * navigation.js 3 * 4 * Handles toggling the navigation menu for small screens. 5 */ 6( function() { 7 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( 'h3' )[ 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 if ( -1 === menu.className.indexOf( 'nav-menu' ) ) { 29 menu.className += 'nav-menu'; 30 } 31 32 button.onclick = function() { 33 if ( -1 !== container.className.indexOf( 'main-small-navigation' ) ) { 34 container.className = container.className.replace( 'main-small-navigation', 'main-navigation' ); 35 } else { 36 container.className = container.className.replace( 'main-navigation', 'main-small-navigation' ); 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 // On li elements toggle the class .focus. 58 if ( 'li' === self.tagName.toLowerCase() ) { 59 if ( - 1 !== self.className.indexOf( 'focus' ) ) { 60 self.className = self.className.replace( ' focus', '' ); 61 } else { 62 self.className += ' focus'; 63 } 64 } 65 66 self = self.parentElement; 67 } 68 } 69 70} )(); 71jQuery( document ).ready( function() { 72 73 jQuery( '#site-navigation .menu-item-has-children' ).append( '<span class="sub-toggle"> <i class="fa fa-caret-down"></i> </span>' ); 74 75 jQuery( '#site-navigation .sub-toggle' ).click( function() { 76 77 jQuery( this ).parent( '.menu-item-has-children' ).children( 'ul.sub-menu' ).first().slideToggle( '1000' ); 78 jQuery( this ).children( '.fa-caret-right' ).first().toggleClass( 'fa-caret-down' ); 79 jQuery( this ).toggleClass( 'active' ); 80 81 } ); 82 83} ); 84 85// Show Submenu on click on touch enabled deviced 86( function() { 87 88 var container = document.getElementById( 'site-navigation' ); 89 90 /** 91 * Toggles `focus` class to allow submenu access on tablets. 92 */ 93 ( function( container ) { 94 95 var touchStartFn, i, 96 parentLink = container.querySelectorAll( '.menu-item-has-children > a, .page_item_has_children > a' ); 97 98 if ( 'ontouchstart' in window ) { 99 touchStartFn = function( e ) { 100 var menuItem = this.parentNode, i; 101 102 if ( !menuItem.classList.contains( 'focus' ) ) { 103 e.preventDefault(); 104 for ( i = 0; i < menuItem.parentNode.children.length; ++i ) { 105 if ( menuItem === menuItem.parentNode.children[ i ] ) { 106 continue; 107 } 108 menuItem.parentNode.children[ i ].classList.remove( 'focus' ); 109 } 110 menuItem.classList.add( 'focus' ); 111 } else { 112 menuItem.classList.remove( 'focus' ); 113 } 114 }; 115 116 for ( i = 0; i < parentLink.length; ++i ) { 117 parentLink[ i ].addEventListener( 'touchstart', touchStartFn, false ); 118 } 119 } 120 121 }( container ) ); 122 123} )();
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.