summaryrefslogtreecommitdiff
path: root/resources/src/mediawiki.action/mediawiki.action.view.metadata.js
blob: 25b5acc5bc6a991cc441ea940737f2d6d62c1653 (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
44
45
/*!
 * 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.length || !$tbody.find( '.collapsable' ).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 ) );