Ticket #31527: 31527.2.patch
File 31527.2.patch, 2.6 KB (added by , 10 years ago) |
---|
-
wp-content/themes/twentyfifteen/js/functions.js
8 8 ( function( $ ) { 9 9 var $body, $window, $sidebar, adminbarOffset, top = false, 10 10 bottom = false, windowWidth, windowHeight, lastWindowPos = 0, 11 topOffset = 0, bodyHeight, sidebarHeight, resizeTimer; 11 topOffset = 0, bodyHeight, sidebarHeight, resizeTimer, 12 secondary, button; 12 13 13 14 // Add dropdown toggle that display child menu items. 14 15 $( '.main-navigation .menu-item-has-children > a' ).after( '<button class="dropdown-toggle" aria-expanded="false">' + screenReaderText.expand + '</button>' ); … … 26 27 _this.html( _this.html() === screenReaderText.expand ? screenReaderText.collapse : screenReaderText.expand ); 27 28 } ); 28 29 30 secondary = $( '#secondary' ); 31 button = $( '.site-branding' ).find( '.secondary-toggle' ); 32 29 33 // Enable menu toggle for small screens. 30 34 ( function() { 31 var secondary = $( '#secondary' ), button,menu, widgets, social;35 var menu, widgets, social; 32 36 if ( ! secondary ) { 33 37 return; 34 38 } 35 39 36 button = $( '.site-branding' ).find( '.secondary-toggle' );37 40 if ( ! button ) { 38 41 return; 39 42 } … … 51 54 secondary.toggleClass( 'toggled-on' ); 52 55 secondary.trigger( 'resize' ); 53 56 $( this ).toggleClass( 'toggled-on' ); 57 if ( $( this, secondary ).hasClass( 'toggled-on' ) ) { 58 $( this ).attr( 'aria-expanded', 'true' ); 59 secondary.attr( 'aria-expanded', 'true' ); 60 } else { 61 $( this ).attr( 'aria-expanded', 'false' ); 62 secondary.attr( 'aria-expanded', 'false' ); 63 } 54 64 } ); 55 65 } )(); 56 66 67 // Add or remove ARIA attributes. 68 function onResizeARIA() { 69 if ( 955 > $window.width() ) { 70 button.attr( 'aria-expanded', 'false' ); 71 secondary.attr( 'aria-expanded', 'false' ); 72 button.attr( 'aria-controls', 'secondary' ); 73 } else { 74 button.removeAttr( 'aria-expanded' ); 75 secondary.removeAttr( 'aria-expanded' ); 76 button.removeAttr( 'aria-controls' ); 77 } 78 } 79 57 80 // Sidebar scrolling. 58 81 function resize() { 59 82 windowWidth = $window.width(); … … 119 142 120 143 $window 121 144 .on( 'scroll.twentyfifteen', scroll ) 145 .on( 'load.twentyfifteen', onResizeARIA ) 122 146 .on( 'resize.twentyfifteen', function() { 123 147 clearTimeout( resizeTimer ); 124 148 resizeTimer = setTimeout( resizeAndScroll, 500 ); 149 onResizeARIA(); 125 150 } ); 126 $sidebar.on( 'click keydown', 'button', resizeAndScroll );151 $sidebar.on( 'click.twentyfifteen keydown.twentyfifteen', 'button', resizeAndScroll ); 127 152 128 153 resizeAndScroll(); 129 154