X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;ds=sidebyside;f=resources%2Fsrc%2Fmediawiki.action%2Fmediawiki.action.view.metadata.js;h=e76ea33ddc68fc4fa08eced143dbe8cb5d2f8daf;hb=6f3d5a5204770b7e9076ec0c956631c32a9e1114;hp=0d000c9ba9947d1b3924dca68c7fe96d32accf55;hpb=a8a5f03b3b6653136c4dc5925d6bb2b806010725;p=lhc%2Fweb%2Fwiklou.git diff --git a/resources/src/mediawiki.action/mediawiki.action.view.metadata.js b/resources/src/mediawiki.action/mediawiki.action.view.metadata.js index 0d000c9ba9..e76ea33ddc 100644 --- a/resources/src/mediawiki.action/mediawiki.action.view.metadata.js +++ b/resources/src/mediawiki.action/mediawiki.action.view.metadata.js @@ -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 = $( '' ); - $col = $( '' ); - - $link = $( '' ) - .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 = $( '' ) + .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( + $( '' ).append( + $( '' ).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 ) ); +}() );