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 8jQuery(document).ready(function ($) { 9 10 (function () { 11 var container, button, menu, links, i, len, animtarget; 12 container = document.getElementById('site-navigation'); 13 if (!container) { 14 console.log('no container'); 15 return; 16 } 17 18 button = container.getElementsByTagName('button')[0]; 19 if ('undefined' === typeof button) { 20 return; 21 } 22 23 menu = container.getElementsByTagName('ul')[0]; 24 25 // Hide menu toggle button if menu is empty and return early. 26 if ('undefined' === typeof menu) { 27 button.style.display = 'none'; 28 return; 29 } 30 31 menu.setAttribute('aria-expanded', 'false'); 32 if (-1 === menu.className.indexOf('nav-menu')) { 33 menu.className += ' nav-menu'; 34 } 35 button.onclick = function () { 36 if (-1 !== container.className.indexOf('toggled')) { 37 container.className = container.className.replace(' toggled', ''); 38 button.setAttribute('aria-expanded', 'false'); 39 menu.setAttribute('aria-expanded', 'false'); 40 } else { 41 container.className += ' toggled'; 42 button.setAttribute('aria-expanded', 'true'); 43 menu.setAttribute('aria-expanded', 'true'); 44 } 45 }; 46 47 // Get all the link elements within the menu. 48 links = menu.getElementsByTagName('a'); 49 50 // Each time a menu link is focused or blurred, toggle focus. 51 for (i = 0, len = links.length; i < len; i++) { 52 links[i].addEventListener('focus', toggleFocus, true); 53 links[i].addEventListener('blur', toggleFocus, true); 54 } 55 56 /** 57 * Sets or removes .focus class on an element. 58 */ 59 function toggleFocus() { 60 var self = this; 61 62 // Move up through the ancestors of the current link until we hit .nav-menu. 63 while (-1 === self.className.indexOf('nav-menu')) { 64 65 // On li elements toggle the class .focus. 66 if ('li' === self.tagName.toLowerCase()) { 67 if (-1 !== self.className.indexOf('focus')) { 68 self.className = self.className.replace(' focus', ''); 69 } else { 70 self.className += ' focus'; 71 } 72 } 73 74 self = self.parentElement; 75 } 76 } 77 78 /** 79 * Toggles `focus` class to allow submenu access on tablets. 80 */ 81 (function (container) { 82 var touchStartFn, i, 83 parentLink = container.querySelectorAll('.menu-item-has-children > a, .page_item_has_children > a'); 84 85 if ('ontouchstart' in window) { 86 touchStartFn = function (e) { 87 var menuItem = this.parentNode, i; 88 89 if (!menuItem.classList.contains('focus')) { 90 e.preventDefault(); 91 for (i = 0; i < menuItem.parentNode.children.length; ++i) { 92 if (menuItem === menuItem.parentNode.children[i]) { 93 continue; 94 } 95 menuItem.parentNode.children[i].classList.remove('focus'); 96 } 97 menuItem.classList.add('focus'); 98 } else { 99 menuItem.classList.remove('focus'); 100 } 101 }; 102 103 for (i = 0; i < parentLink.length; ++i) { 104 parentLink[i].addEventListener('touchstart', touchStartFn, false); 105 } 106 } 107 }(container)); 108 })(); 109 110 // get ancestor for side navigation 111 var menu_item = $('.second-menu .current_page_item, .second-menu .current_page_ancestor').clone(); 112 113 var subMenuItems = $('#sidemenu ul.children .page_item'); 114 115 if (subMenuItems.length > 0) { 116 menu_item.appendTo('.sub-menu-header'); 117 } else { 118 return 119 } 120 121});
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.