( 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
* 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;
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.
if ( 'ontouchstart' in window ) {
- menu.find( '.menu-item-has-children > a' ).on( 'touchstart.twentythirteen', function( e ) {
+ menu.find( '.menu-item-has-children > a, .page_item_has_children > a' ).on( 'touchstart.twentythirteen', function( e ) {
var el = $( this ).parent( 'li' );
if ( ! el.hasClass( 'focus' ) ) {
} );
} )();
+ /**
+ * @summary Add or remove ARIA attributes.
+ * Uses jQuery's width() function to determine the size of the window and add
+ * the default ARIA attributes for the menu toggle if it's visible.
+ * @since Twenty Thirteen 1.5
+ */
+ 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.