Ir al contenido

Diferencia entre revisiones de «MediaWiki:Common.js»

De Wikiviajes, la guía libre de viajes
Contenido eliminado Contenido añadido
ZrbtWm (discusión | contribs.)
no funcionó: desactivo
ZrbtWm (discusión | contribs.)
Según https://es.wikivoyage.org/w/index.php?diff=100800&oldid=100749#Propuesta:_indicar_gu.C3.ADas_destacadas_de_otros_wikiviajes_en_el_.C3.A1rea_de_interwikis
Línea 434: Línea 434:
* por una estrella.
* por una estrella.
* Mantenedores: [[:w:en:User:R. Koot]], editores de interfaz de Wikiviajes en español
* Mantenedores: [[:w:en:User:R. Koot]], editores de interfaz de Wikiviajes en español
*
*/
function LinkFA() {
function LinkFA() {
if ( document.getElementById( 'p-lang' ) ) {
if ( document.getElementById( 'p-lang' ) ) {
Línea 450: Línea 450:
mw.hook( 'wikipage.content' ).add( LinkFA );
mw.hook( 'wikipage.content' ).add( LinkFA );
*/

Revisión del 02:14 1 jun 2014

/* Cualquier código JavaScript escrito aquí se cargará para todos los usuarios en cada carga de página */

//Wikibugs (Herramienta de notificación de errores)
importScript('MediaWiki:Wikibugs.js');

/** WikiMiniAtlas *******************************************************
 *
 *  Description: WikiMiniAtlas is a popup click and drag world map.
 *               This script causes all of our coordinate links to display the WikiMiniAtlas popup button.
 *               The script itself is located on meta because it is used by many projects.
 *               See [[Meta:WikiMiniAtlas]] for more information. 
 *  Maintainers: [[User:Dschwen]]
 */
window.wma_settings = {
    buttonImage: "//upload.wikimedia.org/wikipedia/commons/thumb/9/9a/Erioll_world.svg/15px-Erioll_world.svg.png"
};

if ( $.inArray(mw.config.get('wgAction'), ['edit', 'submit'] ) > -1) {
    /** Fix edit summary prompt for undo  ******************************************
     *  Fixes the fact that the undo function combined with the "no edit summary prompter"
     *  causes problems if leaving the edit summary unchanged.
     *  Added by [[User:Deskana]], code by [[User:Tra]].
     *  See also [[bugzilla:8912]].
     */
    $(document).ready( function () {
        if (document.location.search.indexOf("undo=") != -1 && document.getElementsByName('wpAutoSummary')[0]) {
            document.getElementsByName('wpAutoSummary')[0].value = '1';
        }
    });
 
    /**
     * Caracteres especiales (edittools)
     * Crea (y coloca) el ''combobox'' que permite seleccionar un conjunto determinado de
     * caracteres especiales bajo la caja de edición.
     * Funciona en conjunto con [[MediaWiki:Edittools]] y [[MediaWiki:Edittools.js]].
     * Basado en [[commons:MediaWiki:Edittools.js]].
     */
     importScript('MediaWiki:Edittools.javascript');
 
    //Seguimiento
} else if (mw.config.get('wgPageName') == 'Especial:Seguimiento') {
    mw.loader.load( mw.config.get('wgServer') + mw.config.get('wgScript') +
        '?title=MediaWiki:Common.js/seguimiento.js&action=raw&ctype=text/javascript&smaxage=21600&maxage=86400');
}

/** Collapsible tables *********************************************************
 *
 *  Description: Allows tables to be collapsed, showing only the header. See
 *               [[Wikipedia:NavFrame]].
 *  Maintainers: [[User:R. Koot]]
 */
 
var autoCollapse = 2;
var collapseCaption = "ocultar";
var expandCaption = "mostrar";
 
window.collapseTable = function (tableIndex) {
    var Button = document.getElementById("collapseButton" + tableIndex),
        Table = document.getElementById("collapsibleTable" + tableIndex),
        i;
 
    if (!Table || !Button) {
        return false;
    }
 
    var Rows = Table.rows;
 
    if (Button.firstChild.data == collapseCaption) {
        for (i = 1; i < Rows.length; i++) {
            Rows[i].style.display = "none";
        }
        Button.firstChild.data = expandCaption;
    } else {
        for (i = 1; i < Rows.length; i++) {
            Rows[i].style.display = Rows[0].style.display;
        }
        Button.firstChild.data = collapseCaption;
    }
};
 
function createCollapseButtons() {
    var tableIndex = 0,
        NavigationBoxes = {},
        Tables = document.getElementsByTagName("table"),
        i;
 
    for (i = 0; i < Tables.length; i++) {
        if ( $(Tables[i]).hasClass( 'collapsible' ) ) {
 
            /* only add button and increment count if there is a header row to work with */
            var HeaderRow = Tables[i].getElementsByTagName("tr")[0];
            if (!HeaderRow) {
                continue;
            }
            var Header = HeaderRow.getElementsByTagName("th")[0];
            if (!Header) {
                continue;
            }
 
            NavigationBoxes[tableIndex] = Tables[i];
            Tables[i].setAttribute("id", "collapsibleTable" + tableIndex);
 
            var Button = document.createElement("span");
            var ButtonLink = document.createElement("a");
            var ButtonText = document.createTextNode(collapseCaption);
 
            Button.className = "collapseButton"; //Styles are declared in Common.css
            ButtonLink.style.color = Header.style.color;
            ButtonLink.setAttribute("id", "collapseButton" + tableIndex);
            ButtonLink.setAttribute("href", "#");
            addHandler(ButtonLink, "click", new Function("evt", "collapseTable(" + tableIndex + " ); return killEvt( evt );"));
            ButtonLink.appendChild(ButtonText);
 
            Button.appendChild(document.createTextNode("["));
            Button.appendChild(ButtonLink);
            Button.appendChild(document.createTextNode("]"));
 
            Header.insertBefore(Button, Header.firstChild);
            tableIndex++;
        }
    }
 
    for (i = 0; i < tableIndex; i++) {
        if ( $(NavigationBoxes[i]).hasClass( 'collapsed' ) || (tableIndex >= autoCollapse && $(NavigationBoxes[i]).hasClass( 'autocollapse' ) ) ) {
            window.collapseTable(i);
        } else if ( $(NavigationBoxes[i]).hasClass( 'innercollapse' ) ) {
            var element = NavigationBoxes[i];
            while (element = element.parentNode) {
                if ( $(element).hasClass( 'outercollapse' ) ) {
                    window.collapseTable(i);
                    break;
                }
            }
        }
    }
}
 
$(document).ready(createCollapseButtons);
 
// == Código del plegado/desplegado de plantillas ==
var NavigationBarHide = '[' + collapseCaption + ']';
var NavigationBarShow = '[' + expandCaption + ']';
 
var NavigationBarShowDefault = 0;
 
// shows and hides content and picture (if available) of navigation bars
// Parameters:
//     indexNavigationBar: the index of navigation bar to be toggled
window.toggleNavigationBar = function (indexNavigationBar) {
    var NavToggle = document.getElementById("NavToggle" + indexNavigationBar),
        NavFrame = document.getElementById("NavFrame" + indexNavigationBar),
        NavChild;
 
    if (!NavFrame || !NavToggle) {
        return false;
    }
 
    // if shown now
    if (NavToggle.firstChild.data == NavigationBarHide) {
        for (NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
            if ( $(NavChild).hasClass( 'NavContent' ) || $(NavChild).hasClass( 'NavPic' ) ) {
                NavChild.style.display = 'none';
            }
        }
        NavToggle.firstChild.data = NavigationBarShow;
 
        // if hidden now
    } else if (NavToggle.firstChild.data == NavigationBarShow) {
        for (NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
            if ( $(NavChild).hasClass( 'NavContent' ) || $(NavChild).hasClass( 'NavPic' ) ) {
                NavChild.style.display = 'block';
            }
        }
        NavToggle.firstChild.data = NavigationBarHide;
    }
};
 
// adds show/hide-button to navigation bars
function createNavigationBarToggleButton() {
    var indexNavigationBar = 0,
    // iterate over all < div >-elements 
        divs = document.getElementsByTagName("div"),
        NavFrame,
        NavChild,
        i;
    for (i = 0; NavFrame = divs[i]; i++) {
        // if found a navigation bar
        if ( $(NavFrame).hasClass( 'NavFrame' ) ) {
 
            indexNavigationBar++;
            var NavToggle = document.createElement("a");
            NavToggle.className = 'NavToggle';
            NavToggle.setAttribute('id', 'NavToggle' + indexNavigationBar);
            NavToggle.setAttribute('href', 'javascript:toggleNavigationBar(' + indexNavigationBar + ');');
 
            var isCollapsed = $(NavFrame).hasClass( 'collapsed' );
            /*
             * Check if any children are already hidden.  This loop is here for backwards compatibility:
             * the old way of making NavFrames start out collapsed was to manually add style="display:none"
             * to all the NavPic/NavContent elements.  Since this was bad for accessibility (no way to make
             * the content visible without JavaScript support), the new recommended way is to add the class
             * "collapsed" to the NavFrame itself, just like with collapsible tables.
             */
            for (NavChild = NavFrame.firstChild; NavChild != null && !isCollapsed; NavChild = NavChild.nextSibling) {
                if ( $(NavChild).hasClass( 'NavPic' ) || $(NavChild).hasClass( 'NavContent' ) ) {
                    if (NavChild.style.display == 'none') {
                        isCollapsed = true;
                    }
                }
            }
            if (isCollapsed) {
                for (NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
                    if ( $(NavChild).hasClass( 'NavPic' ) || $(NavChild).hasClass( 'NavContent' ) ) {
                        NavChild.style.display = 'none';
                    }
                }
            }
            var NavToggleText = document.createTextNode(isCollapsed ? NavigationBarShow : NavigationBarHide),
                j;
            NavToggle.appendChild(NavToggleText);
 
            // Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked)
            for (j = 0; j < NavFrame.childNodes.length; j++) {
                if ( $(NavFrame.childNodes[j]).hasClass( 'NavHead' ) ) {
                    NavToggle.style.color = NavFrame.childNodes[j].style.color;
                    NavFrame.childNodes[j].appendChild(NavToggle);
                }
            }
            NavFrame.setAttribute('id', 'NavFrame' + indexNavigationBar);
        }
    }
}
 
$(document).ready(createNavigationBarToggleButton);

/*Pagebanner
/*
* rwdImageMaps jQuery plugin v1.4
*
* Allows image maps to be used in a responsive design by recalculating the area coordinates to match the actual image size on load and window.resize
*
* Copyright (c) 2012 Matt Stow
* https://github.com/stowball/jQuery-rwdImageMaps
* http://mattstow.com
* Licensed under the MIT license
*/
;(function(a){a.fn.rwdImageMaps=function(){var d=this,c=parseFloat(a.fn.jquery);var b=function(){d.each(function(){if(typeof(a(this).attr("usemap"))=="undefined"){return}var f=this,e=a(f);a("<img />").load(function(){var o,k,i="width",n="height";if(c<1.6){o=f.getAttribute(i),k=f.getAttribute(n)}else{o=e.attr(i),k=e.attr(n)}if(!o||!k){var p=new Image();p.src=e.attr("src");if(!o){o=p.width}if(!k){k=p.height}}var g=e.width()/100,l=e.height()/100,j=e.attr("usemap").replace("#",""),m="coords";a('map[name="'+j+'"]').find("area").each(function(){var s=a(this);if(!s.data(m)){s.data(m,s.attr(m))}var r=s.data(m).split(","),q=new Array(r.length);for(var h=0;h<q.length;++h){if(h%2===0){q[h]=parseInt(((r[h]/o)*100)*g)}else{q[h]=parseInt(((r[h]/k)*100)*l)}}s.attr(m,q.toString())})}).attr("src",e.attr("src"))})};a(window).resize(b).trigger("resize");return this}})(jQuery);
 
$(document).ready(function(e) {
    $('img[usemap]').rwdImageMaps();
    $('.banner-box').css('font-size',($('.banner-box').width()*0.03)+'px');
    $('.banner-box').css('line-height',($('.banner-box').width()*0.08)+'px');
});
 
$(window).resize(function(e) {
    $('.banner-box').css('font-size',($('.banner-box').width()*0.03)+'px');
    $('.banner-box').css('line-height',($('.banner-box').width()*0.08)+'px');
});

/* Hide normal page title and move location of geo map symbol when a page has a pagebanner */
$(".topbanner").closest(".mw-body").children(".firstHeading").hide();
$(".topbanner").closest("#mw-content-text").children("#geoCoord").css({top:0});

// Añadir los botones de listados en la barra de herramientas
var customizeToolbar = function() {
$( function() {
             if ( typeof $.fn.wikiEditor != 'undefined' ) {
                   $( '#wpTextbox1' ).wikiEditor( 'removeFromToolbar', {
                          'section': 'main',
                          'group': 'insert',
                          'tool': 'reference'
                   });
             }
        });

$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        'section': 'main',
        'groups': {
                'listings': {
                        'label': 'Listados' // or use labelMsg for a localized label, see above
                }
        }
} );
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        'section': 'main',
        'group': 'listings',
        'tools': {
                'Listings': {
                        label: 'Listado ver', // or use labelMsg for a localized label, see above
                        type: 'button',
                        icon: 'http://upload.wikimedia.org/wikipedia/commons/b/b7/Italian_traffic_signs_-_icona_museo.svg',
                        action: {
                                type: 'encapsulate',
                                options: {
                                        pre: '* {{ver\n| nombre = ',
                                        post: ' | alt = | url = | email = \n| dirección = | lat = | long = | indicaciones = \n| tlf = | tlf_gratuito = | fax = \n| precio = | horario = \n| descripción = \n}}' // text to be inserted
                                }
                        }
                }
        }
} );
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        'section': 'main',
        'group': 'listings',
        'tools': {
                'Listings': {
                        label: 'Listado hacer', // or use labelMsg for a localized label, see above
                        type: 'button',
                        icon: 'http://upload.wikimedia.org/wikipedia/commons/3/30/Pictograms-nps-bicycle_trail-2.svg',
                        action: {
                                type: 'encapsulate',
                                options: {
                                        pre: '* {{hacer\n| nombre = ',
                                        post: ' | alt = | url = | email = \n| dirección = | lat = | long = | indicaciones = \n| tlf = | tlf_gratuito = | fax = \n| precio = | horario = \n| descripción = \n}}' // text to be inserted
                                }
                        }
                }
        }
} );
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        'section': 'main',
        'group': 'listings',
        'tools': {
                'Listings': {
                        label: 'Listado comprar', // or use labelMsg for a localized label, see above
                        type: 'button',
                        icon: 'http://upload.wikimedia.org/wikipedia/commons/a/a1/Italian_traffic_signs_-_icona_supermercato.svg',
                        action: {
                                type: 'encapsulate',
                                options: {
                                        pre: '* {{comprar\n| nombre = ',
                                        post: ' | alt = | url = | email = \n| dirección = | lat = | long = | indicaciones = \n| tlf = | tlf_gratuito = | fax = \n| precio = | horario = \n| descripción = \n}}' // text to be inserted
                                }
                        }
                }
        }
} );
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        'section': 'main',
        'group': 'listings',
        'tools': {
                'Listings': {
                        label: 'Listado comer', // or use labelMsg for a localized label, see above
                        type: 'button',
                        icon: 'http://upload.wikimedia.org/wikipedia/commons/2/2c/Italian_traffic_signs_-_icona_ristorante.svg',
                        action: {
                                type: 'encapsulate',
                                options: {
                                        pre: '* {{comer\n| nombre = ',
                                        post: ' | alt = | url = | email = \n| dirección = | lat = | long = | indicaciones = \n| tlf = | tlf_gratuito = | fax = \n| precio = | horario = \n| descripción = \n}}' // text to be inserted
                                }
                        }
                }
        }
} );
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        'section': 'main',
        'group': 'listings',
        'tools': {
                'Listings': {
                        label: 'Listado beber', // or use labelMsg for a localized label, see above
                        type: 'button',
                        icon: 'http://upload.wikimedia.org/wikipedia/commons/a/a5/Verre_cocktail.svg',
                        action: {
                                type: 'encapsulate',
                                options: {
                                        pre: '* {{beber\n| nombre = ',
                                        post: ' | alt = | url = | email = \n| dirección = | lat = | long = | indicaciones = \n| tlf = | tlf_gratuito = | fax = \n| precio = | horario = \n| descripción = \n}}' // text to be inserted
                                }
                        }
                }
        }
} );
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        'section': 'main',
        'group': 'listings',
        'tools': {
                'Listings': {
                        label: 'Listado dormir', // or use labelMsg for a localized label, see above
                        type: 'button',
                        icon: 'http://upload.wikimedia.org/wikipedia/commons/2/25/Pictograms-nps-lodging.svg',
                        action: {
                                type: 'encapsulate',
                                options: {
                                        pre: '* {{dormir\n| nombre = ',
                                        post: ' | alt = | url = | email = \n| dirección = | lat = | long = | indicaciones = \n| tlf = | tlf_gratuito = | fax = \n| precio = | horario = | hora_entrada = | hora_salida = \n| descripción = \n}}' // text to be inserted
                                }
                        }
                }
        }
} );
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        'section': 'main',
        'group': 'listings',
        'tools': {
                'Listings': {
                        label: 'Otros listados', // or use labelMsg for a localized label, see above
                        type: 'button',
                        icon: 'http://upload.wikimedia.org/wikipedia/commons/7/7e/Italian_traffic_signs_-_icona_informazioni.svg',
                        action: {
                                type: 'encapsulate',
                                options: {
                                        pre: '* {{listado\n| nombre = ',
                                        post: ' | alt = | url = | email = \n| dirección = | lat = | long = | indicaciones = \n| tlf = | tlf_gratuito = | fax = \n| precio = | horario = \n| descripción = \n}}' // text to be inserted
                                }
                        }
                }
        }
} );
};
 
/* Check if view is in edit mode and that the required modules are available. Then, customize the toolbar . . . */
if ( $.inArray( mw.config.get( 'wgAction' ), ['edit', 'submit'] ) !== -1 ) {
        mw.loader.using( 'user.options', function () {
                if ( mw.user.options.get('usebetatoolbar') ) {
                        mw.loader.using( 'ext.wikiEditor.toolbar', function () {
                                $(document).ready( customizeToolbar );
                        } );
                }
        } );
}

// Results from Wikidata
// [[File:Wdsearch_script_screenshot.png]]
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Search' ||  ( mw.config.get( 'wgArticleId' ) === 0 && mw.config.get( 'wgCanonicalSpecialPageName' ) === false ) ) {
	importScriptURI("//en.wikipedia.org/w/index.php?title=MediaWiki:Wdsearch.js&action=raw&ctype=text/javascript");
}

/**
 * Enlaces interwiki a artículos destacados ************************************
 *
 * Descrición: Destaca los enlaces interwiki a artículos destacados (o
 *             equivalentes) cambiando la viñeta antes del enlace interwiki
 *             por una estrella.
 * Mantenedores: [[:w:en:User:R. Koot]], editores de interfaz de Wikiviajes en español
 */
function LinkFA() {
    if ( document.getElementById( 'p-lang' ) ) {
        var InterwikiLinks = document.getElementById( 'p-lang' ).getElementsByTagName( 'li' );
 
        for ( var i = 0; i < InterwikiLinks.length; i++ ) {
            var className = InterwikiLinks[i].className.match(/interwiki-[-\w]+/);
            if ( document.getElementById( className + '-fa' ) ) {
                InterwikiLinks[i].className += ' destacado';
                InterwikiLinks[i].title = 'Esta es una guía destacada en este Wikiviajes.';
            } 
        }
    }
}
 
mw.hook( 'wikipage.content' ).add( LinkFA );