Administration: the current admin menu item should have an `aria-haspopup` attribute when the menu is folded.

Unify the jQuery selector caching for `window`, `document`, and `body`.

Props afercia.
Fixes #32578.


git-svn-id: https://develop.svn.wordpress.org/trunk@35313 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor 2015-10-21 03:40:38 +00:00
parent e4bcddecfb
commit be739bd6c0
1 changed files with 43 additions and 18 deletions

View File

@ -1,6 +1,10 @@
/* global setUserSetting, ajaxurl, commonL10n, alert, confirm, pagenow */ /* global setUserSetting, ajaxurl, commonL10n, alert, confirm, pagenow */
var showNotice, adminMenu, columns, validateForm, screenMeta; var showNotice, adminMenu, columns, validateForm, screenMeta;
( function( $, window, undefined ) { ( function( $, window, undefined ) {
var $document = $( document ),
$window = $( window ),
$body = $( document.body );
// Removed in 3.3. // Removed in 3.3.
// (perhaps) needed for back-compat // (perhaps) needed for back-compat
adminMenu = { adminMenu = {
@ -70,7 +74,7 @@ columns = {
} }
}; };
$(document).ready(function(){columns.init();}); $document.ready(function(){columns.init();});
validateForm = function( form ) { validateForm = function( form ) {
return !$( form ) return !$( form )
@ -133,7 +137,7 @@ screenMeta = {
button.addClass( 'screen-meta-active' ).attr( 'aria-expanded', true ); button.addClass( 'screen-meta-active' ).attr( 'aria-expanded', true );
}); });
$( document ).trigger( 'screen:options:open' ); $document.trigger( 'screen:options:open' );
}, },
close: function( panel, button ) { close: function( panel, button ) {
@ -143,7 +147,7 @@ screenMeta = {
panel.parent().hide(); panel.parent().hide();
}); });
$( document ).trigger( 'screen:options:close' ); $document.trigger( 'screen:options:close' );
} }
}; };
@ -171,7 +175,7 @@ $('.contextual-help-tabs').delegate('a', 'click', function(e) {
panel.addClass('active').show(); panel.addClass('active').show();
}); });
$(document).ready( function() { $document.ready( function() {
var checks, first, last, checked, sliced, mobileEvent, transitionTimeout, focusedRowActions, var checks, first, last, checked, sliced, mobileEvent, transitionTimeout, focusedRowActions,
lastClicked = false, lastClicked = false,
pageInput = $('input.current-page'), pageInput = $('input.current-page'),
@ -179,9 +183,6 @@ $(document).ready( function() {
isIOS = /iPhone|iPad|iPod/.test( navigator.userAgent ), isIOS = /iPhone|iPad|iPod/.test( navigator.userAgent ),
isAndroid = navigator.userAgent.indexOf( 'Android' ) !== -1, isAndroid = navigator.userAgent.indexOf( 'Android' ) !== -1,
isIE8 = $( document.documentElement ).hasClass( 'ie8' ), isIE8 = $( document.documentElement ).hasClass( 'ie8' ),
$document = $( document ),
$window = $( window ),
$body = $( document.body ),
$adminMenuWrap = $( '#adminmenuwrap' ), $adminMenuWrap = $( '#adminmenuwrap' ),
$wpwrap = $( '#wpwrap' ), $wpwrap = $( '#wpwrap' ),
$adminmenu = $( '#adminmenu' ), $adminmenu = $( '#adminmenu' ),
@ -210,7 +211,7 @@ $(document).ready( function() {
}); });
$('#collapse-menu').on('click.collapse-menu', function() { $('#collapse-menu').on('click.collapse-menu', function() {
var body = $( document.body ), respWidth, state; var respWidth, state;
// reset any compensation for submenus near the bottom of the screen // reset any compensation for submenus near the bottom of the screen
$('#adminmenu div.wp-submenu').css('margin-top', ''); $('#adminmenu div.wp-submenu').css('margin-top', '');
@ -224,31 +225,54 @@ $(document).ready( function() {
} }
if ( respWidth && respWidth < 960 ) { if ( respWidth && respWidth < 960 ) {
if ( body.hasClass('auto-fold') ) { if ( $body.hasClass('auto-fold') ) {
body.removeClass('auto-fold').removeClass('folded'); $body.removeClass('auto-fold').removeClass('folded');
setUserSetting('unfold', 1); setUserSetting('unfold', 1);
setUserSetting('mfold', 'o'); setUserSetting('mfold', 'o');
state = 'open'; state = 'open';
} else { } else {
body.addClass('auto-fold'); $body.addClass('auto-fold');
setUserSetting('unfold', 0); setUserSetting('unfold', 0);
state = 'folded'; state = 'folded';
} }
} else { } else {
if ( body.hasClass('folded') ) { if ( $body.hasClass('folded') ) {
body.removeClass('folded'); $body.removeClass('folded');
setUserSetting('mfold', 'o'); setUserSetting('mfold', 'o');
state = 'open'; state = 'open';
} else { } else {
body.addClass('folded'); $body.addClass('folded');
setUserSetting('mfold', 'f'); setUserSetting('mfold', 'f');
state = 'folded'; state = 'folded';
} }
} }
$( document ).trigger( 'wp-collapse-menu', { state: state } ); currentMenuItemHasPopup();
$document.trigger( 'wp-collapse-menu', { state: state } );
}); });
// 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 );
/** /**
* Ensure an admin submenu is within the visual viewport. * Ensure an admin submenu is within the visual viewport.
* *
@ -289,7 +313,7 @@ $(document).ready( function() {
mobileEvent = isIOS ? 'touchstart' : 'click'; mobileEvent = isIOS ? 'touchstart' : 'click';
// close any open submenus when touch/click is not on the menu // close any open submenus when touch/click is not on the menu
$(document.body).on( mobileEvent+'.wp-mobile-hover', function(e) { $body.on( mobileEvent+'.wp-mobile-hover', function(e) {
if ( $adminmenu.data('wp-responsive') ) { if ( $adminmenu.data('wp-responsive') ) {
return; return;
} }
@ -866,6 +890,7 @@ $(document).ready( function() {
window.wpResponsive.init(); window.wpResponsive.init();
setPinMenu(); setPinMenu();
currentMenuItemHasPopup();
$document.on( 'wp-pin-menu wp-window-resized.pin-menu postboxes-columnchange.pin-menu postbox-toggled.pin-menu wp-collapse-menu.pin-menu wp-scroll-start.pin-menu', setPinMenu ); $document.on( 'wp-pin-menu wp-window-resized.pin-menu postboxes-columnchange.pin-menu postbox-toggled.pin-menu wp-collapse-menu.pin-menu wp-scroll-start.pin-menu', setPinMenu );
}); });
@ -875,7 +900,7 @@ $(document).ready( function() {
var timeout; var timeout;
function triggerEvent() { function triggerEvent() {
$(document).trigger( 'wp-window-resized' ); $document.trigger( 'wp-window-resized' );
} }
function fireOnce() { function fireOnce() {
@ -883,7 +908,7 @@ $(document).ready( function() {
timeout = window.setTimeout( triggerEvent, 200 ); timeout = window.setTimeout( triggerEvent, 200 );
} }
$(window).on( 'resize.wp-fire-once', fireOnce ); $window.on( 'resize.wp-fire-once', fireOnce );
}()); }());
// Make Windows 8 devices play along nicely. // Make Windows 8 devices play along nicely.