wp/wp-admin/js/accordion.js
changeset 0 d970ebf37754
child 5 5e2f62d02dcd
equal deleted inserted replaced
-1:000000000000 0:d970ebf37754
       
     1 ( function( $ ){
       
     2 
       
     3 	$( document ).ready( function () {
       
     4 
       
     5 		// Expand/Collapse on click
       
     6 		$( '.accordion-container' ).on( 'click keydown', '.accordion-section-title', function( e ) {
       
     7 			if ( e.type === 'keydown' && 13 !== e.which ) // "return" key
       
     8 					return;
       
     9 			e.preventDefault(); // Keep this AFTER the key filter above
       
    10 
       
    11 			accordionSwitch( $( this ) );
       
    12 		});
       
    13 
       
    14 		// Re-initialize accordion when screen options are toggled
       
    15 		$( '.hide-postbox-tog' ).click( function () {
       
    16 			accordionInit();
       
    17 		});
       
    18 
       
    19 	});
       
    20 
       
    21 	var accordionOptions = $( '.accordion-container li.accordion-section' ),
       
    22 		sectionContent   = $( '.accordion-section-content' );
       
    23 
       
    24 	function accordionInit () {
       
    25 		// Rounded corners
       
    26 		accordionOptions.removeClass( 'top bottom' );
       
    27 		accordionOptions.filter( ':visible' ).first().addClass( 'top' );
       
    28 		accordionOptions.filter( ':visible' ).last().addClass( 'bottom' ).find( sectionContent ).addClass( 'bottom' );
       
    29 	}
       
    30 
       
    31 	function accordionSwitch ( el ) {
       
    32 		var section = el.closest( '.accordion-section' ),
       
    33 			siblings = section.closest( '.accordion-container' ).find( '.open' ),
       
    34 			content = section.find( sectionContent );
       
    35 
       
    36 		if ( section.hasClass( 'cannot-expand' ) )
       
    37 			return;
       
    38 
       
    39 		if ( section.hasClass( 'open' ) ) {
       
    40 			section.toggleClass( 'open' );
       
    41 			content.toggle( true ).slideToggle( 150 );
       
    42 		} else {
       
    43 			siblings.removeClass( 'open' );
       
    44 			siblings.find( sectionContent ).show().slideUp( 150 );
       
    45 			content.toggle( false ).slideToggle( 150 );
       
    46 			section.toggleClass( 'open' );
       
    47 		}
       
    48 
       
    49 		accordionInit();
       
    50 	}
       
    51 
       
    52 	// Initialize the accordion (currently just corner fixes)
       
    53 	accordionInit();
       
    54 
       
    55 })(jQuery);