2 * Exif metadata display for MediaWiki file uploads
4 * Add an expand/collapse link and collapse by default if set to
5 * (with JS disabled, user will see all items)
7 * See also ImagePage.php#makeMetadataTable (creates the HTML)
13 const $tables = $( '.mw_metadata' );
14 if ( !$tables.find( '.mw-metadata-collapsible' ).length ) {
15 // No collapsible rows present on this page
18 $tables.each( ( _, table ) => {
19 const expandText = mw.msg( 'metadata-expand' );
20 const collapseText = mw.msg( 'metadata-collapse' );
21 const $table = $( table );
23 const $link = $( '<a>' )
29 .on( 'click keypress', ( e ) => {
32 e.type === 'keypress' && e.which === 13
34 // eslint-disable-next-line no-jquery/no-class-state
35 if ( $table.hasClass( 'collapsed' ) ) {
36 // From collapsed to expanded. Button will now collapse.
37 $( e.currentTarget ).text( collapseText );
39 // From expanded to collapsed. Button will now expand.
40 $( e.currentTarget ).text( expandText );
42 // eslint-disable-next-line no-jquery/no-class-state
43 $table.toggleClass( 'collapsed' );
47 $table.find( 'tbody' ).append(
48 $( '<tr>' ).addClass( 'mw-metadata-show-hide-extended' ).append(
49 $( '<td>' ).prop( 'colspan', 2 ).append( $link )