2014-07-08 16:22:15 -04: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.
|
|
|
|
*
|
|
|
|
* In addition to the standard accordion behavior, this file includes JS for the
|
|
|
|
* Customizer's "Panel" functionality.
|
|
|
|
*
|
|
|
|
* @since 3.6.0.
|
|
|
|
*/
|
|
|
|
|
2013-07-12 14:16:29 -04:00
|
|
|
( function( $ ){
|
|
|
|
|
|
|
|
$( document ).ready( function () {
|
|
|
|
|
2014-07-08 16:22:15 -04:00
|
|
|
// Expand/Collapse accordion sections on click.
|
2013-07-12 14:16:29 -04:00
|
|
|
$( '.accordion-container' ).on( 'click keydown', '.accordion-section-title', function( e ) {
|
2014-06-26 16:17:15 -04:00
|
|
|
if ( e.type === 'keydown' && 13 !== e.which ) { // "return" key
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-07-12 14:16:29 -04:00
|
|
|
e.preventDefault(); // Keep this AFTER the key filter above
|
|
|
|
|
|
|
|
accordionSwitch( $( this ) );
|
|
|
|
});
|
|
|
|
|
2014-07-08 16:22:15 -04:00
|
|
|
// Go back to the top-level Customizer accordion.
|
2014-08-25 19:05:15 -04:00
|
|
|
$( '#customize-header-actions' ).on( 'click keydown', '.control-panel-back', function( e ) {
|
2014-06-26 16:17:15 -04:00
|
|
|
if ( e.type === 'keydown' && 13 !== e.which ) { // "return" key
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
e.preventDefault(); // Keep this AFTER the key filter above
|
|
|
|
|
2014-08-25 19:05:15 -04:00
|
|
|
panelSwitch( $( '.current-panel' ) );
|
2014-06-26 16:17:15 -04:00
|
|
|
});
|
2013-07-12 14:16:29 -04:00
|
|
|
});
|
|
|
|
|
2014-07-09 13:46:14 -04:00
|
|
|
var sectionContent = $( '.accordion-section-content' );
|
2013-07-12 14:16:29 -04:00
|
|
|
|
2014-07-08 16:22:15 -04: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 14:16:29 -04:00
|
|
|
function accordionSwitch ( el ) {
|
|
|
|
var section = el.closest( '.accordion-section' ),
|
2013-07-18 13:42:53 -04:00
|
|
|
siblings = section.closest( '.accordion-container' ).find( '.open' ),
|
|
|
|
content = section.find( sectionContent );
|
2013-07-12 14:16:29 -04:00
|
|
|
|
2014-07-08 16:22:15 -04:00
|
|
|
// This section has no content and cannot be expanded.
|
2014-06-26 16:17:15 -04:00
|
|
|
if ( section.hasClass( 'cannot-expand' ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-08 16:22:15 -04:00
|
|
|
// Slide into a sub-panel instead of accordioning (Customizer-specific).
|
2014-06-26 16:17:15 -04:00
|
|
|
if ( section.hasClass( 'control-panel' ) ) {
|
|
|
|
panelSwitch( section );
|
2013-02-14 17:58:04 -05:00
|
|
|
return;
|
2014-06-26 16:17:15 -04:00
|
|
|
}
|
2013-02-14 17:58:04 -05:00
|
|
|
|
2013-07-18 13:42:53 -04:00
|
|
|
if ( section.hasClass( 'open' ) ) {
|
|
|
|
section.toggleClass( 'open' );
|
|
|
|
content.toggle( true ).slideToggle( 150 );
|
|
|
|
} else {
|
|
|
|
siblings.removeClass( 'open' );
|
|
|
|
siblings.find( sectionContent ).show().slideUp( 150 );
|
|
|
|
content.toggle( false ).slideToggle( 150 );
|
|
|
|
section.toggleClass( 'open' );
|
|
|
|
}
|
2013-07-12 14:16:29 -04:00
|
|
|
}
|
|
|
|
|
2014-07-08 16:22:15 -04:00
|
|
|
/**
|
|
|
|
* Slide into an accordion sub-panel.
|
|
|
|
*
|
|
|
|
* For the Customizer-specific panel functionality
|
|
|
|
*
|
|
|
|
* @param {Object} panel Title element or back button of the accordion panel to toggle.
|
|
|
|
* @since 4.0.0
|
|
|
|
*/
|
2014-06-26 16:17:15 -04:00
|
|
|
function panelSwitch( panel ) {
|
2014-07-08 16:19:15 -04:00
|
|
|
var position, scroll,
|
2014-06-26 16:17:15 -04:00
|
|
|
section = panel.closest( '.accordion-section' ),
|
2014-07-08 16:19:15 -04:00
|
|
|
overlay = section.closest( '.wp-full-overlay' ),
|
|
|
|
container = section.closest( '.accordion-container' ),
|
|
|
|
siblings = container.find( '.open' ),
|
|
|
|
topPanel = overlay.find( '#customize-theme-controls > ul > .accordion-section > .accordion-section-title' ).add( '#customize-info > .accordion-section-title' ),
|
2014-08-25 19:05:15 -04:00
|
|
|
backBtn = overlay.find( '.control-panel-back' ),
|
2014-07-08 16:19:15 -04:00
|
|
|
panelTitle = section.find( '.accordion-section-title' ).first(),
|
2014-06-26 16:17:15 -04:00
|
|
|
content = section.find( '.control-panel-content' );
|
|
|
|
|
|
|
|
if ( section.hasClass( 'current-panel' ) ) {
|
|
|
|
section.toggleClass( 'current-panel' );
|
2014-07-08 16:19:15 -04:00
|
|
|
overlay.toggleClass( 'in-sub-panel' );
|
2014-06-26 16:17:15 -04:00
|
|
|
content.delay( 180 ).hide( 0, function() {
|
|
|
|
content.css( 'margin-top', 'inherit' ); // Reset
|
|
|
|
} );
|
2014-07-08 16:19:15 -04:00
|
|
|
topPanel.attr( 'tabindex', '0' );
|
|
|
|
backBtn.attr( 'tabindex', '-1' );
|
|
|
|
panelTitle.focus();
|
|
|
|
container.scrollTop( 0 );
|
2014-06-26 16:17:15 -04:00
|
|
|
} else {
|
2014-07-08 16:19:15 -04:00
|
|
|
// Close all open sections in any accordion level.
|
2014-06-26 16:17:15 -04:00
|
|
|
siblings.removeClass( 'open' );
|
2014-07-08 16:19:15 -04:00
|
|
|
siblings.find( sectionContent ).show().slideUp( 0 );
|
2014-06-26 16:17:15 -04:00
|
|
|
content.show( 0, function() {
|
|
|
|
position = content.offset().top;
|
2014-07-08 16:19:15 -04:00
|
|
|
scroll = container.scrollTop();
|
|
|
|
content.css( 'margin-top', ( 45 - position - scroll ) );
|
2014-06-26 16:17:15 -04:00
|
|
|
section.toggleClass( 'current-panel' );
|
2014-07-08 16:19:15 -04:00
|
|
|
overlay.toggleClass( 'in-sub-panel' );
|
|
|
|
container.scrollTop( 0 );
|
2014-06-26 16:17:15 -04:00
|
|
|
} );
|
2014-07-08 16:19:15 -04:00
|
|
|
topPanel.attr( 'tabindex', '-1' );
|
|
|
|
backBtn.attr( 'tabindex', '0' );
|
|
|
|
backBtn.focus();
|
2014-06-26 16:17:15 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-12 14:16:29 -04:00
|
|
|
})(jQuery);
|