MediaWiki:Common.js

De Wikinoticias, la fuente libre de noticias

Nota: Después de guardar, debes recargar la caché de tu navegador para ver los cambios:

  • Mozilla: Pulsa Recargar (o Ctrl-R)
  • Internet Explorer / Opera: Ctrl-F5
  • Safari: Cmd-R
  • Konqueror Ctrl-R.
/* Enlaces editar a la derecha del título */

function moveEditsection() {
    if (typeof oldEditsectionLinks == 'undefined' || oldEditsectionLinks === false) {
        var spans = document.getElementsByTagName("span");
        for (var i = 0; i < spans.length; i++) {
            if (spans[i].className == "editsection") {
                spans[i].style.fontSize = "x-small";
                spans[i].style.fontWeight = "normal";
                spans[i].style.cssFloat = "none";
                spans[i].style.marginLeft = "0px";
                spans[i].parentNode.appendChild(document.createTextNode(" "));
                spans[i].parentNode.appendChild(spans[i]);
            }
        }
    }
}
// onload
$(moveEditsection);

/* includePage - Local maintainer: Superzerocool */

/** 
* @deprecated just for compatibility 
*/
function includePage(name) {
    importScript(name);
}

includePage('MediaWiki:Tabber.js')

/* 
 * Código del plegado/desplegado de plantillas.
 * Default = 1 lo que significa que por defecto están desplegadas-
 * Si se quiere que estén plegadas por defecto, utilizar Default = 0
 * Si se desea que sea distinto, utilizar id="DontHideNavigationBars"
 * Local maintainer: Jurock 
*/

var NavigationBarHide = '[ ↑ ]';
var NavigationBarShow = '[ ↓ ]';

var NavigationBarShowDefault = 1;

/*
 * Desactivar el botón guardar en la primera vez a los anónimos
 * Copyright Marc Mongenet, 2006 (fr.wikipedia.org)
 * Plyd 05/2007: add "after preview" in the button to prevent misunderstanding from beginners
 * Jurock 10/2008: Traído a es.wikinews
 */

function forcePreview() {
    if (mw.config.get('wgUserName') !== null || mw.config.get('wgAction') != "edit") return;
    saveButton = document.getElementById("wpSave");
    if (!saveButton) return;
    saveButton.disabled = true;
    saveButton.value += " (previsualizar antes)";
    saveButton.style.fontWeight = "normal";
    document.getElementById("wpPreview").style.fontWeight = "bold";
}

$(forcePreview);

/* Código de tab 'opiniones' */

if (!mw.config.get('wgIsMainPage')) importScript( 'Mediawiki:Comments.js' );

/* Twitter/facebook etc. See [[template:Social bookmarks]]
* makes stuff in id="social_bookmarks" open in new window
* and dynamically re-writes links to twitter to shorten urls
*/
var newSmallPopup = function (url) {
    return (function () {
        window.open(url, "_blank", "width=640,height=480,menubar,resizable,scrollbars,status,toolbar");
        return false;
    });
};

$(function () {
    var soc = document.getElementById('social_bookmarks');
    if (soc) {
        var links = soc.getElementsByTagName('a');
        for (i = 0; i < links.length; i++) {
            if (links[i].href.indexOf("http://twitter.com/home/?status") === 0) { /*isTwitter*/
                links[i].href = "http://twitter.com/home/?status=" + encodeURIComponent("Mira esto en Wikinoticias: " + mw.config.get('wgServer') + "/wiki/article?curid=" + mw.config.get('wgArticleId'));
            }
            links[i].onclick = newSmallPopup(links[i].href);
        }
    }
});

/* Vamos evitando el espacio de nombre de Comentarios Discusión (aka 101) */
$(function () { /* Redirecciones */
    if (mw.config.get('wgNamespaceNumber') == 101) location.href = mw.config.get('wgServer') + '/wiki/Comentarios:' + mw.config.get('wgTitle'); /*if (mw.config.get('wgNamespaceNumber') == 6) location.href = mw.config.get('wgServer') + '/wiki/Especial:LoQueEnlazaAquí/Archivo:' + mw.config.get('wgTitle');*/
    /* Ocultando las discusiones */
    if (mw.config.get('wgNamespaceNumber') == 100 || mw.config.get('wgNamespaceNumber') == 6) document.getElementById('ca-talk').style.display = 'none';
    if (mw.config.get('wgNamespaceNumber') == 6) document.getElementById('ca-edit').style.display = 'none';
});

/* Botón que reemplaza la plantilla <nowiki>{{En progreso}}</nowiki> por <nowiki>{{Revisar}}</nowiki> - Local Mantainer: AlvaroMolina */
$(function () {
    var changeDevelopToReviewButton = document.getElementById('develop_to_review_link');
    if (changeDevelopToReviewButton) {
        try {
            //in a try since this makes some assumptions about the format of
            //the <nowiki>{{En progreso}}</nowiki> template, which could change.
            mw.loader.load('//en.wikinews.org/w/index.php?title=User%3ABawolff/mwapilib2.js&action=raw&ctype=text/javascript&scrver=2');
            var button = document.createElement('button');
            button.type = 'button';
            button.appendChild(changeDevelopToReviewButton.firstChild.firstChild);
            changeDevelopToReviewButton.replaceChild(button, changeDevelopToReviewButton.firstChild);
            button.onclick = function () {
                this.disabled = true;
                if (this && this.firstChild && this.firstChild.firstChild && this.firstChild.firstChild.data) this.firstChild.firstChild.data = "Reemplazando Plantilla...";
                api(mw.config.get('wgPageName')).getPage().
                    push().
                    setDefaultSummary("Solicitud de revisión de artículo (usando [[MediaWiki:Common.js|JS Button]])").
                    lift( function( input ) { return !input.match( /\{\{Revisar\}\}/ ); }).
                    abortIfFalse().
                    pop().
                    replace(/\{\{[Ee]n progreso?(?:\|[^}]*)?\}\}(?:\n)?/g, "").
                    replace(/^/, "\{\{Revisar}}\n").
                    savePage().
                    lift(function () {
                        alert("El artículo ha sido marcado para su revisión por un editor/revisor");
                        location.reload();
                    }).
                    exec();
            }
        }
        catch (e) {}
    }
});

/* Botón que reemplaza la plantilla {{Tareas|????}} por <nowiki>{{Revisar}}</nowiki> - Local Mantainer: AlvaroMolina */
$(function () {
    var changeReviewToReviewButton = document.getElementById('Review_to_review_link');
    if (changeReviewToReviewButton) {
        try {
            //in a try since this makes some assumptions about the format of
            //the <nowiki>{{En progreso}}</nowiki> template, which could change.
            mw.loader.load('//en.wikinews.org/w/index.php?title=User%3ABawolff/mwapilib2.js&action=raw&ctype=text/javascript&scrver=2');
            var button = document.createElement('button');
            button.type = 'button';
            button.appendChild(changeReviewToReviewButton.firstChild.firstChild);
            changeReviewToReviewButton.replaceChild(button, changeReviewToReviewButton.firstChild);
            button.onclick = function () {
                this.disabled = true;
                if (this && this.firstChild && this.firstChild.firstChild && this.firstChild.firstChild.data) this.firstChild.firstChild.data = "Reemplazando Plantilla...";
                api(mw.config.get('wgPageName')).getPage().
                    push().
                    setDefaultSummary("Solicitud de revisión de artículo (usando [[MediaWiki:Common.js|JS Button]])").
                    lift( function( input ) { return !input.match( /\{\{Revisar\}\}/ ); }).
                    abortIfFalse().
                    pop().
                    replace(/\{\{[Tt]areas\|([^\}]+)\}\}/g, "\{\{Revisar}}").
                    savePage().
                    lift(function () {
                        alert("El artículo ha sido marcado para su revisión por un editor/revisor");
                        location.reload();
                    }).
                    exec();
            }
        }
        catch (e) {}
    }
});

// MEDIAWIKI IMPORTE AUTOMATIQUEMENT LE CSS ET LE JAVASCRIPT COMMUN POUR UNE PAGE //
 importStylesheet("MediaWiki:Common.css/" + mw.config.get('wgPageName'));
 importScript("MediaWiki:Common.js/" + mw.config.get('wgPageName'));

/**
 * Ajoute la date de dernière modification
 */
function LastModCopy( $ ) {
	// L'id change entre Monobook et Modern d'une part, et Vector d'autre part
	$( '.lastmodcopy' ).html( $( '#lastmod, #footer-info-lastmod' ).html() );
}

// Inicio de Código para TickerSource
importScript( 'MediaWiki:Ticker.js' );
importScript( 'MediaWiki:PageCSS.js' );

//Ticker exportado de ca:wikiqoute
var width = $('.ticker-text').width(),
    containerwidth = $('.ticker-container').width(),
    left = containerwidth;
$(document).ready(function(e){
	function tick() {
        if(--left < -width){
            left = containerwidth;
        }
        $(".ticker-text").css("margin-left", left + "px");
        setTimeout(tick, 8); //El número indica la velocidad (más pequeño, más velocidad)
      }
      tick();
});