1(function($) { 2 'use strict'; 3 4 /** 5 * navigation.js 6 * 7 * Handles toggling the navigation menu for small screens and enables tab 8 * support for dropdown menus. 9 */ 10 (function() { 11 var container, button, menu, links, subMenus; 12 13 container = document.getElementById('site-navigation'); 14 if (!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 36 button.onclick = function() { 37 if (-1 !== container.className.indexOf('toggled')) { 38 container.className = container.className.replace(' toggled', ''); 39 button.setAttribute('aria-expanded', 'false'); 40 menu.setAttribute('aria-expanded', 'false'); 41 } else { 42 container.className += ' toggled'; 43 button.setAttribute('aria-expanded', 'true'); 44 menu.setAttribute('aria-expanded', 'true'); 45 } 46 }; 47 48 // Get all the link elements within the menu. 49 links = menu.getElementsByTagName('a'); 50 subMenus = menu.getElementsByTagName('ul'); 51 52 // Set menu items with submenus to aria-haspopup="true". 53 for (var i = 0, len = subMenus.length; i < len; i++) { 54 subMenus[i].parentNode.setAttribute('aria-haspopup', 'true'); 55 } 56 57 // Each time a menu link is focused or blurred, toggle focus. 58 for (i = 0, len = links.length; i < len; i++) { 59 links[i].addEventListener('focus', toggleFocus, true); 60 links[i].addEventListener('blur', toggleFocus, true); 61 } 62 63 /** 64 * Sets or removes .focus class on an element. 65 */ 66 function toggleFocus() { 67 var self = this; 68 69 // Move up through the ancestors of the current link until we hit .nav-menu. 70 while (-1 === self.className.indexOf('nav-menu')) { 71 // On li elements toggle the class .focus. 72 if ('li' === self.tagName.toLowerCase()) { 73 if (-1 !== self.className.indexOf('focus')) { 74 self.className = self.className.replace(' focus', ''); 75 } else { 76 self.className += ' focus'; 77 } 78 } 79 80 self = self.parentElement; 81 } 82 } 83 })(); 84})(jQuery);
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.