Snippets/Collapsible Upload options
< Snippets
Collapsible Upload options | |
---|---|
Language(s): | JavaScript |
Compatible with: | MediaWiki 1.17+ (Vector) |
Description
editThis 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
editChange the if clause as follows to make the snippet work in 1.16 too:
if ( wgCanonicalSpecialPageName === 'Upload' ) {
...
}
MediaWiki 1.20
editTry 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.