Ticket #27406: 27406.accordion.js-docs.diff
File 27406.accordion.js-docs.diff, 3.5 KB (added by , 10 years ago) |
---|
-
src/wp-admin/js/accordion.js
1 /** 2 * Accordion-folding functionality. 3 * 4 * Markup with the appropriate classes will be automatically hidden, 5 * with one section opening at a time when its title is clicked. 6 * Use the following markup structure for accordion behavior: 7 * 8 * <div class="accordion-container"> 9 * <div class="accordion-section open"> 10 * <h3 class="accordion-section-title"></h3> 11 * <div class="accordion-section-content"> 12 * </div> 13 * </div> 14 * <div class="accordion-section"> 15 * <h3 class="accordion-section-title"></h3> 16 * <div class="accordion-section-content"> 17 * </div> 18 * </div> 19 * <div class="accordion-section"> 20 * <h3 class="accordion-section-title"></h3> 21 * <div class="accordion-section-content"> 22 * </div> 23 * </div> 24 * </div> 25 * 26 * Note that any appropriate tags may be used, as long as the above classes are present. 27 * 28 * In addition to the standard accordion behavior, this file includes JS for the 29 * Customizer's "Panel" functionality. 30 * 31 * @since 3.6.0. 32 */ 33 1 34 ( function( $ ){ 2 35 3 36 $( document ).ready( function () { 4 37 5 // Expand/Collapse on click38 // Expand/Collapse accordion sections on click. 6 39 $( '.accordion-container' ).on( 'click keydown', '.accordion-section-title', function( e ) { 7 40 if ( e.type === 'keydown' && 13 !== e.which ) { // "return" key 8 41 return; … … 13 46 accordionSwitch( $( this ) ); 14 47 }); 15 48 16 // Back to top level49 // Go back to the top-level Customizer accordion. 17 50 $( '.accordion-container' ).on( 'click keydown', '.control-panel-back', function( e ) { 18 51 if ( e.type === 'keydown' && 13 !== e.which ) { // "return" key 19 52 return; … … 23 56 24 57 panelSwitch( $( this ) ); 25 58 }); 26 27 // Re-initialize accordion when screen options are toggled28 $( '.hide-postbox-tog' ).click( function () {29 accordionInit();30 });31 32 59 }); 33 60 34 61 var accordionOptions = $( '.accordion-container li.accordion-section' ), 35 62 sectionContent = $( '.accordion-section-content' ); 36 63 37 function accordionInit () { 38 // Rounded corners 39 accordionOptions.removeClass( 'top bottom' ); 40 accordionOptions.filter( ':visible' ).first().addClass( 'top' ); 41 accordionOptions.filter( ':visible' ).last().addClass( 'bottom' ).find( sectionContent ).addClass( 'bottom' ); 42 } 43 64 /** 65 * Close the current accordion section and open a new one. 66 */ 44 67 function accordionSwitch ( el ) { 45 68 var section = el.closest( '.accordion-section' ), 46 69 siblings = section.closest( '.accordion-container' ).find( '.open' ), 47 70 content = section.find( sectionContent ); 48 71 72 // This section has no content and cannot be expanded. 49 73 if ( section.hasClass( 'cannot-expand' ) ) { 50 74 return; 51 75 } 52 76 77 // Slide into a sub-panel instead of accordioning (Customizer-specific). 53 78 if ( section.hasClass( 'control-panel' ) ) { 54 79 panelSwitch( section ); 55 80 return; … … 64 89 content.toggle( false ).slideToggle( 150 ); 65 90 section.toggleClass( 'open' ); 66 91 } 67 68 accordionInit();69 92 } 70 93 94 /** 95 * Slide into an accordion sub-panel. 96 * 97 * For the Customizer-specific panel functionality 98 */ 71 99 function panelSwitch( panel ) { 72 100 var position, 73 101 section = panel.closest( '.accordion-section' ), … … 92 120 } 93 121 } 94 122 95 // Initialize the accordion (currently just corner fixes)96 accordionInit();97 98 123 })(jQuery);