diff options
Diffstat (limited to 'wp-admin/js/common.js')
-rw-r--r-- | wp-admin/js/common.js | 59 |
1 files changed, 34 insertions, 25 deletions
diff --git a/wp-admin/js/common.js b/wp-admin/js/common.js index af6cedc..b2d8b56 100644 --- a/wp-admin/js/common.js +++ b/wp-admin/js/common.js @@ -903,27 +903,6 @@ $( function() { }); /** - * Handles the `aria-haspopup` attribute on the current menu item when it has a submenu. - * - * @since 4.4.0 - * - * @return {void} - */ - function currentMenuItemHasPopup() { - var $current = $( 'a.wp-has-current-submenu' ); - - if ( 'folded' === menuState ) { - // When folded or auto-folded and not responsive view, the current menu item does have a fly-out sub-menu. - $current.attr( 'aria-haspopup', 'true' ); - } else { - // When expanded or in responsive view, reset aria-haspopup. - $current.attr( 'aria-haspopup', 'false' ); - } - } - - $document.on( 'wp-menu-state-set wp-collapse-menu wp-responsive-activate wp-responsive-deactivate', currentMenuItemHasPopup ); - - /** * Ensures an admin submenu is within the visual viewport. * * @since 4.1.0 @@ -1169,7 +1148,7 @@ $( function() { lastClicked = this; // Toggle the "Select all" checkboxes depending if the other ones are all checked or not. - var unchecked = $(this).closest('tbody').find('tr.iedit').find(':checkbox').filter(':visible:enabled').not(':checked'); + var unchecked = $(this).closest('tbody').find('tr').find(':checkbox').filter(':visible:enabled').not(':checked'); /** * Determines if all checkboxes are checked. @@ -1695,8 +1674,10 @@ $( function() { // Modify functionality based on custom activate/deactivate event. $document.on( 'wp-responsive-activate.wp-responsive', function() { self.activate(); + self.toggleAriaHasPopup( 'add' ); }).on( 'wp-responsive-deactivate.wp-responsive', function() { self.deactivate(); + self.toggleAriaHasPopup( 'remove' ); }); $( '#wp-admin-bar-menu-toggle a' ).attr( 'aria-expanded', 'false' ); @@ -1748,7 +1729,7 @@ $( function() { setTimeout( function() { var focusIsInToggle = $.contains( toggleButton, focusedElement ); var focusIsInSidebar = $.contains( sidebar, focusedElement ); - + if ( ! focusIsInToggle && ! focusIsInSidebar ) { $( toggleButton ).trigger( 'click.wp-responsive' ); } @@ -1762,8 +1743,9 @@ $( function() { if ( ! $adminmenu.data('wp-responsive') ) { return; } - + let state = ( 'false' === $( this ).attr( 'aria-expanded' ) ) ? 'true' : 'false'; $( this ).parent( 'li' ).toggleClass( 'selected' ); + $( this ).attr( 'aria-expanded', state ); $( this ).trigger( 'focus' ); event.preventDefault(); }); @@ -1838,6 +1820,34 @@ $( function() { }, /** + * Toggles the aria-haspopup attribute for the responsive admin menu. + * + * The aria-haspopup attribute is only necessary for the responsive menu. + * See ticket https://core.trac.wordpress.org/ticket/43095 + * + * @since 6.6.0 + * + * @param {string} action Whether to add or remove the aria-haspopup attribute. + * + * @return {void} + */ + toggleAriaHasPopup: function( action ) { + var elements = $adminmenu.find( '[data-ariahaspopup]' ); + + if ( action === 'add' ) { + elements.each( function() { + $( this ).attr( 'aria-haspopup', 'menu' ).attr( 'aria-expanded', 'false' ); + } ); + + return; + } + + elements.each( function() { + $( this ).removeAttr( 'aria-haspopup' ).removeAttr( 'aria-expanded' ); + } ); + }, + + /** * Sets the responsiveness and enables the overlay based on the viewport width. * * @since 3.8.0 @@ -2034,7 +2044,6 @@ $( function() { window.wpResponsive.init(); setPinMenu(); setMenuState(); - currentMenuItemHasPopup(); makeNoticesDismissible(); aria_button_if_js(); |