( function( $ ) { var siteHeader, menuIcon, navContainer, siteNavigation; function initMainNavigation( container ) { var dropdownToggle = $( '', { 'role': 'button', 'class': 'dropdown-toggle', 'aria-expanded': false }) .append( bansta_nav_args.icon ) container.find( '.menu-item-has-children > a, .page_item_has_children > a' ).append( dropdownToggle ); container.find( '.current-menu-ancestor > button' ) .addClass( 'toggled-on' ) .attr( 'aria-expanded', 'true' ) .find( '.screen-reader-text' ) .text( bansta_nav_args.collapse ); container.find( '.dropdown-toggle' ).click( function( e ) { e.preventDefault(); var _this = $( this ), screenReaderSpan = _this.find( '.screen-reader-text' ); _this.toggleClass( 'toggled-on' ); _this.next( '.children, .sub-menu' ).toggleClass( 'toggled-on' ); _this.attr( 'aria-expanded', _this.attr( 'aria-expanded' ) === 'false' ? 'true' : 'false' ); screenReaderSpan.text( screenReaderSpan.text() === bansta_nav_args.expand ? bansta_nav_args.collapse : bansta_nav_args.expand ); }); container.find( '.current-menu-ancestor > .sub-menu' ).addClass( 'toggled-on' ); } initMainNavigation( $( '.primary-navigation, .off-canvas-menu' ) ); siteHeader = $( '#site-header' ); menuIcon = siteHeader.find( '.menu-icon' ); navContainer = siteHeader.find( '.navigation-menu' ); siteNavigation = siteHeader.find( '.navigation-menu > ul' ); ( function() { menuIcon.attr( 'aria-expanded', 'false' ); menuIcon.on( 'click', function() { navContainer.toggleClass( 'toggled-on' ); $( this ).attr( 'aria-expanded', navContainer.hasClass( 'toggled-on' ) ); }); })(); ( function() { $('.dropdown-toggle').click(function() { $(this).parents('li').first().find('.sub-menu').first().slideToggle(); $(this).parents('li').first().find('.children').first().slideToggle(); }); }) (); ( function() { if ( ! siteNavigation.length || ! siteNavigation.children().length ) { return; } // Toggle `focus` class to allow submenu access on tablets. function focusTouch() { if ( 'none' === $( '.menu-icon' ).css( 'display' ) ) { $( document.body ).on( 'touchstart', function( e ) { if ( ! $( e.target ).closest( '.navigation-menu li' ).length ) { $( '.navigation-menu li' ).removeClass( 'focus' ); } }); siteNavigation.find( '.menu-item-has-children > a, .page_item_has_children > a' ) .on( 'touchstart', function( e ) { var el = $( this ).parent( 'li' ); if ( ! el.hasClass( 'focus' ) ) { e.preventDefault(); el.toggleClass( 'focus' ); el.siblings( '.focus' ).removeClass( 'focus' ); } }); } else { siteNavigation.find( '.menu-item-has-children > a, .page_item_has_children > a' ).unbind( 'touchstart' ); } } if ( 'ontouchstart' in window ) { $( window ).on( 'resize', focusTouch ); focusTouch(); } siteNavigation.find( 'a' ).on( 'focus blur', function() { $( this ).parents( '.menu-item, .page_item' ).toggleClass( 'focus' ); }); })(); })( jQuery );