Changeset 59916
- Timestamp:
- 03/03/2025 09:05:20 PM (3 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-content/themes/twentyfifteen/js/functions.js
r53247 r59916 15 15 16 16 // Toggle buttons and submenu items with active children menu items. 17 container.find( '.current-menu-ancestor > button' ).addClass( 'toggle-on' ) ;17 container.find( '.current-menu-ancestor > button' ).addClass( 'toggle-on' ).attr( 'aria-expanded', 'true' ); 18 18 container.find( '.current-menu-ancestor > .sub-menu' ).addClass( 'toggled-on' ); 19 19 … … 23 23 _this.toggleClass( 'toggle-on' ); 24 24 _this.next( '.children, .sub-menu' ).toggleClass( 'toggled-on' ); 25 _this.attr( 'aria-expanded', _this. attr( 'aria-expanded' ) === 'false'? 'true' : 'false' );25 _this.attr( 'aria-expanded', _this.hasClass( 'toggle-on' ) ? 'true' : 'false' ); 26 26 _this.html( _this.html() === screenReaderText.expand ? screenReaderText.collapse : screenReaderText.expand ); 27 27 } ); 28 28 } 29 29 initMainNavigation( $( '.main-navigation' ) ); 30 31 // Add unique ID to each .sub-menu and aria-controls to parent links 32 function addUniqueIDToSubMenus() { 33 var subMenus = document.querySelectorAll( '.main-navigation .sub-menu' ); 34 subMenus.forEach( function( subMenu, index ) { 35 var parentLi = subMenu.closest( 'li.menu-item-has-children' ); 36 subMenu.id = 'sub-menu-' + (index + 1); 37 if ( parentLi ) { 38 var parentLink = parentLi.querySelector( 'button' ); 39 if ( parentLink ) { 40 parentLink.setAttribute( 'aria-controls', subMenu.id ); 41 } 42 } 43 } ); 44 } 45 46 addUniqueIDToSubMenus(); 30 47 31 48 // Re-initialize the main navigation when it is updated, persisting any existing submenu expanded states.
Note: See TracChangeset
for help on using the changeset viewer.