]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-content/themes/twentythirteen/js/functions.js
WordPress 4.2
[autoinstalls/wordpress.git] / wp-content / themes / twentythirteen / js / functions.js
index 526c15d6b3f913cee09decc1581bdf96207b8461..fa8160d53a237f1f0f040ffabb1040d4d2ef0006 100644 (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
         * 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.