Merge "user: Allow "CAS update failed" exceptions to be normalised"
[lhc/web/wiklou.git] / resources / src / mediawiki.action / mediawiki.action.view.metadata.js
index 0d000c9..e76ea33 100644 (file)
@@ -6,47 +6,52 @@
  *
  * See also ImagePage.php#makeMetadataTable (creates the HTML)
  */
-( function ( mw, $ ) {
+( function () {
        $( 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 ) {
+               var $tables = $( '.mw_metadata' );
+               if ( !$tables.find( '.mw-metadata-collapsible, .collapsable' ).length ) {
+                       // No collapsible rows present on this page
                        return;
                }
+               $tables.each( function () {
+                       var $link,
+                               expandText = mw.msg( 'metadata-expand' ),
+                               collapseText = mw.msg( 'metadata-collapse' ),
+                               $table = $( this );
 
-               $row = $( '<tr class="mw-metadata-show-hide-extended"></tr>' );
-               $col = $( '<td colspan="2"></td>' );
-
-               $link = $( '<a>' )
-                       .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 );
+                       $link = $( '<a>' )
+                               .text( expandText )
+                               .attr( {
+                                       role: 'button',
+                                       tabindex: 0
+                               } )
+                               .on( 'click keypress', function ( e ) {
+                                       if (
+                                               e.type === 'click' ||
+                                               e.type === 'keypress' && e.which === 13
+                                       ) {
+                                               if ( $table.hasClass( 'collapsed' ) ) {
+                                                       // From collapsed to expanded. Button will now collapse.
+                                                       $( this ).text( collapseText );
+                                               } else {
+                                                       // From expanded to collapsed. Button will now expand.
+                                                       $( this ).text( expandText );
+                                               }
+                                               $table.toggleClass( 'collapsed' );
                                        }
-                                       $table.toggleClass( 'expanded collapsed' );
-                               }
-                       } );
+                               } );
 
-               $col.append( $link );
-               $row.append( $col );
-               $tbody.append( $row );
+                       $table.find( 'tbody' ).append(
+                               $( '<tr class="mw-metadata-show-hide-extended"></tr>' ).append(
+                                       $( '<td colspan="2"></td>' ).append( $link )
+                               )
+                       );
+               } );
 
-               // And collapse!
-               $table.addClass( 'collapsed' );
+               // Initial collapsed state
+               // (For back-compat with cached HTML from before ImagePage.php
+               // did this by default)
+               $tables.addClass( 'collapsed' );
        } );
 
-}( mediaWiki, jQuery ) );
+}() );