Snippets/Collapsible Upload options

From mediawiki.org
How to use Snippets
List of Snippets
Collapsible Upload options
Language(s): JavaScript
Compatible with: MediaWiki 1.17+ (Vector)

Description[edit]

This snippet will make the description and options fieldsets on the file upload page collapsible. They are collapsed by default as most users won't use them anyway.

Code[edit]

/**
 * Make file upload description and options collapsible
 *
 * @source: https://www.mediawiki.org/wiki/Snippets/Collapsible_Upload_options
 * @rev: 1
 */
if ( $.inArray( mw.config.get( 'wgCanonicalSpecialPageName' ), ['Upload']) != -1 ) {
 
    $( 'legend:nth(1)' ).wrapInner( '<a href="#" />' )
        .click( function( e ) {
            e.preventDefault(); // avoid jumping to the top (href=#)
            $( '#mw-htmlform-description' ).toggle( 'fast' );
        } )
    $( '#mw-htmlform-description' ).delay( 500 ).hide( 'slow' );  // Hide by default, but delayed for to give other elements time to expand first

    $( 'legend:nth(2)' ).wrapInner( '<a href="#" />' )
        .click( function( e ) {
            e.preventDefault(); // avoid jumping to the top (href=#)
            $( '#mw-htmlform-options' ).toggle( 'fast' );
        } )
    $( '#mw-htmlform-options' ).hide( );  // Hide by default
}

MediaWiki 1.16[edit]

Change the if clause as follows to make the snippet work in 1.16 too:

if ( wgCanonicalSpecialPageName === 'Upload' ) {
    ...
}


MediaWiki 1.20[edit]

Try wrapping the code in

( function( $ ) { 
        // Simple scope wrap, where $ is available as alias for jQuery.
        // Code here will be executed immediately
} )( jQuery );

as recommended at JQuery.