Twenty Fifteen: add ARIA attributes to menu toggle.

See #31527, props davidakennedy, lance.

Built from https://develop.svn.wordpress.org/trunk@31644


git-svn-id: http://core.svn.wordpress.org/trunk@31625 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Lance Willett 2015-03-06 17:34:26 +00:00
parent 38df7e5048
commit 04ff214073
2 changed files with 31 additions and 10 deletions

View File

@ -8,7 +8,8 @@
( function( $ ) { ( function( $ ) {
var $body, $window, $sidebar, adminbarOffset, top = false, var $body, $window, $sidebar, adminbarOffset, top = false,
bottom = false, windowWidth, windowHeight, lastWindowPos = 0, bottom = false, windowWidth, windowHeight, lastWindowPos = 0,
topOffset = 0, bodyHeight, sidebarHeight, resizeTimer; topOffset = 0, bodyHeight, sidebarHeight, resizeTimer,
secondary, button;
// Add dropdown toggle that display child menu items. // Add dropdown toggle that display child menu items.
$( '.main-navigation .menu-item-has-children > a' ).after( '<button class="dropdown-toggle" aria-expanded="false">' + screenReaderText.expand + '</button>' ); $( '.main-navigation .menu-item-has-children > a' ).after( '<button class="dropdown-toggle" aria-expanded="false">' + screenReaderText.expand + '</button>' );
@ -26,15 +27,13 @@
_this.html( _this.html() === screenReaderText.expand ? screenReaderText.collapse : screenReaderText.expand ); _this.html( _this.html() === screenReaderText.expand ? screenReaderText.collapse : screenReaderText.expand );
} ); } );
secondary = $( '#secondary' );
button = $( '.site-branding' ).find( '.secondary-toggle' );
// Enable menu toggle for small screens. // Enable menu toggle for small screens.
( function() { ( function() {
var secondary = $( '#secondary' ), button, menu, widgets, social; var menu, widgets, social;
if ( ! secondary ) { if ( ! secondary || ! button ) {
return;
}
button = $( '.site-branding' ).find( '.secondary-toggle' );
if ( ! button ) {
return; return;
} }
@ -51,9 +50,29 @@
secondary.toggleClass( 'toggled-on' ); secondary.toggleClass( 'toggled-on' );
secondary.trigger( 'resize' ); secondary.trigger( 'resize' );
$( this ).toggleClass( 'toggled-on' ); $( this ).toggleClass( 'toggled-on' );
if ( $( this, secondary ).hasClass( 'toggled-on' ) ) {
$( this ).attr( 'aria-expanded', 'true' );
secondary.attr( 'aria-expanded', 'true' );
} else {
$( this ).attr( 'aria-expanded', 'false' );
secondary.attr( 'aria-expanded', 'false' );
}
} ); } );
} )(); } )();
// Add or remove ARIA attributes.
function onResizeARIA() {
if ( 955 > $window.width() ) {
button.attr( 'aria-expanded', 'false' );
secondary.attr( 'aria-expanded', 'false' );
button.attr( 'aria-controls', 'secondary' );
} else {
button.removeAttr( 'aria-expanded' );
secondary.removeAttr( 'aria-expanded' );
button.removeAttr( 'aria-controls' );
}
}
// Sidebar scrolling. // Sidebar scrolling.
function resize() { function resize() {
windowWidth = $window.width(); windowWidth = $window.width();
@ -119,11 +138,13 @@
$window $window
.on( 'scroll.twentyfifteen', scroll ) .on( 'scroll.twentyfifteen', scroll )
.on( 'load.twentyfifteen', onResizeARIA )
.on( 'resize.twentyfifteen', function() { .on( 'resize.twentyfifteen', function() {
clearTimeout( resizeTimer ); clearTimeout( resizeTimer );
resizeTimer = setTimeout( resizeAndScroll, 500 ); resizeTimer = setTimeout( resizeAndScroll, 500 );
onResizeARIA();
} ); } );
$sidebar.on( 'click keydown', 'button', resizeAndScroll ); $sidebar.on( 'click.twentyfifteen keydown.twentyfifteen', 'button', resizeAndScroll );
resizeAndScroll(); resizeAndScroll();

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.2-alpha-31643'; $wp_version = '4.2-alpha-31644';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.