MediaWiki:Common.js

De Català a Cort
Dreceres ràpides: navegació, cerca

Nota: Després de desar, possiblement necessitareu refrescar la memòria cau del vostre navegador per a veure'n els canvis.

  • Firefox / Safari: Premeu Shift i alhora cliqueu el botó Actualitza, o pressioneu Ctrl+F5 o Ctrl+R (⌘+R en un Mac)
  • Google Chrome: Premeu Ctrl+Shift+R (⌘+Shift+R en un Mac)
  • Internet Explorer: Premeu Ctrl i alhora cliqueu a Actualitza o pressioneu Ctrl+F5
  • Opera: Aneu a Menú → Preferències (Opera → Preferències en un Mac) i llavors a Privadesa i seguretat → Neteja dades de navegació → Imatges i fitxers en memòria cau.
/**
 * Keep code in MediaWiki:Common.js to a minimum as it is unconditionally
 * loaded for all users on every wiki page. If possible create a gadget that is
 * enabled by default instead of adding it here (since gadgets are fully
 * optimized ResourceLoader modules with possibility to add dependencies etc.)
 *
 * Since Common.js isn't a gadget, there is no place to declare its
 * dependencies, so we have to lazy load them with mw.loader.using on demand and
 * then execute the rest in the callback. In most cases these dependencies will
 * be loaded (or loading) already and the callback will not be delayed. In case a
 * dependency hasn't arrived yet it'll make sure those are loaded before this.
 */
 
/*global mw, $, importScript*/

mw.loader.using( ['mediawiki.user', 'mediawiki.util', 'mediawiki.notify', 'jquery.client'] ).done( function () {
/* Begin of mw.loader.using callback */

/* Workaround pel sitenotice, per Toniher, modificat per Joancreus */
/**
 $(window).load(function(){
 setTimeout(function (){
  $("#wlm-banner a").attr("href", "http://www.wikilovesmonuments.cat");
 },400);
 $(document).on("click","#wlm-banner a",function () {
    if($(this).attr("href") != "http://www.wikilovesmonuments.cat") {
        $(this).attr("href", "http://www.wikilovesmonuments.cat");
    }
 });
});
*/

 /*HERE STARTS THE WORKING-CODE OF "METABOXES"*/

 /* Funcionament de la Plantilla:Metacaixa
 Implementat per: Usuari:Peleguer.
 Actualitzat per Joanjoc seguint les indicacions d'en Martorell
 */

 function MetaCaixaInit(){
  //S'executa al carregar-se la pàgina, si hi ha metacaixes,
  // s'assignen els esdeveniments als botons
  //alert("MetaCaixaInit");
  
  var i=0;       //Inicialitzem comptador de caixes
  for (i=0;i<=9;i++){
     var vMc = document.getElementById("mc"+i);
     if (!vMc) break;
     //alert("MetaCaixaInit, trobada Metacaixa mc"+i);
     
     var j=1;    //Inicialitzem comptador de botons dins de la caixa
     var vPsIni = 0;  //Pestanya visible inicial
     for (j=1;j<=9;j++){
        var vBt = document.getElementById("mc"+i+"bt"+j);
        if (!vBt) break;
        //alert("MetaCaixaInit, trobat botó mc"+i+"bt"+j);
        vBt.onclick = MetaCaixaMostraPestanya;          //A cada botó assignem l'esdeveniment onclick
        //alert (vBt.className);
        if (vBt.className=="mcBotoSel") vPsIni=j;  //Si tenim un botó seleccionat, en guardem l'index
     }
     //alert ("mc="+i+", ps="+j+", psini="+vPsIni );
     if (vPsIni === 0) { //Si no tenim cap botó seleccionat, n'agafem un aleatòriament
         vPsIni = 1+Math.floor((j-1)*Math.random()) ;
         //alert ("Activant Pestanya a l'atzar; _mc"+i+"bt"+vPsIni +"_");
         document.getElementById("mc"+i+"ps"+vPsIni).style.display = "block";
         document.getElementById("mc"+i+"ps"+vPsIni).style.visibility = "visible";
         document.getElementById("mc"+i+"bt"+vPsIni).className="mcBotoSel";
     } 
  }
 }
   
 function MetaCaixaMostraPestanya(){
  //S'executa al clicar una pestanya,
  //aquella es fa visible i les altres s'oculten
  var vMcNom = this.id.substr(0,3); //A partir del nom del botó, deduïm el nom de la caixa
  var vIndex = this.id.substr(5,1); //I l'index
  
  var i=1;
  for (i=1;i<=9;i++){        //busquem totes les pestanyes d'aquella caixa
      //alert(vMcNom+"ps"+i);
        var vPsElem = document.getElementById(vMcNom+"ps"+i);
        if (!vPsElem) break;
        if (vIndex==i){ //Si és la pestanya bona la mostrem i canviem la classe de botó
                vPsElem.style.display = "block";
                vPsElem.style.visibility = "visible";
                document.getElementById(vMcNom+"bt"+i).className="mcBotoSel";
        } else {             //Sinó, l'ocultem i canviem la classe de botó
                vPsElem.style.display = "none";
                vPsElem.style.visibility = "hidden";
                document.getElementById(vMcNom+"bt"+i).className="mcBoto";
        }
  }
  return false; //evitem la recàrrega de la pàgina
 }
 
 $( MetaCaixaInit );

 /*HERE FINISHES THE WORKING-CODE OF "METABOXES"*/

 function AvisAdminsVand()
 {
    var url_name = '//ca.wikipedia.org/w/index.php?alertavandalisme=esclar';
    var page_name = document.URL;
    var index = page_name.indexOf(url_name);
    if (index == -1)
        return;
    var text_area = document.editform.wpTextbox1;
      var comment = "Atenció! Passa\'t per la pàgina de [[Especial:Recentchanges|canvis recents]] per a jutjar alguns canvis que poden ésser considerats com a [[Viquipèdia:vandalisme|vandalisme]].--~~"+"~~";
      text_area.value = comment;
    document.editform.wpSummary.value="Avís de vandalisme en curs!!!";
 }

 $( AvisAdminsVand );

/**
 * Enllaç de càrrega per defecte a la pàgina d'ajuda
 * Amb els ginys es pot eliminar i es pot afegir també un enllaç a Commons
 */
var LienUpload = function () {
  var uploadLink = document.getElementById("t-upload");
  if (!uploadLink) return;
 
  var a = uploadLink.firstChild;
  a.setAttribute('href', '/wiki/Ajuda:Carregar_un_fitxer');
};
$(LienUpload);

//**************************************************************
// Permet configurar el joc de caràcters especials.
// Adaptat de la versió anglesa
// per ca:Usuari:Martorell, segona versió per ca:Usuari:Pasqual
//
// Afegida possibilitat de personalització (Vegeu [[Viquipèdia:Scripts]])
// per ca:Usuari:Joanjoc
//**************************************************************

function addCharSubsetMenu()
{
   addCharSubsetMenuVar(0);
}

/* Afegeix un menu per a seleccionar subconjunts de caràcters especials */
/***** ha d'avenir-se amb MediaWiki:Edittools *****/
function chooseCharSubset(s) {
  var l = document.getElementById('specialchars').getElementsByTagName('p');
  for (var i = 0; i < l.length ; i++) {
    l[i].style.display = i == s ? 'inline' : 'none';
    l[i].style.visibility = i == s ? 'visible' : 'hidden';
  }
}

function addCharSubsetMenuVar(s) {
  var copywarn = document.getElementById('specialchars');

  if (copywarn) {
    var aIdx = [];
    aIdx[s] = "selected=\"selected\"";
 
    var menu = "<span style=\"margin-top:1px 1px 1px 1px;border-width:1px;border-style:solid;border-color:#aaaaaa;padding:2px 2px 2px 2px;font-size:x-small;position:relative;\"><select id=\"charsetBox\" style=\"display:inline\" onChange=\"chooseCharSubset(selectedIndex)\">";
    menu += "<option "+aIdx[0]+">matemàtiques</option>";
    menu += "<option "+aIdx[1]+">fonètica</option>";
    menu += "<option "+aIdx[2]+">diacrítiques</option>";
    menu += "<option "+aIdx[3]+">ciríl·lic</option>";
    menu += "<option "+aIdx[4]+">alemany</option>";
    menu += "<option "+aIdx[5]+">alt alemany antic</option>";
    menu += "<option "+aIdx[6]+">anglés antic</option>";
    menu += "<option "+aIdx[7]+">àrab</option>";
    menu += "<option "+aIdx[8]+">berber</option>";
    menu += "<option "+aIdx[9]+">bosni/serbocroata</option>";
    menu += "<option "+aIdx[10]+">castellà</option>";
    menu += "<option "+aIdx[11]+">escandinau</option>";
    menu += "<option "+aIdx[12]+">eslovac</option>";
    menu += "<option "+aIdx[13]+">esperanto</option>";
    menu += "<option "+aIdx[14]+">estonià</option>";
    menu += "<option "+aIdx[15]+">francés</option>";
    menu += "<option "+aIdx[16]+">gal·lés</option>";
    menu += "<option "+aIdx[17]+">grec</option>";
    menu += "<option "+aIdx[18]+">grec antic</option>";
    menu += "<option "+aIdx[19]+">hawaià</option>";
    menu += "<option "+aIdx[20]+">hebreu</option>";
    menu += "<option "+aIdx[21]+">holandés</option>";
    menu += "<option "+aIdx[22]+">hongarés</option>";
    menu += "<option "+aIdx[23]+">indoeuropeu</option>";
    menu += "<option "+aIdx[24]+">irlandés</option>";
    menu += "<option "+aIdx[25]+">islandés</option>";
    menu += "<option "+aIdx[26]+">italià</option>";
    menu += "<option "+aIdx[27]+">japonés (romanji)</option>";
    menu += "<option "+aIdx[28]+">jiddisch</option>";
    menu += "<option "+aIdx[29]+">letó</option>";
    menu += "<option "+aIdx[30]+">lituà</option>";
    menu += "<option "+aIdx[31]+">maltés</option>";
    menu += "<option "+aIdx[32]+">navajo i apatxe</option>";
    menu += "<option "+aIdx[33]+">pinyin</option>";
    menu += "<option "+aIdx[34]+">polonés</option>";
    menu += "<option "+aIdx[35]+">portugués</option>";
    menu += "<option "+aIdx[36]+">romanés</option>";
    menu += "<option "+aIdx[37]+">serbi</option>";
    menu += "<option "+aIdx[38]+">turc i ll. turqueses</option>";
    menu += "<option "+aIdx[39]+">txec</option>";
    menu += "<option "+aIdx[40]+">vietnamita</option>";
    menu += "</select></span>";
    copywarn.innerHTML = menu + copywarn.innerHTML;

    chooseCharSubset(s);
  }
}

$( addCharSubsetMenu );

/**
 * 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]]
 */
( function () {
    var require_wikiminiatlas = false;
    var coord_filter = /geohack/;
    $( function() {
        $( 'a.external.text' ).each( function( key, link ) {
            if ( link.href && coord_filter.exec( link.href ) ) {
                require_wikiminiatlas = true;
                // break from loop
                return false;
            }
        } );
        if ( $( 'div.kmldata' ).length ) {
            require_wikiminiatlas = true;
        }
        if ( require_wikiminiatlas ) {
            mw.loader.load('//meta.wikimedia.org/w/index.php?title=MediaWiki:Wikiminiatlas.js&action=raw&ctype=text/javascript');
        }
    } );
} )();

/***** OpenStreetMap *****
 * vegeu Ajuda:OpenStreetMap
 */
mw.config.set( 'osm_proj_map', 'mapa' ); //"map" in project language
mw.config.set( 'osm_proj_lang', 'ca' ); //project language
mw.loader.load('//meta.wikimedia.org/w/index.php?title=MediaWiki:OSM.js&action=raw&ctype=text/javascript');

/**
 * Collapsible tables *********************************************************
 * https://en.wikipedia.org/w/index.php?title=MediaWiki:Common.js&oldid=554529999
 * Description: Allows tables to be collapsed, showing only the header. See
 *              [[Wikipedia:NavFrame]].
 * Maintainers: [[User:R. Koot]]
 */

var autoCollapse = 2;
var collapseCaption = 'amaga';
var expandCaption = 'mostra';

window.collapseTable = function ( tableIndex ) {
    var Button = document.getElementById( 'collapseButton' + tableIndex );
    var Table = document.getElementById( 'collapsibleTable' + tableIndex );

    if ( !Table || !Button ) {
        return false;
    }

    var Rows = Table.rows;
    var i;

    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;
    var NavigationBoxes = {};
    var Tables = document.getElementsByTagName( 'table' );
    var i;

    function handleButtonLink( index, e ) {
        window.collapseTable( index );
        e.preventDefault();
    }

    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', '#' );
            $( ButtonLink ).on( 'click', $.proxy( handleButtonLink, ButtonLink, tableIndex ) );
            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;
                }
            }
        }
    }
}

$( createCollapseButtons );

/**
 * Dynamic Navigation Bars (experimental)
 * https://en.wikipedia.org/w/index.php?title=MediaWiki:Common.js&oldid=554529999
 * Description: See [[Wikipedia:NavFrame]].
 * Maintainers: UNMAINTAINED
 */

/* set up the words in your language */
var NavigationBarHide = '[' + collapseCaption + ']';
var NavigationBarShow = '[' + expandCaption + ']';

/**
 * 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, event ) {
    var NavToggle = document.getElementById( 'NavToggle' + indexNavigationBar );
    var NavFrame = document.getElementById( 'NavFrame' + indexNavigationBar );
    var 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;
    }

    event.preventDefault();
};

/* adds show/hide-button to navigation bars */
function createNavigationBarToggleButton() {
    var indexNavigationBar = 0;
    var NavFrame;
    var NavChild;
    /* iterate over all < div >-elements */
    var divs = document.getElementsByTagName( 'div' );
    for ( var 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', '#' );
            $( NavToggle ).on( 'click', $.proxy( window.toggleNavigationBar, window, 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 );
            NavToggle.appendChild( NavToggleText );

            /* Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked) */
            for( var 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 );
        }
    }
}

$( createNavigationBarToggleButton );

/**
 * Diverses fonctions manipulant les classes
 * Utilise des expressions régulières et un cache pour de meilleures perfs
 * isClass et whichClass depuis http://fr.wikibooks.org/w/index.php?title=MediaWiki:Common.js&oldid=140211
 * hasClass, addClass, removeClass et eregReplace depuis http://drupal.org.in/doc/misc/drupal.js.source.html
 * surveiller l'implémentation de .classList http://www.w3.org/TR/2008/WD-html5-diff-20080122/#htmlelement-extensions
 */
function isClass(element, classe) {
    return hasClass(element, classe);
}
 
function whichClass(element, classes) {
    var s=" "+element.className+" ";
    for(var i=0;i<classes.length;i++)
        if (s.indexOf(" "+classes[i]+" ")>=0) return i;
    return -1;
}
 
function hasClass(node, className) {
  if (node.className == className) {
    return true;
  }
  var reg = new RegExp('(^| )'+ className +'($| )');
  if (reg.test(node.className)) {
    return true;
  }
  return false;
}
 
function addClass(node, className) {
    if (hasClass(node, className)) {
        return false;
    }
    node.className += ' '+ className;
    return true;
}
 
function removeClass(node, className) {
  if (!hasClass(node, className)) {
    return false;
  }
  node.className = eregReplace('(^|\\s+)'+ className +'($|\\s+)', ' ', node.className);
  return true;
}
 
function eregReplace(search, replace, subject) {
    return subject.replace(new RegExp(search,'g'), replace);
}
 
/** 
 * Test if an element has a certain class
 *
 * @deprecated:  Use $(element).hasClass() instead.
 */
mw.log.deprecate( window, 'hasClass', function ( element, className ) {
	return $( element ).hasClass( className );
}, 'Use jQuery.hasClass() instead' );

/**
 * Interwiki links to featured articles ***************************************
 *
 * Description: Highlights interwiki links to featured articles (or
 *              equivalents) by changing the bullet before the interwiki link
 *              into a star.
 * Adaptat de la versió anglesa en correspondència amb Plantilla:Enllaç AD i Enllaç AB
 */
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( 'AdQ-' + className ) && InterwikiLinks[i].className.indexOf( 'badge-featuredarticle' ) === -1 ) {
                InterwikiLinks[i].className += ' AdQ';
                InterwikiLinks[i].title = 'Aquest és un article destacat en aquesta llengua.';
            } else if ( document.getElementById( 'AB-' + className ) && InterwikiLinks[i].className.indexOf( 'badge-goodarticle' ) === -1 ) {
                InterwikiLinks[i].className += ' AB';
                InterwikiLinks[i].title = 'Aquest és un article bo en aquesta llengua.';
            }
        }
    }
}

mw.hook( 'wikipage.content' ).add( LinkFA );

//###### comença codi per a plantilla de diapositives (grups d'imatges) #####
/* actualitzat  28-11-13 de [[de:MediaWiki:Common.js]] s'empra amb la plantilla:Galeria dinàmica d'imatges */
/** Skript für [[Vorlage:Galerie]] */
$(function() {
  if (document.URL.match(/printable/g)) return;
 
  function toggleImageFunction(group,  remindex, shwindex) {
    return function() {
      document.getElementById("ImageGroupsGr" + group + "Im" + remindex).style.display = "none";
      document.getElementById("ImageGroupsGr" + group + "Im" + shwindex).style.display = "block";
      return false;
    };
  }
 
  var divs = document.getElementsByTagName("div");
  var i = 0, j = 0;
  var units, search;
  var currentimage;
  var UnitNode;
  for (i = 0; i < divs.length; i++) {
    if (divs[i].className !== "ImageGroup") { continue; }
    UnitNode = undefined;
    search = divs[i].getElementsByTagName("div");
    for (j = 0; j < search.length; j++) {
      if (search[j].className !== "ImageGroupUnits") { continue; }
      UnitNode=search[j];
      break;
    }
    if (UnitNode === undefined) { continue; }
    units = [];
    for (j = 0 ; j < UnitNode.childNodes.length ; j++ ) {
      var temp = UnitNode.childNodes[j];
      if (temp.className === "center") { units.push(temp); }
    }
    var rightlink;
    var commentText;
    for (j = 0; j < units.length; j++) {
      currentimage = units[j];
      currentimage.id = "ImageGroupsGr" + i + "Im" + j;
      var leftlink = document.createElement("a");
      if (commentText !== undefined) {
        leftlink.setAttribute("title", commentText);
      }
      var comment;
      if (typeof(currentimage.getAttribute("title")) !== "string") {
        commentText = (j+1) + "/" + units.length;
        comment = document.createElement("tt").appendChild(document.createTextNode("("+ commentText + ")"));
      } else {
        commentText = currentimage.getAttribute("title");
        comment = document.createElement("span").appendChild(document.createTextNode(commentText));
        currentimage.removeAttribute("title");
      }
      if(rightlink !== undefined) {
        rightlink.setAttribute("title", commentText);
      }
      var imghead = document.createElement("div");
      rightlink = document.createElement("a");
      if (j !== 0) {
        leftlink.href = "#";
        leftlink.onclick = toggleImageFunction(i, j, j-1);
        leftlink.appendChild(document.createTextNode("◀"));
      }
      if (j !== units.length - 1) {
        rightlink.href = "#";
        rightlink.onclick = toggleImageFunction(i, j, j+1);
        rightlink.appendChild(document.createTextNode("▶"));
      }
      imghead.style.fontSize = "110%";
      imghead.style.fontweight = "bold";
      imghead.appendChild(leftlink);
      imghead.appendChild(document.createTextNode("\xA0"));
      imghead.appendChild(comment);
      imghead.appendChild(document.createTextNode("\xA0"));
      imghead.appendChild(rightlink);
      if (units.length > 1) {
        currentimage.insertBefore(imghead,currentimage.childNodes[0]);
      }
      if (j !== 0) {
        currentimage.style.display = "none";
      }
    }
  }
});

//###### finalitza codi per a plantilla de diapositives #####

//================================================================================
//*** force the loading of another JavaScript file (copiat de [[Commons:Common.js]])
// Local Maintainer: [[Commons:User:Dschwen]]
mw.log.deprecate( window, 'includePage', importScript,
 'Use importScript instead' );

/**
 * Transformar certes pàgines en pàgines de discussió amb la plantilla:pàgina de discussió
 * copiat de https://fr.wikipedia.org/w/index.php?title=MediaWiki:Common.js&oldid=98220897
 * abans function TransformeEnDiscussion()
 */
$( function() {
  if( document.getElementById('transformeEnPageDeDiscussion') ) {
    removeClass(document.body, 'ns-subject');
    addClass(document.body, 'ns-talk');
  }
} );

/** Magic editintros ****************************************************
 *
 *  Description: Adds editintros on (disambiguation pages and) BLP pages.
 *  Maintainers: [[User:RockMFR]]
 */

function addEditIntro( name ) {
  $( '.mw-editsection, #ca-edit' ).find( 'a' ).each( function( i, el ) {
    el.href = $(this).attr("href") + '&editintro=' + name;
  });
}

if (mw.config.get('wgNamespaceNumber') === 0) {
  $(function(){
    var cats = mw.config.get('wgCategories');
    if (!cats) {
      return;
    }
    if ( $.inArray( 'Persones vives', cats ) !== -1 ) {
        addEditIntro( "Plantilla:Avís_d'edició_BPV" );
    }
  });
}

/**
 * Inserció de nous botons en la barra d'eines d'edició
 */
var addExtraButtons = function(){
mw.toolbar.addButtons(
	{
		imageFile: '//upload.wikimedia.org/wikipedia/commons/0/04/Button_array.png',
		speedTip: 'Taula',
		tagOpen: '{|\n|-\n|\n|\n|}',
		tagClose: '',
		sampleText: '',
		imageId: 'mw-editbutton-array'
	},
	{
		imageFile: '//upload.wikimedia.org/wikipedia/commons/8/88/Btn_toolbar_enum.png',
		speedTip: 'Enumeració',
		tagOpen: '\n# element 1\n# element 2\n# element 3',
		tagClose: '',
		sampleText: '',
		imageId: 'mw-editbutton-enum'
	},
	{
		imageFile: '//upload.wikimedia.org/wikipedia/commons/1/11/Btn_toolbar_liste.png',
		speedTip: 'Llista',
		tagOpen: '\n* element A\n* element B\n* element C',
		tagClose: '',
		sampleText: '',
		imageId: 'mw-editbutton-liste'
	},
	{
		imageFile: '//upload.wikimedia.org/wikipedia/commons/9/9e/Btn_toolbar_gallery.png',
		speedTip: 'Galeria d\'imatges',
		tagOpen: '\n<gallery>\nFitxer:Exemple.jpg|Descripció\nFitxer:Exemple1.jpg|Descripció 1\nFitxer:Exemple2.jpg|Descripció 2\n</gallery>\n',
		tagClose: '',
		sampleText: '',
		imageId: 'mw-editbutton-gallery'
	},
	{
		imageFile: '//upload.wikimedia.org/wikipedia/commons/3/37/Btn_toolbar_commentaire.png',
		speedTip: 'Comentari',
		tagOpen: '<!--',
		tagClose: '-->',
		sampleText: '',
		imageId: 'mw-editbutton-comment'
	},
	{
		imageFile: '//upload.wikimedia.org/wikipedia/commons/4/47/Button_redir.png',
		speedTip: 'Redirecció',
		tagOpen: '#REDIRECT[[',
		tagClose: ']]',
		sampleText: 'pàgina destinació',
		imageId: 'mw-editbutton-redir'
	},
	{
		imageFile: '//upload.wikimedia.org/wikipedia/commons/b/b4/Button_category03.png',
		speedTip: 'Categoria',
		tagOpen: '[[Categoria:',
		tagClose: ']]',
		sampleText: 'nom de la categoria',
		imageId: 'mw-editbutton-category'
	},
	{
		imageFile: '//upload.wikimedia.org/wikipedia/commons/3/3b/Button_template_alt.png',
		speedTip: 'Plantilla',
		tagOpen: '{{',
		tagClose: '}}',
		sampleText: 'plantilla o pàgina a incloure',
		imageId: 'mw-editbutton-template'
	},
	{
		imageFile: '//upload.wikimedia.org/wikipedia/commons/c/c4/Button_ref.png',
		speedTip: 'Referència',
		tagOpen: '<ref>',
		tagClose: '</ref>',
		sampleText: 'referència, citació o enllaç',
		imageId:  'mw-editbutton-ref'
	},
	{
		imageFile: '//upload.wikimedia.org/wikipedia/commons/6/64/Buttonrefvs8.png',
		speedTip: 'Índex de referències',
		tagOpen: '== Referències ==\n{{referències}}',
		tagClose: '',
		sampleText: '',
		imageId: 'mw-editbutton-references'
	},
	{
		imageFile: '//upload.wikimedia.org/wikipedia/commons/b/bb/Seealso.png',
		speedTip: 'Seccions annexes',
		tagOpen: '== Referències ==\n' +
			'{{referències}}\n\n' +
			'== Vegeu també ==\n' +
			'* [[A omplir]]\n\n' +
			'== Enllaços externs ==\n' +
			'*\n\n',
		tagClose: '',
		sampleText: '',
		imageId: 'mw-editbutton-voiraussi'
	}
);
};

if( $.inArray( mw.config.get( 'wgAction' ), [ 'edit', 'submit' ] ) !== -1 ) {
	mw.loader.using( 'user.options', function () {
		if ( ! mw.user.options.get( 'usebetatoolbar' ) && mw.user.options.get( 'showtoolbar' ) ) {
			$.when(
				mw.loader.using( 'mediawiki.toolbar' ),
				$.ready
			).then( addExtraButtons );
		}
	} );
}
/**
 * Import more specific scripts if necessary
 */
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Watchlist' ) {
    /* watchlist scripts */
    importScript( 'MediaWiki:Common.js/watchlist.js' );
}

/**
 * Redirect User:Name/skin.js and skin.css to the current skin's pages
 * (unless the 'skin' page really exists).
 *
 * Dependencies: mediawiki.util
 *
 * @source www.mediawiki.org/wiki/Snippets/Redirect_skin.js
 * @revision 2014-05-19
 */
if ( mw.config.get( 'wgArticleId' ) === 0 && mw.config.get( 'wgNamespaceNumber' ) === 2 ) {
	var titleParts = mw.config.get( 'wgPageName' ).split( '/' );
	// Make sure there was a part before and after the slash
	// And that the latter is 'skin.js' or 'skin.css'
	if ( titleParts.length == 2 ) {
		var userSkinPage = titleParts[0] + '/' + mw.config.get( 'skin' );
		if ( titleParts[1] === 'skin.js' ) {
			location.href = mw.util.getUrl( userSkinPage + '.js' );
		} else if ( titleParts[1] === 'skin.css' ) {
			location.href = mw.util.getUrl( userSkinPage + '.css' );
		}
	}
}

/**
 * afegeix un enllaç "nova secció" en l'últim encapçalament de pàgines de discussió
 * copiat de https://de.wikipedia.org/w/index.php?title=MediaWiki:Common.js&oldid=153954208
 */
mw.loader.using( [ 'jquery.accessKeyLabel' ], function() { $( function() {
    var newSectionLink = $( '#ca-addsection a' );
    if( newSectionLink.length ) {
        var link = newSectionLink.clone(); //create a copy
        //avoid duplicate accesskey
        link.removeAttr( 'accesskey' ).updateTooltipAccessKeys();
        // passem "Nova secció" a minúscules per coherència
        link.css( {
            "text-transform" : "lowercase" 
        } );
        //add it wihin the brackets
        var lastEditsectionLink = $( 'span.mw-editsection:last a:last' );
        lastEditsectionLink.after( link );
        lastEditsectionLink.after( ' | ' ); //see [[MediaWiki:Pipe-separator]]
    }
})});

/**
 * Description: Stay on the secure server as much as possible
 * Copiat de https://en.wikipedia.org/w/index.php?title=MediaWiki:Common.js&oldid=525198410
 */
if ( document.location && document.location.protocol  && document.location.protocol == 'https:' ) {
    /* New secure servers */
    importScript( 'MediaWiki:Common.js/secure.js' );
}

/**
 * Ticker: vegeu [[plantilla:ticker]]
 * Adaptat de https://en.wikinews.org/w/index.php?title=MediaWiki:Ticker2.js&oldid=1384515
 */
 $(function () {if ((window.disable_ticker2 !== true) && (document.getElementById("singleTickerForPage") || document.getElementById('enableTickers'))) 
mw.loader.load('//en.wikinews.org/w/index.php?title=MediaWiki:ticker2.js&action=raw&ctype=text/javascript');});

/**
 * Simulació d'una pàgina de diferències
 * Necessàri per [[VP:BUS]]. TODO: Afegir a Ajuda:Diferències
 */
if ( mw.config.get( 'wgPageName' ) === 'Viquipèdia:Bus_turístic/Earth/4/Diff' ) {
    mw.loader.load( 'mediawiki.action.history.diff' );
}

/** Ajusta el ordenamiento alfabético en las tablas "sortable" */
/** https://es.wikipedia.org/w/index.php?title=MediaWiki:Common.js&oldid=90238839 */
(function() {
  var letras = [["áàâäãāăåą", "a"], ["æ", "ae"], ["ćĉčç", "c"], ["ďḑđð", "d"], ["éèêëẽěēĕę", "e"],
            ["ĝḡğģǥ", "g"], ["ĥḧḩħ", "h"], ["íìÎîïĩīĭįı", "i"], ["ĵ", "j"], ["ķ", "k"],
            ["ĺľļł", "l"], ["ńňņ", "n"], ["ñ", "n~"], ["óòôöõōŏǫőø", "o"], ["œ", "oe"],
            ["ŕřŗ", "r"], ["śŝšş", "s"], ["ß", "ss"], ["ťţŧ", "t"], ["úùûüũūŭůųű", "u"], ["ṽ", "v"],
            ["ŵẅ", "w"], ["ẍ", "x"], ["ýŷÿỹ", "y"], ["źẑžƶ", "z"], ["·", ""], ["'", " "]];
  var hash = {};
  for (var i = 0; i < letras.length; i++) {
    var arr = letras[i][0].split("");
    var dest = letras[i][1];
    for (var j = 0; j < arr.length; j++) {
      hash[arr[j]] = dest;
    }
  }
  mw.config.set('tableSorterCollation', hash);
})();

/* End of mw.loader.using callback */
} );
/* DO NOT ADD CODE BELOW THIS LINE */
/* Es carregarà per a tots els usuaris, i per a qualsevol pàgina, el codi JavaScript que hi haja després d'aquesta línia. */
importScript('MediaWiki:Infocarrer.js');