Twenty Fourteen: add ARIA attributes to menu toggle. See #31527.

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


git-svn-id: http://core.svn.wordpress.org/trunk@31764 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Lance Willett 2015-03-15 20:00:27 +00:00
parent 8c7ffba3b2
commit f81f253434
4 changed files with 37 additions and 13 deletions

View File

@ -260,7 +260,7 @@ function twentyfourteen_scripts() {
) );
}
wp_enqueue_script( 'twentyfourteen-script', get_template_directory_uri() . '/js/functions.js', array( 'jquery' ), '20140616', true );
wp_enqueue_script( 'twentyfourteen-script', get_template_directory_uri() . '/js/functions.js', array( 'jquery' ), '20150315', true );
}
add_action( 'wp_enqueue_scripts', 'twentyfourteen_scripts' );

View File

@ -51,7 +51,7 @@
<nav id="primary-navigation" class="site-navigation primary-navigation" role="navigation">
<button class="menu-toggle"><?php _e( 'Primary Menu', 'twentyfourteen' ); ?></button>
<a class="screen-reader-text skip-link" href="#content"><?php _e( 'Skip to content', 'twentyfourteen' ); ?></a>
<?php wp_nav_menu( array( 'theme_location' => 'primary', 'menu_class' => 'nav-menu' ) ); ?>
<?php wp_nav_menu( array( 'theme_location' => 'primary', 'menu_class' => 'nav-menu', 'menu_id' => 'primary-menu' ) ); ?>
</nav>
</div>

View File

@ -7,29 +7,34 @@
*/
( function( $ ) {
var body = $( 'body' ),
_window = $( window );
_window = $( window ),
nav, button, menu;
nav = $( '#primary-navigation' );
button = nav.find( '.menu-toggle' );
menu = nav.find( '.nav-menu' );
// Enable menu toggle for small screens.
( function() {
var nav = $( '#primary-navigation' ), button, menu;
if ( ! nav ) {
return;
}
button = nav.find( '.menu-toggle' );
if ( ! button ) {
if ( ! nav || ! button ) {
return;
}
// Hide button if menu is missing or empty.
menu = nav.find( '.nav-menu' );
if ( ! menu || ! menu.children().length ) {
button.hide();
return;
}
$( '.menu-toggle' ).on( 'click.twentyfourteen', function() {
button.on( 'click.twentyfourteen', function() {
nav.toggleClass( 'toggled-on' );
if ( nav.hasClass( 'toggled-on' ) ) {
$( this ).attr( 'aria-expanded', 'true' );
menu.attr( 'aria-expanded', 'true' );
} else {
$( this ).attr( 'aria-expanded', 'false' );
menu.attr( 'aria-expanded', 'false' );
}
} );
} )();
@ -109,6 +114,25 @@
} );
} );
// Add or remove ARIA attributes.
function onResizeARIA() {
if ( 781 > _window.width() ) {
button.attr( 'aria-expanded', 'false' );
menu.attr( 'aria-expanded', 'false' );
button.attr( 'aria-controls', 'primary-menu' );
} else {
button.removeAttr( 'aria-expanded' );
menu.removeAttr( 'aria-expanded' );
button.removeAttr( 'aria-controls' );
}
}
_window
.on( 'load.twentyfourteen', onResizeARIA )
.on( 'resize.twentyfourteen', function() {
onResizeARIA();
} );
_window.load( function() {
// Arrange footer widgets vertically.
if ( $.isFunction( $.fn.masonry ) ) {

View File

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