2014-07-08 22:22:15 +02:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
2017-12-15 06:16:47 +01:00
|
|
|
* @since 3.6.0
|
2018-06-28 04:30:15 +02:00
|
|
|
* @output wp-admin/js/accordion.js
|
2014-07-08 22:22:15 +02:00
|
|
|
*/
|
|
|
|
|
2013-07-12 20:16:29 +02:00
|
|
|
( function( $ ){
|
|
|
|
|
|
|
|
$( document ).ready( function () {
|
|
|
|
|
2014-07-08 22:22:15 +02:00
|
|
|
// Expand/Collapse accordion sections on click.
|
2013-07-12 20:16:29 +02:00
|
|
|
$( '.accordion-container' ).on( 'click keydown', '.accordion-section-title', function( e ) {
|
2020-01-29 01:45:18 +01:00
|
|
|
if ( e.type === 'keydown' && 13 !== e.which ) { // "Return" key.
|
2014-06-26 22:17:15 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
e.preventDefault(); // Keep this AFTER the key filter above.
|
2013-07-12 20:16:29 +02:00
|
|
|
|
|
|
|
accordionSwitch( $( this ) );
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2014-07-08 22:22:15 +02:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2013-07-12 20:16:29 +02:00
|
|
|
function accordionSwitch ( el ) {
|
|
|
|
var section = el.closest( '.accordion-section' ),
|
2015-07-24 22:28:25 +02:00
|
|
|
sectionToggleControl = section.find( '[aria-expanded]' ).first(),
|
2015-07-30 01:40:25 +02:00
|
|
|
container = section.closest( '.accordion-container' ),
|
|
|
|
siblings = container.find( '.open' ),
|
2015-07-24 22:28:25 +02:00
|
|
|
siblingsToggleControl = siblings.find( '[aria-expanded]' ).first(),
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* 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
2014-10-29 23:51:22 +01:00
|
|
|
content = section.find( '.accordion-section-content' );
|
2013-07-12 20:16:29 +02:00
|
|
|
|
2014-07-08 22:22:15 +02:00
|
|
|
// This section has no content and cannot be expanded.
|
2014-06-26 22:17:15 +02:00
|
|
|
if ( section.hasClass( 'cannot-expand' ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-07-30 01:40:25 +02:00
|
|
|
// 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' );
|
|
|
|
|
2013-07-18 19:42:53 +02:00
|
|
|
if ( section.hasClass( 'open' ) ) {
|
|
|
|
section.toggleClass( 'open' );
|
|
|
|
content.toggle( true ).slideToggle( 150 );
|
|
|
|
} else {
|
2015-07-24 22:28:25 +02:00
|
|
|
siblingsToggleControl.attr( 'aria-expanded', 'false' );
|
2013-07-18 19:42:53 +02:00
|
|
|
siblings.removeClass( 'open' );
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* 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
2014-10-29 23:51:22 +01:00
|
|
|
siblings.find( '.accordion-section-content' ).show().slideUp( 150 );
|
2013-07-18 19:42:53 +02:00
|
|
|
content.toggle( false ).slideToggle( 150 );
|
|
|
|
section.toggleClass( 'open' );
|
|
|
|
}
|
2015-07-24 22:28:25 +02:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// We have to wait for the animations to finish.
|
2015-07-30 01:40:25 +02:00
|
|
|
setTimeout(function(){
|
|
|
|
container.removeClass( 'opening' );
|
|
|
|
}, 150);
|
|
|
|
|
2015-07-24 22:28:25 +02:00
|
|
|
// 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' ) );
|
|
|
|
}
|
2013-07-12 20:16:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
})(jQuery);
|