Usuari:Grondin/common.js

De Viquinotícies

Nota: Després de desar, heu de posar al dia la memòria cau del vostre navegador per veure els canvis. Mozilla / Firefox / Safari: Premeu Shift mentre cliqueu Actualitza (Reload), o premeu Ctrl+Shift+R (Cmd+Shift+R en un Mac Apple); Internet Explorer: premeu Ctrl mentre cliqueu Actualtiza (Refresh), o premeu Ctrl+F5; Konqueror:: simplement cliqueu el botó Recarregar (Reload), o premeu F5; Opera haureu d'esborrar completament la vostra memòria cau (caché) a Tools→Preferences.

/*<pre>*/

/*</pre>
== Edition sommaire ==

<pre>*/

///////////////////////ajouts/////////////////////////


function addToSummary(str)
{
        document.editform.wpSummary.value += " " + str
}

function DeluxeSummary()
{
        var sumLbl = document.getElementById("wpSummaryLabel")
        if (sumLbl)
        {
                //élargissement boite de résumé
                var sumInput = document.getElementById("wpSummary")
                sumInput.style.width = "90%"

                var titles = new Array()
                titles.push("esborrany")
                titles.push("des")
                titles.push("pub")
                titles.push("titular")
                titles.push("dia")
                titles.push("cat")
                titles.push("fitxer")
                titles.push("viquif")
                titles.push("interwiki")
                titles.push("interprojecte")
                titles.push("int")
                titles.push("ext")
                titles.push("corr interwiki")
                titles.push("corr int")
                titles.push("corr ext")
                titles.push("corr prjt")
                titles.push("ext -> int")
                titles.push("int -> interviqui")
                titles.push("ext -> interviqui")
                titles.push("paginació")
                titles.push("redir")
                titles.push("orto/gram")
                titles.push("retocs")
                titles.push("afInfo")
		titles.push("fonts")
                titles.push("recat")
                titles.push("creació")
                titles.push("data")
                titles.push("bloqueig")


                var inputs = new Array()
                inputs.push("Esborrany")
                inputs.push("Notícia en desenvolupament")
                inputs.push("Publicació de la pàgina")
                inputs.push("Nou titular")
                inputs.push("Nou dia")
                inputs.push(" - categoria")
                inputs.push(" - fitxer")
                inputs.push("viquificació")
                inputs.push(" - enllaços interviquis")
                inputs.push(" - enllaços interprojectes")
                inputs.push(" - enllaç intern")
                inputs.push(" - enllaç extern")
                inputs.push("correcció enllaç interviqui")
                inputs.push("correcció enllaç intern")
                inputs.push("correcció enllaç extern")
                inputs.push("correcció enllaç interprojecte")
                inputs.push("conversió enllaç extern en enllaç intern")
                inputs.push("conversió enllaç intern en enllaç interviqui")
                inputs.push("conversió enllaç extern en enllaç interviqui")
                inputs.push("paginació")
                inputs.push("redirecció")
                inputs.push("correcció de l’ortografia o de la gramàtica")
                inputs.push("diversos retocs")
                inputs.push("afegeix algunes informacions")
			 	inputs.push("afegeix algunes fonts")
                inputs.push("canvi de categoria")
                inputs.push("creació de la pàgina")
                inputs.push(" - "+ TodayDate())
                inputs.push("Avís de bloqueig")

                var str = ""
                for (var cpt = 0; cpt < titles.length; cpt ++)
                {
                        str += "<a href=\"javascript:addToSummary('" + inputs[cpt] + "')\""
                                + " class=\"sumLink\" title=\"Ajouter '" + inputs[cpt] +"' dans la boîte de résumé\">"
                                + titles[cpt]
                                + " ·</a> "
                }
                sumLbl.innerHTML = str + "<br />" + sumLbl.innerHTML
        }
}

$(DeluxeSummary);



/*</pre>

==BARRE EDITION BOUTON==

<pre>*/

function DeluxeBar() {
  if (document.createTextNode) {
        var toolbar = document.getElementById("toolbar"); 
        if (!toolbar) return;
        

        var messages = new Array()
        var images = new Array()
        var commentaires = new Array()
        var a=-1;

//Le décompte commence à -1 avec une incrementation sur le premier message, pour éviter tout probleme en cas d'inversion ou suppression du premier message

        // le texte a été splitté sinon Mediawiki casse tout...

        messages[++a] = "<br />" ;
        images[a] = "http://upload.wikimedia.org/wikipedia/en/1/13/Button_enter.png";
        commentaires[a] = ""

        messages[++a] = ":"+ "{{" + "Fet" + "}}" + " --" + "~~" + "~~";
        images[a] = "http://upload.wikimedia.org/wikipedia/commons/9/9d/Button_fait.png";
        commentaires[a] = "Fet "

        messages[++a] = "{{" + "Desenvolupament" + "}}" ;
        images[a] = "http://upload.wikimedia.org/wikipedia/commons/c/c3/Button_travaux.png"
        commentaires[a] = "Notícia en desenvolupament"

        messages[++a] = "{{" + "Esdeveniments en curs" + "}}";
        images[a] = "http://upload.wikimedia.org/wikipedia/commons/2/26/Button_horloge.png";
        commentaires[a] = "Esdeveniments en curs"

        messages[++a] = "{{Projectes germans" + "\\n|Commons=\\n|Viccionari=\\n|Viquidites=\\n|Viquiespècies=\\n|Viquillibres=\\n|Viquipèdia=\\n|Viquitexts=\\n|Viquiversitat=\\n" + "}}";
        images[a] = "http://upload.wikimedia.org/wikipedia/commons/3/30/Button_Wikimedia.png";
        commentaires[a] = "Projectes germans"

        messages[++a] = "{{" + "notes" + "}}";
        images[a] = "http://upload.wikimedia.org/wikipedia/commons/f/fe/Button_refs.png";
        commentaires[a] = ""

      ////////////////////////////////

for (var i=0;i<messages.length;i++) {
                var img = document.createElement("img");
                img.setAttribute("src", images[i]);
                
                var ref = document.createElement("a");
                ref.setAttribute("href", "javascript:insertTags('', \"" + messages[i] + "\", '');" + 
                                 "javascript:changeSummary(\"" + commentaires[i] + "\");" ); 
                ref.appendChild(img); 
                
                toolbar.appendChild(ref);
        }
  }
}

function changeSummary(sampleText) {
        document.editform.wpSummary.value = sampleText;
}

$(document).ready(DeluxeBar);

/* </pre>
==Afegeix enllaços interns (Import, Edittool.) a la pantalla esquerra de la finestra ==
<pre>*/
function OptimizedNavig() 
{
  var a = document.getElementById("p-navigation");

  if (a) 
  {
    b = a.getElementsByTagName("ul");
    if(b.length > 0)
    { 
      var startUrl = '/w/index.php?title='
      var endUrl = '&action=purge'

      // liste des URLs
      var urls = new Array()
      urls[0] = 'Special:Export'
      urls[1] = 'Special:Import'
      urls[2] = 'Mediawiki:Edittools'
      urls[3] = 'Mediawiki:Common.js'
      urls[4] = 'Mediawiki:Gadgets-definition'
      urls[5] = 'Mediawiki:Common.css'


	
      var labels = new Array()
      labels[0] = 'Export'
      labels[1] = 'Import'
      labels[2] = 'Edittools'
      labels[3] = 'Common'
      labels[4] = 'Gadgets'
      labels[5] = 'Style'



      for (var i=0;i<urls.length;i+=2) {
        tableHTML = '<div style="font-size:0.75em;"><table valign="top" cellspacing="0" cellpadding="0">'
        tableHTML += '<tr>'
        tableHTML += '<li><td><a href="' + startUrl + urls[i] + endUrl + '">' + labels[i] + ' | </a></td>'
        tableHTML += '<td><a href="' + startUrl + urls[i+1] + endUrl + '">' + labels[i+1] + '</a></td></li>'
        tableHTML += '</tr>'
        tableHTML += '</table></div>' 
        b[0].innerHTML = b[0].innerHTML + tableHTML
      }

    }
  }
}

$(OptimizedNavig);

////FONCTION TODAYDATE///
function TodayDate()
{
        var m = new Array("de gener", "de febrer", "de març", "d’abril", "de maig", "de juny", "de juliol", "d’agost", "de setembre", "d’octubre", "de novembre", "de desembre")
        var today = new Date()
        var day = today.getDate()
        var year = today.getYear()

        if (year < 2000)
                year += 1900

        return (day + " " + m[today.getMonth()] + " del " + year)
}


/*</pre>

== Optimise le suivi ==

<pre>*/

function OptimizedSuivi() 
{
  if (document.URL.indexOf("http://fr.wikipedia.org/wiki/Special:Watchlist")==0 ||
      document.URL.indexOf("http://fr.wikipedia.org/w/index.php?title=Special:Watchlist")==0) {
                
    var allDays = document.getElementsByTagName("ul");          
    for (i=0; i<allDays.length; i++) {
       if (allDays[i].getAttribute("class") == "special") {
  
          var artList = allDays[i].getElementsByTagName("li");
          for (j=0; j<artList.length; j++) {
             var elem = artList[j];
             var aTag = elem.getElementsByTagName("a");
             var articleName = aTag[0].getAttribute("title");
             var stopWatch  = "/w/index.php?title=" + articleName + "&action=unwatch"
                            
             var newElement = document.createElement("a");
             newElement.setAttribute("href",stopWatch);
             var newText = document.createTextNode("stop");
             newElement.appendChild(newText);

             var newPar = document.createTextNode(") (")
             // séparation des cas (nouvel article, ou déjà existant)
             if (aTag[0].childNodes[0].data == "diff") {
                insertAfter(elem, newPar, aTag[1]); 
             } else {
                insertAfter(elem, newPar, aTag[0]); 
             }
                                        
             insertAfter(elem, newElement, newPar);
          }       
       }
    }
  }
}


/* NOUVEAUX CODE POUR LES BOUTON SUPPRIMÉS */

$(function() {

  if (['edit', 'submit'].indexOf(mw.config.get('wgAction')) == -1)
    return;

  $.each([
    // Format : pour chaque bouton
    // [
    //   'Texte à insérer avant la sélection', 'Texte à insérer après la sélection',
    //   'Image du bouton (après « commons/ » et sans « .png » à la fin)',
    //   'Texte apparaissant dans la bulle au survol du bouton',
    //   'Identifiant de l'image ; importance faible, mais il faut s'assurer que l'identifiant est unique, ne change pas et n'utilise ni espace, ni caractères spéciaux'
    // ],
    //
    /*
    [
     '', '',
     '',
     '',
     ''
    ],
    */
    [
     '{{Text Global Voices\n|1=', '\n|2=\n|3=\n}}',
     '1/1d/Button_trefle',
     'Font Global Voices',
     'enllaç'
    ],
    [
     '{{Text Vilaweb\n|enllaç=div\n|1=', '\n|2=\n}}',
     '8/8f/Button_catalunya',
     'Font Vilaweb',
     'enllaç'
    ],
    [
     '{{Text el Diaro\n|1=', '\n|2=\n}}',
     '5/51/Button_spain',
     'Font el Diaro',
     'enllaç'
    ],
    [
     '{{Ext|1=', '|2=}}',
     '5/53/Button_ext_link',
     'Estil d’enllaç extern',
     'Enllaç extern'
    ],
    [
     '{| border=0\n|width=50%| ','\n|width=50%| \n|}',
     '2/2f/Button_tableau',
     'Esborrany de taula',
     'Text'
    ],
    [
     '{{Portal ', '}}',
     '9/97/Template_button',
     'Nom del portal',
     'Bandera portal'
    ],
    [
     '{{Vermell|', '}}',
     '8/8d/Button_rouge',
     'Text en vermell',
     'Text'
    ],
    [
     '{{Text|', '| | }}',
     '1/1e/Button_font_color',
     'Mida i color del text',
     'Text'
    ],
    [
    '{{subst:#time:j}} {{subst:#switch:{{subst:#time:m}}|#default=de {{subst:#time:F}}|04|08|10=d\'{{subst:#time:F}}}} del {{subst:#time:Y}}', '',
     '3/3f/Button_attendre',
     'Data corrent',
     ''
    ],
    [
     '{{formatnum:', '}}',
     'e/e9/Button_formatnum',
     'Format dels nombres',
     'Nombre'
    ],
    [
     '{{Encadré\n|align=\n|longueur=\n|titre=\n|1=','\n}}',
     'c/cf/Button_encadr%C3%A9',
     'Text enquadrat',
     'Text'
    ],
    [
     '<div style="text-align:center;">', '</div>',
     '5/5f/Button_center',
     'Centra el texte',
     'Text'
    ],
], function(_, button) {
    mw.toolbar.addButton('//upload.wikimedia.org/wikipedia/commons/' + button[2] + '.png', button[3], button[0], button[1], (button[0] ? button[4] : ''), 'mw-editbutton-' + button[4]);
  });

});


/*</pre>*/