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( 'side-navigation' ); 11 if ( ! container ) { 12 return; 13 } 14 15 button = jQuery("button.menu-toggle"); 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.click(function() { 34 if ( -1 !== container.className.indexOf( 'toggled' ) ) { 35 jQuery("body").removeClass("leftNavOpen"); 36 jQuery(".menuPageOverlay").removeClass("visible"); 37 jQuery("body").removeClass("overlayOn"); 38 container.className = container.className.replace( ' toggled', '' ); 39 button.attr( 'aria-expanded', 'false' ); 40 menu.setAttribute( 'aria-expanded', 'false' ); 41 } else { 42 jQuery("body").addClass("leftNavOpen"); 43 jQuery(".menuPageOverlay").addClass("visible"); 44 jQuery("body").addClass("overlayOn"); 45 container.className += ' toggled'; 46 button.attr( 'aria-expanded', 'true' ); 47 menu.setAttribute( 'aria-expanded', 'true' ); 48 } 49 }); 50 51 // MOBILE FOOTER NAV 52 jQuery(".footer-navigation > ul > li > a").on("click",function(e){ 53 if(jQuery(window).width() < 700) { 54 e.preventDefault(); 55 if(!jQuery(this).hasClass("focus")){ 56 jQuery(".footer-navigation > ul > li > a").removeClass("focus"); 57 jQuery(this).addClass("focus"); 58 } 59 } 60 }); 61 // END MOBILE FOOTER NAV 62 63 64 // kenric:future code to handle closing menus by clicking outside them 65 // jQuery("html").click(function() { 66 // if(jQuery("body").is('.leftNavOpen, .myColorsOpen')) { 67 // jQuery(".menuPageOverlay").removeClass("visible"); 68 // jQuery("body").removeClass("leftNavOpen"); 69 // jQuery("body").removeClass("myColorsOpen"); 70 // jQuery(".side-navigation").removeClass("toggled"); 71 // button.attr( 'aria-expanded', 'false' ); 72 // } 73 // }); 74 75 // kenric:close side menus by clicking on page overlay 76 jQuery(".menuPageOverlay").click(function() { 77 jQuery(".menuPageOverlay").removeClass("visible"); 78 jQuery("body").removeClass("overlayOn"); 79 jQuery("body").removeClass("leftNavOpen"); 80 jQuery(".side-navigation").removeClass("toggled"); 81 button.attr( 'aria-expanded', 'false' ); 82 jQuery(".tpsDropDown").removeClass("open"); 83 }); 84 85 // Get all the link elements within the menu. 86 links = menu.getElementsByTagName( 'a' ); 87 subMenus = menu.getElementsByTagName( 'ul' ); 88 89 // Set menu items with submenus to aria-haspopup="true". 90 for ( i = 0, len = subMenus.length; i < len; i++ ) { 91 subMenus[i].parentNode.setAttribute( 'aria-haspopup', 'true' ); 92 } 93 94 // Each time a menu link is focused or blurred, toggle focus. 95 for ( i = 0, len = links.length; i < len; i++ ) { 96 links[i].addEventListener( 'focus', toggleFocus, true ); 97 links[i].addEventListener( 'blur', toggleFocus, true ); 98 } 99 100 /** 101 * Sets or removes .focus class on an element. 102 */ 103 function toggleFocus() { 104 var self = this; 105 106 // Move up through the ancestors of the current link until we hit .nav-menu. 107 while ( -1 === self.className.indexOf( 'nav-menu' ) ) { 108 109 // On li elements toggle the class .focus. 110 if ( 'li' === self.tagName.toLowerCase() ) { 111 if ( -1 !== self.className.indexOf( 'focus' ) ) { 112 self.className = self.className.replace( ' focus', '' ); 113 } else { 114 self.className += ' focus'; 115 } 116 } 117 118 self = self.parentElement; 119 } 120 } 121 122 /** 123 * Toggles `focus` class to allow submenu access on tablets. 124 */ 125 ( function( container ) { 126 var touchStartFn, i, 127 parentLink = container.querySelectorAll( '.menu-item-has-children > a, .page_item_has_children > a' ); 128 129 if ( 'ontouchstart' in window ) { 130 touchStartFn = function( e ) { 131 var menuItem = this.parentNode, i; 132 133 if ( ! menuItem.classList.contains( 'focus' ) ) { 134 e.preventDefault(); 135 for ( i = 0; i < menuItem.parentNode.children.length; ++i ) { 136 if ( menuItem === menuItem.parentNode.children[i] ) { 137 continue; 138 } 139 menuItem.parentNode.children[i].classList.remove( 'focus' ); 140 } 141 menuItem.classList.add( 'focus' ); 142 } else { 143 menuItem.classList.remove( 'focus' ); 144 } 145 }; 146 147 for ( i = 0; i < parentLink.length; ++i ) { 148 parentLink[i].addEventListener( 'touchstart', touchStartFn, false ); 149 } 150 } 151 }( container ) ); 152} )();
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.