1/* 2An accessible menu for WordPress 3https://github.com/argenteum/accessible-nav-wp 4Licensed GPL v.2 (http://www.gnu.org/licenses/gpl-2.0.html) 5This work derived from: 6https://github.com/WordPress/twentysixteen (GPL v.2) 7https://github.com/wpaccessibility/a11ythemepatterns/tree/master/menu-keyboard-arrow-nav (GPL v.2) 8*/ 9 10(function($) { 11 12 var menuContainer = $('.menu-container'); 13 var menuToggle = menuContainer.find( '.menu-button' ); 14 var siteHeaderMenu = menuContainer.find( '#site-header-menu' ); 15 var siteNavigation = menuContainer.find( '#site-navigation' ); 16 var body = $('body'); 17 18 // If you are using WordPress, and do not need to localise your script, or if you are not using WordPress, then uncomment the next line 19 var screenReaderText = {"expand":"Expand child menu","collapse":"Collapse child menu"}; 20 21 var dropdownToggle = $('<button />', {'class': 'dropdown-toggle','aria-expanded': false}) 22 .append($('<span />', {'class': 'screen-readers',text: screenReaderText.expand})); 23 24 25 // Toggles the menu button 26 (function() { 27 28 if (!menuToggle.length) { 29 return; 30 } 31 32 menuToggle.add(siteNavigation).attr('aria-expanded', 'false'); 33 34 menuToggle.on('click', function() { 35 $(this).add(siteHeaderMenu).toggleClass('toggled-on'); 36 $(this).add(body).toggleClass('disable-scroll'); 37 38 // jscs:disable 39 $(this).add( siteNavigation ) 40 .attr('aria-expanded', $( this )
41 .add( siteNavigation ).attr( 'aria-expanded' ) === 'false' ? 'true' : 'false' ); 42 // jscs:enable 43 44 } ); 45 } )(); 46 47 // Adds the dropdown toggle button 48 $('.menu-item-has-children > a').after(dropdownToggle); 49 50 // Adds aria attribute 51 siteHeaderMenu.find( '.menu-item-has-children' ).attr( 'aria-haspopup', 'true' ); 52 53 // Toggles the sub-menu when dropdown toggle button clicked 54 siteHeaderMenu.find( '.dropdown-toggle' ).click( function(e) { 55 56 screenReaderSpan = $(this).find( '.screen-readers' ); 57 58 e.preventDefault(); 59 $(this).toggleClass( 'toggled-on' ); 60 $(this).nextAll( '.sub-menu' ).toggleClass( 'toggled-on' ); 61 62 // jscs:disable 63 $(this).attr( 'aria-expanded', $(this).attr( 'aria-expanded' ) === 'false' 64 ? 'true' : 'false' ); 65 // jscs:enable 66 screenReaderSpan.text( screenReaderSpan.text() === 67 screenReaderText.expand ? screenReaderText.collapse : 68 screenReaderText.expand ); 69 }); 70 71 // Adds a class to sub-menus for styling 72 $('.sub-menu .menu-item-has-children').parent('.sub-menu').addClass('has-sub-menu'); 73 74 75 // Keyboard navigation 76 $('.menu-item a, button.dropdown-toggle').on('keydown', function(e) { 77 78 if ([37,38,39,40].indexOf(e.keyCode) == -1) { 79 return; 80 } 81 82 switch(e.keyCode) { 83 84 case 37: // left key 85 e.preventDefault(); 86 e.stopPropagation(); 87 88 if ($(this).hasClass('dropdown-toggle')){ 89 $(this).prev('a').focus(); 90 } 91 else { 92 93 if ($(this).parent().prev().children('button.dropdown-toggle').length) { 94 $(this).parent().prev().children('button.dropdown-toggle').focus(); 95 } 96 else { 97 $(this).parent().prev().children('a').focus(); 98 } 99 } 100 101 if ($(this).is('ul ul ul.sub-menu.toggled-on li:first-child a')) { 102 $(this).parents('ul.sub-menu.toggled-on li').children('button.dropdown-toggle').focus(); 103 } 104 105 break; 106 107 case 39: // right key 108 e.preventDefault(); 109 e.stopPropagation(); 110 111 if($(this).next('button.dropdown-toggle').length) { 112 $(this).next('button.dropdown-toggle').focus(); 113 } 114 else { 115 $(this).parent().next().children('a').focus(); 116 } 117 118 if ($(this).is('ul.sub-menu .dropdown-toggle.toggled-on')){ 119 $(this).parent().find('ul.sub-menu li:first-child a').focus(); 120 } 121 122 break; 123 124 125 case 40: // down key 126 e.preventDefault(); 127 e.stopPropagation(); 128 129 if($(this).next().length){ 130 $(this).next().find('li:first-child a').first().focus(); 131 } 132 else { 133 $(this).parent().next().children('a').focus(); 134 } 135 136 if (($(this).is('ul.sub-menu a')) && ($(this).next('button.dropdown-toggle').length)) { 137 $(this).parent().next().children('a').focus(); 138 } 139 140 if (($(this).is('ul.sub-menu .dropdown-toggle')) && ($(this).parent().next().children('.dropdown-toggle').length)) { 141 $(this).parent().next().children('.dropdown-toggle').focus(); 142 } 143 144 break; 145 146 147 case 38: // up key 148 e.preventDefault(); 149 e.stopPropagation(); 150 151 if($(this).parent().prev().length){ 152 $(this).parent().prev().children('a').focus(); 153 } 154 else { 155 $(this).parents('ul').first().prev('.dropdown-toggle.toggled-on').focus(); 156 } 157 158 if (($(this).is('ul.sub-menu .dropdown-toggle')) && ($(this).parent().prev().children('.dropdown-toggle').length)) { 159 $(this).parent().prev().children('.dropdown-toggle').focus(); 160 } 161 162 break; 163 164 } 165 }); 166})(jQuery); 167 168 169 // https://raw.githubusercontent.com/davidjbradshaw/iframe-resizer/master/js/iframeResizer.min.js 170function loadReziser(id) { 171 iFrameResize( 172 { 173 checkOrigin: false, 174 heightCalculationMethod: "taggedElement", 175 }, 176 id 177 ); 178 }
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.