| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
( function () { |
| 10 |
'use strict'; |
| 11 |
|
| 12 |
$( () => { |
| 13 |
const $tables = $( '.mw_metadata' ); |
| 14 |
if ( !$tables.find( '.mw-metadata-collapsible' ).length ) { |
| 15 |
|
| 16 |
return; |
| 17 |
} |
| 18 |
$tables.each( ( _, table ) => { |
| 19 |
const expandText = mw.msg( 'metadata-expand' ); |
| 20 |
const collapseText = mw.msg( 'metadata-collapse' ); |
| 21 |
const $table = $( table ); |
| 22 |
|
| 23 |
const $link = $( '<a>' ) |
| 24 |
.text( expandText ) |
| 25 |
.attr( { |
| 26 |
role: 'button', |
| 27 |
tabindex: 0 |
| 28 |
} ) |
| 29 |
.on( 'click keypress', ( e ) => { |
| 30 |
if ( |
| 31 |
e.type === 'click' || |
| 32 |
e.type === 'keypress' && e.which === 13 |
| 33 |
) { |
| 34 |
|
| 35 |
if ( $table.hasClass( 'collapsed' ) ) { |
| 36 |
|
| 37 |
$( e.currentTarget ).text( collapseText ); |
| 38 |
} else { |
| 39 |
|
| 40 |
$( e.currentTarget ).text( expandText ); |
| 41 |
} |
| 42 |
|
| 43 |
$table.toggleClass( 'collapsed' ); |
| 44 |
} |
| 45 |
} ); |
| 46 |
|
| 47 |
$table.find( 'tbody' ).append( |
| 48 |
$( '<tr>' ).addClass( 'mw-metadata-show-hide-extended' ).append( |
| 49 |
$( '<td>' ).prop( 'colspan', 2 ).append( $link ) |
| 50 |
) |
| 51 |
); |
| 52 |
} ); |
| 53 |
} ); |
| 54 |
}() ); |