/** * Collapsible tables * * Based on http://www.mediawiki.org/wiki/Manual:Collapsible_tables#Common.js_script_.28before_1.18.29 */( function() { var $tables = $content.find( 'table.collapsible' ); if ( !$tables || !$tables.length ) { return false; } var buttonText = ' <span class="collapsible-button">[<span class="jslink">' + mcw.i18n.hideText + '</span>]</span> '; $tables.each( function() { var $table = $( this ), $header, $collapseButton, firstWidth, secondWidth; // This table is already collapsible if ( $table.data( 'collapsible' ) ) { return true; } // Use the collapse-button if specified otherwise the first header cell of the first row $header = $table.find( 'tr:first .collapse-button' ); if ( !$header.length ) { $header = $table.find( 'tr:first > th:first' ); } // No header or the table body is empty if ( !$header.length || !$table.find( 'tr:not(tr:first)' ).html().trim().length ) { return true; } // For the button to float properly, it has to be /before/ the cell text if ( $table.hasClass( 'collapse-button-none' ) ) { $header.append( buttonText ); } else { $header.prepend( buttonText ); } // Find max button size, and set its min-width to it $collapseButton = $table.find( '.collapsible-button' ); firstWidth = $collapseButton.width(); $collapseButton.find( '> .jslink' ).text( mcw.i18n.showText ); secondWidth = $collapseButton.width(); if ( firstWidth != secondWidth ) { if ( firstWidth < secondWidth ) { $collapseButton.css( 'min-width', secondWidth ); } else { $collapseButton.css( 'min-width', firstWidth ); } } // Set the text back to hide if it's not collapsed to begin with if ( !$table.hasClass( 'collapsed' ) ) { $collapseButton.find( '> .jslink' ).text( mcw.i18n.hideText ); } $table.data( 'collapsible', true ); } ); // This is bound directly because sortable tables don't play nice $tables.find( '.collapsible-button .jslink' ).click( function( e ) { var $table = $( this ).closest( 'table.collapsible' ); // Stop table sorting activating when clicking the link e.stopPropagation(); if ( $table.hasClass( 'collapsed' ) ) { $table.removeClass( 'collapsed' ).addClass( 'expanded' ); $( this ).text( mcw.i18n.hideText ); } else { $table.removeClass( 'expanded' ).addClass( 'collapsed' ); $( this ).text( mcw.i18n.showText ); } } );}() );