mirror of
https://github.com/WordPress/WordPress.git
synced 2024-08-26 15:53:08 +02:00
* Introduce models for panels and sections. * Introduce API to expand and focus a control, section or panel. * Allow deep-linking to panels, sections, and controls inside of the Customizer. * Clean up `accordion.js`, removing all Customizer-specific logic. * Add initial unit tests for `wp.customize.Class` in `customize-base.js`. https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API. props westonruter, celloexpressions, ryankienstra. see #28032, #28579, #28580, #28650, #28709, #29758. fixes #29529. Built from https://develop.svn.wordpress.org/trunk@30102 git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
76 lines
2.0 KiB
JavaScript
76 lines
2.0 KiB
JavaScript
/**
|
|
* Accordion-folding functionality.
|
|
*
|
|
* Markup with the appropriate classes will be automatically hidden,
|
|
* with one section opening at a time when its title is clicked.
|
|
* Use the following markup structure for accordion behavior:
|
|
*
|
|
* <div class="accordion-container">
|
|
* <div class="accordion-section open">
|
|
* <h3 class="accordion-section-title"></h3>
|
|
* <div class="accordion-section-content">
|
|
* </div>
|
|
* </div>
|
|
* <div class="accordion-section">
|
|
* <h3 class="accordion-section-title"></h3>
|
|
* <div class="accordion-section-content">
|
|
* </div>
|
|
* </div>
|
|
* <div class="accordion-section">
|
|
* <h3 class="accordion-section-title"></h3>
|
|
* <div class="accordion-section-content">
|
|
* </div>
|
|
* </div>
|
|
* </div>
|
|
*
|
|
* Note that any appropriate tags may be used, as long as the above classes are present.
|
|
*
|
|
* @since 3.6.0.
|
|
*/
|
|
|
|
( function( $ ){
|
|
|
|
$( document ).ready( function () {
|
|
|
|
// Expand/Collapse accordion sections on click.
|
|
$( '.accordion-container' ).on( 'click keydown', '.accordion-section-title', function( e ) {
|
|
if ( e.type === 'keydown' && 13 !== e.which ) { // "return" key
|
|
return;
|
|
}
|
|
|
|
e.preventDefault(); // Keep this AFTER the key filter above
|
|
|
|
accordionSwitch( $( this ) );
|
|
});
|
|
|
|
});
|
|
|
|
/**
|
|
* Close the current accordion section and open a new one.
|
|
*
|
|
* @param {Object} el Title element of the accordion section to toggle.
|
|
* @since 3.6.0
|
|
*/
|
|
function accordionSwitch ( el ) {
|
|
var section = el.closest( '.accordion-section' ),
|
|
siblings = section.closest( '.accordion-container' ).find( '.open' ),
|
|
content = section.find( '.accordion-section-content' );
|
|
|
|
// This section has no content and cannot be expanded.
|
|
if ( section.hasClass( 'cannot-expand' ) ) {
|
|
return;
|
|
}
|
|
|
|
if ( section.hasClass( 'open' ) ) {
|
|
section.toggleClass( 'open' );
|
|
content.toggle( true ).slideToggle( 150 );
|
|
} else {
|
|
siblings.removeClass( 'open' );
|
|
siblings.find( '.accordion-section-content' ).show().slideUp( 150 );
|
|
content.toggle( false ).slideToggle( 150 );
|
|
section.toggleClass( 'open' );
|
|
}
|
|
}
|
|
|
|
})(jQuery);
|