2013-07-12 14:16:29 -04:00
|
|
|
( function( $ ){
|
|
|
|
|
|
|
|
$( document ).ready( function () {
|
|
|
|
|
|
|
|
// Expand/Collapse on click
|
|
|
|
$( '.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-06-26 16:17:15 -04:00
|
|
|
// Back to top level
|
|
|
|
$( '.accordion-container' ).on( 'click keydown', '.control-panel-back', function( e ) {
|
|
|
|
if ( e.type === 'keydown' && 13 !== e.which ) { // "return" key
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
e.preventDefault(); // Keep this AFTER the key filter above
|
|
|
|
|
|
|
|
panelSwitch( $( this ) );
|
|
|
|
});
|
|
|
|
|
2013-07-18 13:42:53 -04:00
|
|
|
// Re-initialize accordion when screen options are toggled
|
2013-07-12 14:16:29 -04:00
|
|
|
$( '.hide-postbox-tog' ).click( function () {
|
|
|
|
accordionInit();
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
var accordionOptions = $( '.accordion-container li.accordion-section' ),
|
|
|
|
sectionContent = $( '.accordion-section-content' );
|
|
|
|
|
2013-07-18 13:42:53 -04:00
|
|
|
function accordionInit () {
|
|
|
|
// Rounded corners
|
2013-07-12 14:16:29 -04:00
|
|
|
accordionOptions.removeClass( 'top bottom' );
|
|
|
|
accordionOptions.filter( ':visible' ).first().addClass( 'top' );
|
2013-07-18 13:42:53 -04:00
|
|
|
accordionOptions.filter( ':visible' ).last().addClass( 'bottom' ).find( sectionContent ).addClass( 'bottom' );
|
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-06-26 16:17:15 -04:00
|
|
|
if ( section.hasClass( 'cannot-expand' ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
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' );
|
|
|
|
}
|
|
|
|
|
|
|
|
accordionInit();
|
2013-07-12 14:16:29 -04:00
|
|
|
}
|
|
|
|
|
2014-06-26 16:17:15 -04:00
|
|
|
function panelSwitch( panel ) {
|
|
|
|
var position,
|
|
|
|
section = panel.closest( '.accordion-section' ),
|
|
|
|
container = section.closest( '.wp-full-overlay' ),
|
|
|
|
siblings = container.find( '.accordion-section.open' ),
|
|
|
|
content = section.find( '.control-panel-content' );
|
|
|
|
|
|
|
|
if ( section.hasClass( 'current-panel' ) ) {
|
|
|
|
section.toggleClass( 'current-panel' );
|
|
|
|
container.toggleClass( 'in-sub-panel' );
|
|
|
|
content.delay( 180 ).hide( 0, function() {
|
|
|
|
content.css( 'margin-top', 'inherit' ); // Reset
|
|
|
|
} );
|
|
|
|
} else {
|
|
|
|
siblings.removeClass( 'open' );
|
|
|
|
content.show( 0, function() {
|
|
|
|
position = content.offset().top;
|
|
|
|
content.css( 'margin-top', ( 45 - position ) );
|
|
|
|
section.toggleClass( 'current-panel' );
|
|
|
|
container.toggleClass( 'in-sub-panel' );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-18 13:42:53 -04:00
|
|
|
// Initialize the accordion (currently just corner fixes)
|
2013-07-12 14:16:29 -04:00
|
|
|
accordionInit();
|
|
|
|
|
|
|
|
})(jQuery);
|