summaryrefslogtreecommitdiff
path: root/resources/mediawiki.action/mediawiki.action.view.metadata.js
blob: ce3c674b8be5302e81a767743b04bc3fbb4ed5e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
 * 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)
 */
( 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.length ) {
			return;
		}

		$row = $( '<tr class="mw-metadata-show-hide-extended"></tr>' );
		$col = $( '<td colspan="2"></td>' );

		$link = $( '<a>', {
			text: showText,
			href: '#'
		}).click(function () {
			if ( $table.hasClass( 'collapsed' ) ) {
				$( this ).text( hideText );
			} else {
				$( this ).text( showText );
			}
			$table.toggleClass( 'expanded collapsed' );
			return false;
		});

		$col.append( $link );
		$row.append( $col );
		$tbody.append( $row );

		// And collapse!
		$table.addClass( 'collapsed' );
	} );

}( mediaWiki, jQuery ) );