+ // Handle the `aria-haspopup` attribute on the current menu item when it has a sub-menu.
+ function currentMenuItemHasPopup() {
+ var respWidth,
+ $current = $( 'a.wp-has-current-submenu' );
+
+ if ( window.innerWidth ) {
+ respWidth = Math.max( window.innerWidth, document.documentElement.clientWidth );
+ } else {
+ respWidth = 961;
+ }
+
+ if ( $body.hasClass( 'folded' ) || ( $body.hasClass( 'auto-fold' ) && respWidth && respWidth <= 960 && respWidth > 782 ) ) {
+ // 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-window-resized wp-responsive-activate wp-responsive-deactivate', currentMenuItemHasPopup );
+