1/** 2 * File main.js 3 * 4 */ 5 6 7/** 8 * Mobile Navigation 9 */ 10( function( $ ) { 11 12 var body, masthead, menuToggle, siteNavigation; 13 14 function initMainNavigation( container ) { 15 16 // Add dropdown toggle that displays child menu items. 17 var dropdownToggle = $( '<button />', { 18 'class': 'dropdown-toggle', 19 'aria-expanded': false 20 } ); 21 22 container.find( '.menu-item-has-children > a' ).after( dropdownToggle ); 23 24 // Toggle buttons and submenu items with active children menu items. 25 container.find( '.current-menu-ancestor > button' ).addClass( 'toggled-on' ); 26 container.find( '.current-menu-ancestor > .sub-menu' ).addClass( 'toggled-on' ); 27 28 // Add menu items with submenus to aria-haspopup="true". 29 container.find( '.menu-item-has-children' ).attr( 'aria-haspopup', 'true' ); 30 31 container.find( '.dropdown-toggle' ).click( function( e ) { 32 var _this = $( this ), 33 screenReaderSpan = _this.find( '.screen-reader-text' ); 34 35 e.preventDefault(); 36 _this.toggleClass( 'toggled-on' ); 37 _this.next( '.children, .sub-menu' ).toggleClass( 'toggled-on' ); 38 39 // jscs:disable 40 _this.attr( 'aria-expanded', _this.attr( 'aria-expanded' ) === 'false' ? 'true' : 'false' ); 41 // jscs:enable 42 43 } ); 44 } 45 initMainNavigation( $( '.main-navigation' ) ); 46 47 masthead = $( '#masthead' ); 48 menuToggle = masthead.find( '#menu-toggle' ); 49 siteNavigation = masthead.find( '#site-navigation' ); 50 51 // Enable menuToggle. 52 ( function() { 53 54 // Return early if menuToggle is missing. 55 if ( ! menuToggle.length ) { 56 return; 57 } 58 59 // Add an initial values for the attribute. 60 menuToggle.add( siteNavigation ).attr( 'aria-expanded', 'false' ); 61 62 menuToggle.on( 'click.brilliant', function() { 63 $( this ).add( siteNavigation ).toggleClass( 'toggled-on' ); 64 65 // jscs:disable 66 $( this ).add( siteNavigation ).attr( 'aria-expanded', $( this ).add( siteNavigation ).attr( 'aria-expanded' ) === 'false' ? 'true' : 'false' ); 67 // jscs:enable 68 } ); 69 } )(); 70 71 // Fix sub-menus for touch devices and better focus for hidden submenu items for accessibility. 72 ( function() { 73 if ( ! siteNavigation.length || ! siteNavigation.children().length ) { 74 return; 75 } 76 77 // Toggle `focus` class to allow submenu access on tablets. 78 function toggleFocusClassTouchScreen() { 79 if ( window.innerWidth >= 960 ) { 80 $( document.body ).on( 'touchstart.brilliant', function( e ) { 81 if ( ! $( e.target ).closest( '.main-navigation li' ).length ) { 82 $( '.main-navigation li' ).removeClass( 'focus' ); 83 } 84 } ); 85 siteNavigation.find( '.menu-item-has-children > a' ).on( 'touchstart.brilliant', function( e ) { 86 var el = $( this ).parent( 'li' ); 87 88 if ( ! el.hasClass( 'focus' ) ) { 89 e.preventDefault(); 90 el.toggleClass( 'focus' ); 91 el.siblings( '.focus' ).removeClass( 'focus' ); 92 } 93 } ); 94 } else { 95 siteNavigation.find( '.menu-item-has-children > a' ).unbind( 'touchstart.brilliant' ); 96 } 97 } 98 99 if ( 'ontouchstart' in window ) { 100 $( window ).on( 'resize.brilliant', toggleFocusClassTouchScreen ); 101 toggleFocusClassTouchScreen(); 102 } 103 104 siteNavigation.find( 'a' ).on( 'focus.brilliant blur.brilliant', function() { 105 $( this ).parents( '.menu-item' ).toggleClass( 'focus' ); 106 } ); 107 } )(); 108 109 // Add the default ARIA attributes for the menu toggle and the navigations. 110 function onResizeARIA() { 111 if ( window.innerWidth < 960 ) { 112 if ( menuToggle.hasClass( 'toggled-on' ) ) { 113 menuToggle.attr( 'aria-expanded', 'true' ); 114 } else { 115 menuToggle.attr( 'aria-expanded', 'false' ); 116 } 117 118 if ( siteNavigation.hasClass( 'toggled-on' ) ) { 119 siteNavigation.attr( 'aria-expanded', 'true' ); 120 } else { 121 siteNavigation.attr( 'aria-expanded', 'false' ); 122 } 123 124 menuToggle.attr( 'aria-controls', 'site-navigation' ); 125 } else { 126 menuToggle.removeAttr( 'aria-expanded' ); 127 siteNavigation.removeAttr( 'aria-expanded' ); 128 menuToggle.removeAttr( 'aria-controls' ); 129 } 130 } 131 132} )( jQuery ); 133 134 135/** 136 * Search Icon Toggle effect 137 */ 138jQuery(document).ready(function(){ 139 jQuery('.top-search-button').click(function(){ 140 jQuery('.top-search').toggleClass('active'); 141 }); 142}); 143 144 145/** 146 * Top Navbar Toggle effect 147 */ 148jQuery(document).ready(function(){ 149 jQuery('#mobile-menu-toggle').click(function(){ 150 jQuery('#top-navbar .button-toggle').toggleClass('close'); 151 jQuery('body').toggleClass('active'); 152 }); 153}); 154 155 156/** 157 * Scroll Up 158 */ 159jQuery(document).ready(function(){ 160 jQuery("#scroll-up").hide(); 161 jQuery(function () { 162 jQuery(window).scroll(function () { 163 if (jQuery(this).scrollTop() > 800) { 164 jQuery('#scroll-up').fadeIn(); 165 } else { 166 jQuery('#scroll-up').fadeOut(); 167 } 168 }); 169 jQuery('a#scroll-up').click(function () { 170 jQuery('body,html').animate({ 171 scrollTop: 0 172 }, 600); 173 return false;
174 }); 175 }); 176}); 177 178 179/** 180 * Skip link focus fix 181 * Helps with accessibility for keyboard only users. 182 */ 183(function() { 184 var isIe = /(trident|msie)/i.test( navigator.userAgent ); 185 186 if ( isIe && document.getElementById && window.addEventListener ) { 187 window.addEventListener( 'hashchange', function() { 188 var id = location.hash.substring( 1 ), 189 element; 190 191 if ( ! ( /^[A-z0-9_-]+$/.test( id ) ) ) { 192 return; 193 } 194 195 element = document.getElementById( id ); 196 197 if ( element ) { 198 if ( ! ( /^(?:a|select|input|button|textarea)$/i.test( element.tagName ) ) ) { 199 element.tabIndex = -1; 200 } 201 202 element.focus(); 203 } 204 }, false ); 205 } 206})();
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.