Diferencia entre revisiones de «MediaWiki:Common.js»

Xstela (discusión | contribs.)
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 );
} );
};


/ Collapsible tables /
$( '#mw-content-text' ).on( 'click', 'table.collapsible .collapsible-button .jslink', function( e ) {
if ( wgIsArticle || window.location.href.indexOf( 'action=submit' ) > -1 )
var $table = $( this ).closest( 'table.collapsible' );
{
  var script  = document.createElement( 'script' );
// Stop table sorting activating when clicking the link
  script.src  = '/index.php?title=MediaWiki:CollapsibleTables.js&action=raw&ctype=text/javascript';
e.stopPropagation();
  script.type = 'text/javascript';
  document.getElementsByTagName( 'head' )[0].appendChild( script );
if ( $table.hasClass( 'collapsed' ) ) {
 
$table.removeClass( 'collapsed' ).addClass( 'expanded' );
  hookEvent( 'load', function()
$( this ).text( mcw.i18n.hideText );
  {
} else {
    new CollapsibleTables();
$table.removeClass( 'expanded' ).addClass( 'collapsed' );
  } );
$( this ).text( mcw.i18n.showText );
}
}
} );
mcw.makeCollapsible();


/**
* Frame parser (for [[Template:Grid]])
*
* Requests the urls for all the animated grids on a page in 2
* API requests (due to a bug, 1 API request when it is fixed)
* and appends them to the correct location.
*/
var baseURL = '/', wikiURL = '/wiki/', $grids = $( '.grid' ), titles = [], titleCount = 0, section = 0;
if ( $grids.length ) {
    $grids.each( function() {
        var imgs = $( this ).data( 'imgs' ), mod = $( this ).data( 'mod' );
        if ( !imgs ) {
            return true;
        }
       
        imgs = imgs.split( ';' );
        imgs.shift();
        $.each( imgs, function() {
            if ( !this.trim() ) {
                return true;
            }
           
            if ( titleCount === 50 ) {
                titleCount = 0;
                section++;
            }
            if ( !titles[section] ) {
                titles[section] = '';
            }
           
            if ( this.indexOf( ':' ) > -1 ) {
                this.replace( /([^:]*):?([^,]*)/, function( $, mod, name ) {
                    if ( mod.trim().toLowerCase() === 'v' || mod.trim().toLowerCase() === 'vanilla' ) {
                        if ( titles[section].indexOf( 'File:Grid ' + name.trim() + '.png' ) < 0 ) {
                            titles[section] += 'File:Grid ' + name.trim() + '.png|';
                            titleCount++;
                        }
                    } else {
                        if ( titles[section].indexOf( 'File:Grid ' + name.trim() + ' (' + mod.trim() + ').png' ) < 0 ) {
                            titles[section] += 'File:Grid ' + name.trim() + ' (' + mod.trim() + ').png|';
                            titleCount++;
                        }
                    }
                } );
            } else {
                this.replace( /([^,]*)/, function( $, name ) {
                    if ( !mod || mod.trim().toLowerCase() === 'v' || mod.trim().toLowerCase() === 'vanilla' ) {
                        if ( titles[section].indexOf( 'File:Grid ' + name.trim() + '.png' ) < 0 ) {
                            titles[section] += 'File:Grid ' + name.trim() + '.png|';
                            titleCount++;
                        }
                    } else {
                        if ( titles[section].indexOf( 'File:Grid ' + name.trim() + ' (' + mod.trim() + ').png' ) < 0 ) {
                            titles[section] += 'File:Grid ' + name.trim() + ' (' + mod.trim() + ').png|';
                            titleCount++;
                        }
                    }
                } );
            }
        } );


/**  
/**