X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=resources%2Fsrc%2Fmediawiki.action%2Fmediawiki.action.view.metadata.js;h=bbe3032fc53d73844380dd8149a348b319da0aec;hb=3844fd9d639ed67cd3519eab2d7db440100cdd26;hp=a3a82d51a6bc57dafaecee061baf6d772240e54c;hpb=f43fa6f4f0e2cb60b8543daad661b48a3e0653a9;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 a3a82d51a6..bbe3032fc5 100644 --- a/resources/src/mediawiki.action/mediawiki.action.view.metadata.js +++ b/resources/src/mediawiki.action/mediawiki.action.view.metadata.js @@ -8,45 +8,50 @@ */ ( 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.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( 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' ); + } + } ); - $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 ); - } - $table.toggleClass( 'expanded collapsed' ); - } + $table.find( 'tbody' ).append( + $( '' ).append( + $( '' ).append( $link ) + ) + ); } ); - $col.append( $link ); - $row.append( $col ); - $tbody.append( $row ); - - // 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 ) );