X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/mediawiki.git/blobdiff_plain/19e297c21b10b1b8a3acad5e73fc71dcb35db44a..6932310fd58ebef145fa01eb76edf7150284d8ea:/resources/src/mediawiki.action/mediawiki.action.view.metadata.js diff --git a/resources/src/mediawiki.action/mediawiki.action.view.metadata.js b/resources/src/mediawiki.action/mediawiki.action.view.metadata.js new file mode 100644 index 00000000..0d000c9b --- /dev/null +++ b/resources/src/mediawiki.action/mediawiki.action.view.metadata.js @@ -0,0 +1,52 @@ +/*! + * Exif metadata display for MediaWiki file uploads + * + * Add an expand/collapse link and collapse by default if set to + * (with JS disabled, user will see all items) + * + * See also ImagePage.php#makeMetadataTable (creates the HTML) + */ +( function ( mw, $ ) { + $( function () { + var $row, $col, $link, + showText = mw.msg( 'metadata-expand' ), + hideText = mw.msg( 'metadata-collapse' ), + $table = $( '#mw_metadata' ), + $tbody = $table.find( 'tbody' ); + + if ( !$tbody.find( '.collapsable' ).length ) { + return; + } + + $row = $( '' ); + $col = $( '' ); + + $link = $( '' ) + .text( showText ) + .attr( { + role: 'button', + tabindex: 0 + } ) + .on( 'click keypress', function ( e ) { + if ( + e.type === 'click' || + e.type === 'keypress' && e.which === 13 + ) { + if ( $table.hasClass( 'collapsed' ) ) { + $( this ).text( hideText ); + } else { + $( this ).text( showText ); + } + $table.toggleClass( 'expanded collapsed' ); + } + } ); + + $col.append( $link ); + $row.append( $col ); + $tbody.append( $row ); + + // And collapse! + $table.addClass( 'collapsed' ); + } ); + +}( mediaWiki, jQuery ) );