Split /resources into /resources/lib and /resources/src
[lhc/web/wiklou.git] / resources / src / mediawiki.action / mediawiki.action.view.metadata.js
1 /**
2 * Exif metadata display for MediaWiki file uploads
3 *
4 * Add an expand/collapse link and collapse by default if set to
5 * (with JS disabled, user will see all items)
6 *
7 * See also:
8 * - ImagePage.php#makeMetadataTable (creates the HTML)
9 * - skins/common/shared.css (hides tr.collapsable inside table.collapsed)
10 */
11 ( function ( mw, $ ) {
12 $( function () {
13 var $row, $col, $link,
14 showText = mw.msg( 'metadata-expand' ),
15 hideText = mw.msg( 'metadata-collapse' ),
16 $table = $( '#mw_metadata' ),
17 $tbody = $table.find( 'tbody' );
18
19 if ( !$tbody.length || !$tbody.find( '.collapsable' ).length ) {
20 return;
21 }
22
23 $row = $( '<tr class="mw-metadata-show-hide-extended"></tr>' );
24 $col = $( '<td colspan="2"></td>' );
25
26 $link = $( '<a>', {
27 text: showText,
28 href: '#'
29 } ).click( function () {
30 if ( $table.hasClass( 'collapsed' ) ) {
31 $( this ).text( hideText );
32 } else {
33 $( this ).text( showText );
34 }
35 $table.toggleClass( 'expanded collapsed' );
36 return false;
37 } );
38
39 $col.append( $link );
40 $row.append( $col );
41 $tbody.append( $row );
42
43 // And collapse!
44 $table.addClass( 'collapsed' );
45 } );
46
47 }( mediaWiki, jQuery ) );