Diferencia entre revisiones de «MediaWiki:Common.js»
Sin resumen de edición |
Sin resumen de edición |
||
| (No se muestran 9 ediciones intermedias de 2 usuarios) | |||
| Línea 18: | Línea 18: | ||
mcw.baseURL = '/'; | mcw.baseURL = '/'; | ||
mcw.wikiURL = '/'; | mcw.wikiURL = '/'; | ||
/* Variables for interface text used throughout the script, for ease of translating */ | |||
mcw.i18n = { | |||
// Collapsible tables and page loader | |||
hideText: 'ocultar', | |||
showText: 'mostrar', | |||
// Page loader | // Page loader | ||
| Línea 40: | Línea 47: | ||
* Based on http://www.mediawiki.org/wiki/Manual:Collapsible_tables#Common.js_script_.28before_1.18.29 | * Based on http://www.mediawiki.org/wiki/Manual:Collapsible_tables#Common.js_script_.28before_1.18.29 | ||
*/ | */ | ||
mcw.makeCollapsible = function( $content ) { | |||
if ( $content === undefined ) { | |||
$content = $( 'table.collapsible' ); | |||
} else { | |||
$content = $content.find( 'table.collapsible' ); | |||
} | |||
if ( !$content.length ) { | |||
return false; | |||
} | |||
var buttonText = ' <span class="collapsible-button">[<span class="jslink">' + mcw.i18n.hideText + '</span>]</span> '; | |||
$content.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)' ).text().replace( /\n/g, '' ).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 ); | |||
} ); | |||
}; | |||
$( '#mw-content-text' ).on( 'click', 'table.collapsible .collapsible-button .jslink', 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 ); | |||
} | |||
} ); | |||
mcw.makeCollapsible(); | |||
/** | /** | ||