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