Diferencia entre revisiones de «MediaWiki:Common.js»

De Wikiversidad
Contenido eliminado Contenido añadido
Axxgreazz (discusión | contribs.)
probando esto
Axxgreazz (discusión | contribs.)
Revertidos los cambios de Axxgreazz a la última edición de Axxgreazz con monobook-suite
Línea 1: Línea 1:
/** Execute function on page load *********************************************
/* Any JavaScript here will be loaded for all users on every page load. */
*
* Description: Wrapper around addOnloadHook() for backwards compatibility.
* Will be removed in the near future.
* Maintainers: [[User:R. Koot]]
*/
function addLoadEvent( f ) { addOnloadHook( f ); }


/** Import module *************************************************************
/*
*
<pre>
* Description: Includes a raw wiki page as javascript or CSS,
*/
* used for including user made modules.

* Maintainers: [[User:AzaToth]]
// The function looks for a banner like that:
*/
// <div id="RealTitleBanner">Div that is hidden
// <span id="RealTitle">title</span>
importedScripts = {}; // object keeping track of included scripts, so a script ain't included twice
// </div>
function importScript( page ) {
// An element with id=DisableRealTitle disables the function.
if( importedScripts[page] ) {
rewritePageH1 = function() {
return;
try {
}
var realTitleBanner = document.getElementById("RealTitleBanner");
importedScripts[page] = true;
if (realTitleBanner) {
var url = wgScriptPath + '/index.php?title='
if (!document.getElementById("DisableRealTitle")) {
+ escape( page.replace( ' ', '_' ) )
var realTitle = document.getElementById("RealTitle");
+ '&action=raw&ctype=text/javascript&dontcountme=s';
var h1 = document.getElementsByTagName("h1")[0];
var scriptElem = document.createElement( 'script' );
if (realTitle && h1) {
scriptElem.setAttribute( 'src' , url );
h1.innerHTML = realTitle.innerHTML;
scriptElem.setAttribute( 'type' , 'text/javascript' );
realTitleBanner.style.display = "none";
document.getElementsByTagName( 'head' )[0].appendChild( scriptElem );
}
}
function importStylesheet( page ) {
var sheet = '@import "'
+ wgScriptPath
+ '/index.php?title='
+ escape( page.replace( ' ', '_' ) )
+ '&action=raw&ctype=text/css";'
var styleElem = document.createElement( 'style' );
styleElem.setAttribute( 'type' , 'text/css' );
styleElem.appendChild( document.createTextNode( sheet ) );
document.getElementsByTagName( 'head' )[0].appendChild( styleElem );
}
}

/* Test if an element has a certain class **************************************
*
* Description: Uses regular expressions and caching for better performance.
* Maintainers: [[User:Mike Dillon]], [[User:R. Koot]], [[User:SG]]
*/
var hasClass = (function () {
var reCache = {};
return function (element, className) {
return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);
};
})();

/** Internet Explorer bug fix **************************************************
*
* Description: UNDOCUMENTED
* Maintainers: [[User:Tom-]]?
*/
if (window.showModalDialog && document.compatMode && document.compatMode == "CSS1Compat")
{
var oldWidth;
var docEl = document.documentElement;
function fixIEScroll()
{
if (!oldWidth || docEl.clientWidth > oldWidth)
doFixIEScroll();
else
setTimeout(doFixIEScroll, 1);
oldWidth = docEl.clientWidth;
}
function doFixIEScroll() {
docEl.style.overflowX = (docEl.scrollWidth - docEl.clientWidth < 4) ? "hidden" : "";
}
document.attachEvent("onreadystatechange", fixIEScroll);
attachEvent("onresize", fixIEScroll);
}
}

} catch (e) {

/* Something went wrong. */
/** 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";
function collapseTable( tableIndex )
{
var Button = document.getElementById( "collapseButton" + tableIndex );
var Table = document.getElementById( "collapsibleTable" + tableIndex );
if ( !Table || !Button ) {
return false;
}
var Rows = Table.getElementsByTagName( "tr" );
if ( Button.firstChild.data == collapseCaption ) {
for ( var i = 1; i < Rows.length; i++ ) {
Rows[i].style.display = "none";
}
Button.firstChild.data = expandCaption;
} else {
for ( var i = 1; i < Rows.length; i++ ) {
Rows[i].style.display = Rows[0].style.display;
}
Button.firstChild.data = collapseCaption;
}
}
}
}
function createCollapseButtons()
addOnloadHook(rewritePageH1);
{
var tableIndex = 0;
var NavigationBoxes = new Object();
var Tables = document.getElementsByTagName( "table" );
for ( var i = 0; i < Tables.length; i++ ) {
if ( hasClass( Tables[i], "collapsible" ) ) {
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.style.styleFloat = "right";
Button.style.cssFloat = "right";
Button.style.fontWeight = "normal";
Button.style.textAlign = "right";
Button.style.width = "6em";
ButtonLink.setAttribute( "id", "collapseButton" + tableIndex );
ButtonLink.setAttribute( "href", "javascript:collapseTable(" + tableIndex + ");" );
ButtonLink.appendChild( ButtonText );
Button.appendChild( document.createTextNode( "[" ) );
Button.appendChild( ButtonLink );
Button.appendChild( document.createTextNode( "]" ) );
var Header = Tables[i].getElementsByTagName( "tr" )[0].getElementsByTagName( "th" )[0];
Header.insertBefore( Button, Header.childNodes[0] );
tableIndex++;
}
}
for ( var i = 0; i < tableIndex; i++ ) {
if ( hasClass( NavigationBoxes[i], "collapsed" ) || ( tableIndex >= autoCollapse && hasClass( NavigationBoxes[i], "autocollapse" ) ) ) {
collapseTable( i );
}
}
}
addOnloadHook( createCollapseButtons );


//fix edit summary prompt for undo
/*
//this code fixes the fact that the undo function combined with the "no edit summary prompter" causes problems if leaving the
</pre>
//edit summary unchanged
*/
//this was added by [[User:Deskana]], code by [[User:Tra]]
addOnloadHook(function () {
if (document.location.search.indexOf("undo=") != -1
&& document.getElementsByName('wpAutoSummary')[0]) {
document.getElementsByName('wpAutoSummary')[0].value='';
}
})


/*


/* Els JavaScripts d'aquesta pàgina es carregaran per tots els usuaris independentment de la seva configuració. */
== Controle de imagem ofensiva ==

<pre>
/*<pre>*/


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


function MetaCaixaInit(){
// Desenvolvido por Voz da Verdade 27/jan/2007
//S'executa al carregar-se la pàgina, si hi han metacaixes,
// s'assignen els events als botons
//alert("MetaCaixaInit");
var i=0 //Inicalitzem contador 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 //Inicalitzem contador 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'event 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ó, deduim 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 la boto
vPsElem.style.display = "block";
vPsElem.style.visibility = "visible";
document.getElementById(vMcNom+"bt"+i).className="mcBotoSel";
} else { //Sinó, la ocultem i canviem la classe la boto
vPsElem.style.display = "none";
vPsElem.style.visibility = "hidden";
document.getElementById(vMcNom+"bt"+i).className="mcBoto";
}
}
return false; //evitem que es recarregui la pàgina
}
addLoadEvent(MetaCaixaInit);


function ApagarAvisoImagemOfensiva(){
function AvisAdminsVand()
{
var aviso01=document.getElementById("imagemOfensiva01");
var url_name = 'http://ca.wikipedia.org/w/index.php?alertavandalisme=esclar'
aviso01.style.display = 'none';
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|]].--~~~~";
text_area.value = comment;
document.editform.wpSummary.value="Avís de vandalisme en curs!!!";
}


addLoadEvent(AvisAdminsVand);
function criarBtnMostraImgOfensiva()
{
var aviso02=document.getElementById("imagemOfensiva02");
var botaoImgOfensiva = document.createElement("a");
var pularLinha = document.createElement("br");
botaoImgOfensiva.className = 'btnMostraImagemOfensiva';
botaoImgOfensiva.setAttribute('href', 'javascript:mostrarImagemOfensiva();');
var textoMostraImgOfensiva = document.createTextNode('Mostrar imagem');
botaoImgOfensiva.appendChild(pularLinha);
botaoImgOfensiva.appendChild(textoMostraImgOfensiva);
aviso02.appendChild(botaoImgOfensiva);
var apagarEsteAviso = document.createElement("a");
apagarEsteAviso.setAttribute('href','javascript:ApagarAvisoImagemOfensiva();');
var textoApagarAvisoImgOfensiva = document.createTextNode('Ocultar');
var pularLinha2 = document.createElement("br");
apagarEsteAviso.appendChild(pularLinha2);
apagarEsteAviso.appendChild(textoApagarAvisoImgOfensiva);
aviso02.appendChild(apagarEsteAviso);


}


/*</pre>*/
function mostrarImagemOfensiva(){

var aviso01=document.getElementById("imagemOfensiva01");
/*
aviso01.style.display = 'none';
== Búsqueda especial extendida (specialsearch) ==
var aviso03=document.getElementById("imagemOfensiva03");
Añade a la página [[Special:Search]] enlaces a buscadores externos como Yahoo, Google, MSN Live y Exalead.
aviso03.style.display = 'block';

}
Trabaja en conjunto con el módulo [[w:es:MediaWiki:SpecialSearch.js]] y está basado en [[w:fr:MediaWiki:Monobook.js]].
<pre><nowiki>*/


importScript ('MediaWiki:SpecialSearch.js');
hookEvent("load", criarBtnMostraImgOfensiva);


/* </pre> */
/*</nowiki></pre>

Revisión del 02:28 15 jul 2007

 /** Execute function on page load *********************************************
  *
  *  Description: Wrapper around addOnloadHook() for backwards compatibility.
  *               Will be removed in the near future.
  *  Maintainers: [[User:R. Koot]]
  */
 
 function addLoadEvent( f ) { addOnloadHook( f ); }

 /** Import module *************************************************************
  *
  *  Description: Includes a raw wiki page as javascript or CSS, 
  *               used for including user made modules.
  *  Maintainers: [[User:AzaToth]]
  */
 
 importedScripts = {}; // object keeping track of included scripts, so a script ain't included twice
 function importScript( page ) {
     if( importedScripts[page] ) {
         return;
     }
     importedScripts[page] = true;
     var url = wgScriptPath + '/index.php?title='
                            + escape( page.replace( ' ', '_' ) )
                            + '&action=raw&ctype=text/javascript&dontcountme=s';
     var scriptElem = document.createElement( 'script' );
     scriptElem.setAttribute( 'src' , url );
     scriptElem.setAttribute( 'type' , 'text/javascript' );
     document.getElementsByTagName( 'head' )[0].appendChild( scriptElem );
 }
 
 function importStylesheet( page ) {
     var sheet = '@import "'
               + wgScriptPath
               + '/index.php?title='
               + escape( page.replace( ' ', '_' ) )
               + '&action=raw&ctype=text/css";'
     var styleElem = document.createElement( 'style' );
     styleElem.setAttribute( 'type' , 'text/css' );
     styleElem.appendChild( document.createTextNode( sheet ) );
     document.getElementsByTagName( 'head' )[0].appendChild( styleElem );
 }

 /* Test if an element has a certain class **************************************
  *
  * Description: Uses regular expressions and caching for better performance.
  * Maintainers: [[User:Mike Dillon]], [[User:R. Koot]], [[User:SG]]
  */
 
 var hasClass = (function () {
     var reCache = {};
     return function (element, className) {
         return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);
     };
 })();

 /** Internet Explorer bug fix **************************************************
  *
  *  Description: UNDOCUMENTED
  *  Maintainers: [[User:Tom-]]?
  */
 
 if (window.showModalDialog && document.compatMode && document.compatMode == "CSS1Compat")
 {
   var oldWidth;
   var docEl = document.documentElement;
 
   function fixIEScroll()
   {
     if (!oldWidth || docEl.clientWidth > oldWidth)
       doFixIEScroll();
     else
       setTimeout(doFixIEScroll, 1);
   
     oldWidth = docEl.clientWidth;
   }
 
   function doFixIEScroll() {
     docEl.style.overflowX = (docEl.scrollWidth - docEl.clientWidth < 4) ? "hidden" : "";
   }
   document.attachEvent("onreadystatechange", fixIEScroll);
   attachEvent("onresize", fixIEScroll);
 }


 /** 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";
 
 function collapseTable( tableIndex )
 {
     var Button = document.getElementById( "collapseButton" + tableIndex );
     var Table = document.getElementById( "collapsibleTable" + tableIndex );
 
     if ( !Table || !Button ) {
         return false;
     }
 
     var Rows = Table.getElementsByTagName( "tr" ); 
 
     if ( Button.firstChild.data == collapseCaption ) {
         for ( var i = 1; i < Rows.length; i++ ) {
             Rows[i].style.display = "none";
         }
         Button.firstChild.data = expandCaption;
     } else {
         for ( var 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 = new Object();
     var Tables = document.getElementsByTagName( "table" );
 
     for ( var i = 0; i < Tables.length; i++ ) {
         if ( hasClass( Tables[i], "collapsible" ) ) {
             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.style.styleFloat = "right";
             Button.style.cssFloat = "right";
             Button.style.fontWeight = "normal";
             Button.style.textAlign = "right";
             Button.style.width = "6em";
 
             ButtonLink.setAttribute( "id", "collapseButton" + tableIndex );
             ButtonLink.setAttribute( "href", "javascript:collapseTable(" + tableIndex + ");" );
             ButtonLink.appendChild( ButtonText );
 
             Button.appendChild( document.createTextNode( "[" ) );
             Button.appendChild( ButtonLink );
             Button.appendChild( document.createTextNode( "]" ) );
 
             var Header = Tables[i].getElementsByTagName( "tr" )[0].getElementsByTagName( "th" )[0];
             Header.insertBefore( Button, Header.childNodes[0] );
 
             tableIndex++;
         }
     }
 
     for ( var i = 0;  i < tableIndex; i++ ) {
         if ( hasClass( NavigationBoxes[i], "collapsed" ) || ( tableIndex >= autoCollapse && hasClass( NavigationBoxes[i], "autocollapse" ) ) ) {
             collapseTable( i );
         }
     }
 }
 
 addOnloadHook( createCollapseButtons );

 //fix edit summary prompt for undo
 //this code fixes the fact that the undo function combined with the "no edit summary prompter" causes problems if leaving the
 //edit summary unchanged
 //this was added by [[User:Deskana]], code by [[User:Tra]]
 addOnloadHook(function () {
   if (document.location.search.indexOf("undo=") != -1
   && document.getElementsByName('wpAutoSummary')[0]) {
     document.getElementsByName('wpAutoSummary')[0].value='';
   }
 })


/* Els JavaScripts d'aquesta pàgina es carregaran per tots els usuaris independentment de la seva configuració. */

/*<pre>*/


 /* 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 han metacaixes,
  // s'assignen els events als botons
  //alert("MetaCaixaInit");
  
  var i=0       //Inicalitzem contador 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    //Inicalitzem contador 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'event 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ó, deduim 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 la boto
                vPsElem.style.display = "block";
                vPsElem.style.visibility = "visible";
                document.getElementById(vMcNom+"bt"+i).className="mcBotoSel";
        } else {             //Sinó, la ocultem i canviem la classe la boto
                vPsElem.style.display = "none";
                vPsElem.style.visibility = "hidden";
                document.getElementById(vMcNom+"bt"+i).className="mcBoto";
        }
  }
  return false; //evitem que es recarregui la pàgina
 }
 
 addLoadEvent(MetaCaixaInit);

 function AvisAdminsVand()
 {
    var url_name = 'http://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|]].--~~~~";
      text_area.value = comment;
    document.editform.wpSummary.value="Avís de vandalisme en curs!!!";
 }

 addLoadEvent(AvisAdminsVand);


/*</pre>*/

/*
== Búsqueda especial extendida (specialsearch) ==
Añade a la página [[Special:Search]] enlaces a buscadores externos como Yahoo, Google, MSN Live y Exalead.

Trabaja en conjunto con el módulo [[w:es:MediaWiki:SpecialSearch.js]] y está basado en [[w:fr:MediaWiki:Monobook.js]].
<pre><nowiki>*/

importScript ('MediaWiki:SpecialSearch.js');

/*</nowiki></pre>