9 | 9 | var $body, $window, $sidebar, adminbarOffset, top = false, |
10 | 10 | bottom = false, windowWidth, windowHeight, lastWindowPos = 0, |
11 | 11 | topOffset = 0, bodyHeight, sidebarHeight, resizeTimer, |
12 | | secondary, button; |
13 | | |
14 | | // Add dropdown toggle that display child menu items. |
15 | | $( '.main-navigation .menu-item-has-children > a' ).after( '<button class="dropdown-toggle" aria-expanded="false">' + screenReaderText.expand + '</button>' ); |
16 | | |
17 | | // Toggle buttons and submenu items with active children menu items. |
18 | | $( '.main-navigation .current-menu-ancestor > button' ).addClass( 'toggle-on' ); |
19 | | $( '.main-navigation .current-menu-ancestor > .sub-menu' ).addClass( 'toggled-on' ); |
20 | | |
21 | | $( '.dropdown-toggle' ).click( function( e ) { |
22 | | var _this = $( this ); |
23 | | e.preventDefault(); |
24 | | _this.toggleClass( 'toggle-on' ); |
25 | | _this.next( '.children, .sub-menu' ).toggleClass( 'toggled-on' ); |
26 | | _this.attr( 'aria-expanded', _this.attr( 'aria-expanded' ) === 'false' ? 'true' : 'false' ); |
27 | | _this.html( _this.html() === screenReaderText.expand ? screenReaderText.collapse : screenReaderText.expand ); |
28 | | } ); |
| 12 | secondary, button; |
| 13 | |
| 14 | |
| 15 | function initMainNavigation() { |
| 16 | // Add dropdown toggle that display child menu items. |
| 17 | $( '.main-navigation .menu-item-has-children > a' ).after( '<button class="dropdown-toggle" aria-expanded="false">' + screenReaderText.expand + '</button>' ); |
| 18 | |
| 19 | // Toggle buttons and submenu items with active children menu items. |
| 20 | $( '.main-navigation .current-menu-ancestor > button' ).addClass( 'toggle-on' ); |
| 21 | $( '.main-navigation .current-menu-ancestor > .sub-menu' ).addClass( 'toggled-on' ); |
| 22 | |
| 23 | $( '.dropdown-toggle' ).click( function( e ) { |
| 24 | var _this = $( this ); |
| 25 | e.preventDefault(); |
| 26 | _this.toggleClass( 'toggle-on' ); |
| 27 | _this.next( '.children, .sub-menu' ).toggleClass( 'toggled-on' ); |
| 28 | _this.attr( 'aria-expanded', _this.attr( 'aria-expanded' ) === 'false' ? 'true' : 'false' ); |
| 29 | _this.html( _this.html() === screenReaderText.expand ? screenReaderText.collapse : screenReaderText.expand ); |
| 30 | } ); |
| 31 | } |
| 32 | initMainNavigation(); |
| 33 | $( document ).on( 'customize-preview-menu-refreshed', initMainNavigation ); |