/** * Alpha-Centauri.js * * Some custom scripts for this theme. */ ( function( $ ) { // Check distance to top and display back-to-top. $(window).scroll(function(){ if ($(this).scrollTop() > 800) { $( ".back-to-top" ).addClass( "show-back-to-top" ); } else { $( ".back-to-top" ).removeClass( "show-back-to-top" ); } }); // Click event to scroll to top. $( '.back-to-top, .search-toggle' ).click(function(){ $( 'html, body' ).animate({scrollTop : 0},800); return false; }); // Open hidden header to reveal mobile menu. $( ".menu-toggle" ).click(function() { $( "#hidden-header" ).slideToggle( "slow" ); $( ".menu-toggle" ).toggleClass( "menu-toggled" ); // Change aria attritute. if ( $( this ).hasClass( "menu-toggled" ) ) { $( ".menu-toggle" ).attr( "aria-expanded" , "true" ); } else { $( ".menu-toggle" ).attr( "aria-expanded" , "false" ); } }); // Add a focus class to sub menu items with children. $( ".menu-item-has-children" ).on( 'focusin focusout', function() { $( this ).toggleClass( "focus" ); }); // Make focus menu-toggle more intuitif. $( '.menu-toggle' ).click(function(){ // Move focus to first menu item. $( ".menu-toggle" ).on( 'blur', function() { $( '#mobile-navigation' ).find( 'a:eq(0)' ).focus(); }); // Move focus to menu-toggle. $( "#mobile-navigation .search-submit" ).on( 'blur', function() { $( ".menu-toggle" ).focus(); }); }); // Add aria-haspopup to menu items with children. $( "#desktop-navigation .menu-item-has-children" ).attr( "aria-haspopup" , "true" ); // Resize function. $( window ).on( 'resize',function() { var windowWidth = window.innerWidth; // Hide hidden header and remove class if width is more than or equal to 800px. if ( windowWidth >= 800 ) { $( "#hidden-header" ).hide(); $( '.menu-toggle' ).removeClass( 'menu-toggled' ); } }).trigger( 'resize' ); })( jQuery );