X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/f5fcdc7994bb67cce809bc4777944ae8b7fad4a4..53f4633144ed68c8b8fb5861f992b5489894a940:/wp-admin/js/accordion.js diff --git a/wp-admin/js/accordion.js b/wp-admin/js/accordion.js index 1769d27d..af628154 100644 --- a/wp-admin/js/accordion.js +++ b/wp-admin/js/accordion.js @@ -53,7 +53,10 @@ */ function accordionSwitch ( el ) { var section = el.closest( '.accordion-section' ), - siblings = section.closest( '.accordion-container' ).find( '.open' ), + sectionToggleControl = section.find( '[aria-expanded]' ).first(), + container = section.closest( '.accordion-container' ), + siblings = container.find( '.open' ), + siblingsToggleControl = siblings.find( '[aria-expanded]' ).first(), content = section.find( '.accordion-section-content' ); // This section has no content and cannot be expanded. @@ -61,15 +64,30 @@ return; } + // Add a class to the container to let us know something is happening inside. + // This helps in cases such as hiding a scrollbar while animations are executing. + container.addClass( 'opening' ); + if ( section.hasClass( 'open' ) ) { section.toggleClass( 'open' ); content.toggle( true ).slideToggle( 150 ); } else { + siblingsToggleControl.attr( 'aria-expanded', 'false' ); siblings.removeClass( 'open' ); siblings.find( '.accordion-section-content' ).show().slideUp( 150 ); content.toggle( false ).slideToggle( 150 ); section.toggleClass( 'open' ); } + + // We have to wait for the animations to finish + setTimeout(function(){ + container.removeClass( 'opening' ); + }, 150); + + // If there's an element with an aria-expanded attribute, assume it's a toggle control and toggle the aria-expanded value. + if ( sectionToggleControl ) { + sectionToggleControl.attr( 'aria-expanded', String( sectionToggleControl.attr( 'aria-expanded' ) === 'false' ) ); + } } })(jQuery);