X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/61343b82c4f0da4c68e4c6373daafff4a81efdd1..c46e6dd20c438dddfea40c35935b877ac3e67daa:/wp-admin/js/accordion.js diff --git a/wp-admin/js/accordion.js b/wp-admin/js/accordion.js index 7bc99ccc..1769d27d 100644 --- a/wp-admin/js/accordion.js +++ b/wp-admin/js/accordion.js @@ -1,55 +1,75 @@ +/** + * 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: + * + *
+ *
+ *

+ *
+ *
+ *
+ *
+ *

+ *
+ *
+ *
+ *
+ *

+ *
+ *
+ *
+ *
+ * + * 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 on click + // 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; + if ( e.type === 'keydown' && 13 !== e.which ) { // "return" key + return; + } + e.preventDefault(); // Keep this AFTER the key filter above accordionSwitch( $( this ) ); }); - // Re-initialize accordion when screen options are toggled - $( '.hide-postbox-tog' ).click( function () { - accordionInit(); - }); - }); - var accordionOptions = $( '.accordion-container li.accordion-section' ), - sectionContent = $( '.accordion-section-content' ); - - function accordionInit () { - // Rounded corners - accordionOptions.removeClass( 'top bottom' ); - accordionOptions.filter( ':visible' ).first().addClass( 'top' ); - accordionOptions.filter( ':visible' ).last().addClass( 'bottom' ).find( sectionContent ).addClass( 'bottom' ); - } - + /** + * 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( sectionContent ); + content = section.find( '.accordion-section-content' ); - if ( section.hasClass( 'cannot-expand' ) ) + // 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( sectionContent ).show().slideUp( 150 ); + siblings.find( '.accordion-section-content' ).show().slideUp( 150 ); content.toggle( false ).slideToggle( 150 ); section.toggleClass( 'open' ); } - - accordionInit(); } - // Initialize the accordion (currently just corner fixes) - accordionInit(); - })(jQuery);