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

git-svn-id: https://develop.svn.wordpress.org/trunk@31785 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Lance Willett 2015-03-15 20:00:57 +00:00
parent 3366386aa3
commit b69fe9bd6a
3 changed files with 35 additions and 11 deletions

View File

@ -170,7 +170,7 @@ function twentythirteen_scripts_styles() {
wp_enqueue_script( 'jquery-masonry' );
// Loads JavaScript file with functionality specific to Twenty Thirteen.
wp_enqueue_script( 'twentythirteen-script', get_template_directory_uri() . '/js/functions.js', array( 'jquery' ), '2014-06-08', true );
wp_enqueue_script( 'twentythirteen-script', get_template_directory_uri() . '/js/functions.js', array( 'jquery' ), '20150315', true );
// Add Source Sans Pro and Bitter fonts, used in the main stylesheet.
wp_enqueue_style( 'twentythirteen-fonts', twentythirteen_fonts_url(), array(), null );

View File

@ -42,7 +42,7 @@
<nav id="site-navigation" class="navigation main-navigation" role="navigation">
<button class="menu-toggle"><?php _e( 'Menu', 'twentythirteen' ); ?></button>
<a class="screen-reader-text skip-link" href="#content" title="<?php esc_attr_e( 'Skip to content', 'twentythirteen' ); ?>"><?php _e( 'Skip to content', 'twentythirteen' ); ?></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' ) ); ?>
<?php get_search_form(); ?>
</nav><!-- #site-navigation -->
</div><!-- #navbar -->

View File

@ -6,7 +6,12 @@
( function( $ ) {
var body = $( 'body' ),
_window = $( window );
_window = $( window ),
nav, button, menu;
nav = $( '#site-navigation' );
button = nav.find( '.menu-toggle' );
menu = nav.find( '.nav-menu' );
/**
* Adds a top margin to the footer if the sidebar widget area is higher
@ -29,18 +34,11 @@
* Enables menu toggle for small screens.
*/
( function() {
var nav = $( '#site-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;
@ -48,6 +46,13 @@
button.on( 'click.twentythirteen', 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' );
}
} );
// Fix sub-menus for touch devices.
@ -69,6 +74,25 @@
} );
} )();
// Add or remove ARIA attributes.
function onResizeARIA() {
if ( 643 > _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.twentythirteen', onResizeARIA )
.on( 'resize.twentythirteen', function() {
onResizeARIA();
} );
/**
* Makes "skip to content" link work correctly in IE9 and Chrome for better
* accessibility.