| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 /** 2 * Accordion-folding functionality. 3 * 4 * Markup with the appropriate classes will be automatically hidden, 5 * with one section opening at a time when its title is clicked. 6 * Use the following markup structure for accordion behavior: 7 * 8 * <div class="accordion-container"> 9 * <div class="accordion-section open"> 10 * <h3 class="accordion-section-title"><button type="button" aria-expanded="true" aria-controls="target-1"></button></h3> 11 * <div class="accordion-section-content" id="target"> 12 * </div> 13 * </div> 14 * <div class="accordion-section"> 15 * <h3 class="accordion-section-title"><button type="button" aria-expanded="false" aria-controls="target-2"></button></h3> 16 * <div class="accordion-section-content" id="target-2"> 17 * </div> 18 * </div> 19 * <div class="accordion-section"> 20 * <h3 class="accordion-section-title"><button type="button" aria-expanded="false" aria-controls="target-3"></button></h3> 21 * <div class="accordion-section-content" id="target-3"> 22 * </div> 23 * </div> 24 * </div> 25 * 26 * Note that any appropriate tags may be used, as long as the above classes are present. 27 * 28 * @since 3.6.0 29 * @output wp-admin/js/accordion.js 30 */ 31 32 /** 33 * @param {JQueryStatic} $ The jQuery object. 34 */ 35 ( function( $ ){ 36 37 $( function () { 38 39 // Expand/Collapse accordion sections on click. 40 $( '.accordion-container' ).on( 'click', '.accordion-section-title button', function() { 41 accordionSwitch( $( this ) ); 42 }); 43 44 }); 45 46 /** 47 * Close the current accordion section and open a new one. 48 * 49 * @param {Object} el Title element of the accordion section to toggle. 50 * @since 3.6.0 51 */ 52 function accordionSwitch ( el ) { 53 var section = el.closest( '.accordion-section' ), 54 container = section.closest( '.accordion-container' ), 55 siblings = container.find( '.open' ), 56 siblingsToggleControl = siblings.find( '[aria-expanded]' ).first(), 57 content = section.find( '.accordion-section-content' ); 58 59 // This section has no content and cannot be expanded. 60 if ( section.hasClass( 'cannot-expand' ) ) { 61 return; 62 } 63 64 // Add a class to the container to let us know something is happening inside. 65 // This helps in cases such as hiding a scrollbar while animations are executing. 66 container.addClass( 'opening' ); 67 68 if ( section.hasClass( 'open' ) ) { 69 section.toggleClass( 'open' ); 70 content.toggle( true ).slideToggle( 150 ); 71 } else { 72 siblingsToggleControl.attr( 'aria-expanded', 'false' ); 73 siblings.removeClass( 'open' ); 74 siblings.find( '.accordion-section-content' ).show().slideUp( 150 ); 75 content.toggle( false ).slideToggle( 150 ); 76 section.toggleClass( 'open' ); 77 } 78 79 // We have to wait for the animations to finish. 80 setTimeout(function(){ 81 container.removeClass( 'opening' ); 82 }, 150); 83 84 // If there's an element with an aria-expanded attribute, assume it's a toggle control and toggle the aria-expanded value. 85 if ( el ) { 86 el.attr( 'aria-expanded', String( el.attr( 'aria-expanded' ) === 'false' ) ); 87 } 88 } 89 90 })(jQuery);
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Fri Sep 4 08:20:24 2026 | Cross-referenced by PHPXref |