X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/fa6ee2c363cdfdebcb4b76e4d9c4347a4cb19065..refs/tags/wordpress-4.2:/wp-content/themes/twentyfifteen/js/functions.js
diff --git a/wp-content/themes/twentyfifteen/js/functions.js b/wp-content/themes/twentyfifteen/js/functions.js
index 6610757e..eeeecd22 100644
--- a/wp-content/themes/twentyfifteen/js/functions.js
+++ b/wp-content/themes/twentyfifteen/js/functions.js
@@ -8,10 +8,15 @@
( function( $ ) {
var $body, $window, $sidebar, adminbarOffset, top = false,
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.
- $( '.main-navigation .page_item_has_children > a, .main-navigation .menu-item-has-children > a' ).after( '' );
+ $( '.main-navigation .menu-item-has-children > a' ).after( '' );
+
+ // Toggle buttons and submenu items with active children menu items.
+ $( '.main-navigation .current-menu-ancestor > button' ).addClass( 'toggle-on' );
+ $( '.main-navigation .current-menu-ancestor > .sub-menu' ).addClass( 'toggled-on' );
$( '.dropdown-toggle' ).click( function( e ) {
var _this = $( this );
@@ -22,15 +27,13 @@
_this.html( _this.html() === screenReaderText.expand ? screenReaderText.collapse : screenReaderText.expand );
} );
+ secondary = $( '#secondary' );
+ button = $( '.site-branding' ).find( '.secondary-toggle' );
+
// Enable menu toggle for small screens.
( function() {
- var secondary = $( '#secondary' ), button, menu, widgets, social;
- if ( ! secondary ) {
- return;
- }
-
- button = $( '.site-branding' ).find( '.secondary-toggle' );
- if ( ! button ) {
+ var menu, widgets, social;
+ if ( ! secondary || ! button ) {
return;
}
@@ -47,15 +50,37 @@
secondary.toggleClass( 'toggled-on' );
secondary.trigger( 'resize' );
$( 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' );
+ }
} );
} )();
+ /**
+ * @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 Fifteen 1.1
+ */
+ 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.
function resize() {
- windowWidth = $window.width();
- windowHeight = $window.height();
- bodyHeight = $body.height();
- sidebarHeight = $sidebar.height();
+ windowWidth = $window.width();
if ( 955 > windowWidth ) {
top = bottom = false;
@@ -70,6 +95,10 @@
return;
}
+ sidebarHeight = $sidebar.height();
+ windowHeight = $window.height();
+ bodyHeight = $body.height();
+
if ( sidebarHeight + adminbarOffset > windowHeight ) {
if ( windowPos > lastWindowPos ) {
if ( top ) {
@@ -115,11 +144,13 @@
$window
.on( 'scroll.twentyfifteen', scroll )
+ .on( 'load.twentyfifteen', onResizeARIA )
.on( 'resize.twentyfifteen', function() {
clearTimeout( resizeTimer );
resizeTimer = setTimeout( resizeAndScroll, 500 );
+ onResizeARIA();
} );
- $sidebar.on( 'click keydown', 'button', resizeAndScroll );
+ $sidebar.on( 'click.twentyfifteen keydown.twentyfifteen', 'button', resizeAndScroll );
resizeAndScroll();