Utilisateur:Cj73/BandeauxFaciles.js

Note : après avoir enregistré la page, vous devrez forcer le rechargement complet du cache de votre navigateur pour voir les changements.

Mozilla / Firefox / Konqueror / Safari : maintenez la touche Majuscule (Shift) en cliquant sur le bouton Actualiser (Reload) ou pressez Maj-Ctrl-R (Cmd-R sur Apple Mac) ;

Firefox (sur GNU/Linux) / Chrome / Internet Explorer / Opera : maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl-F5.
/* ***********************************************

BandeauxFaciles

Licence : domaine public

Documentation : [[Projet:JavaScript/Notices/BandeauxFaciles]]


{{Projet:JavaScript/Script|BandauxFaciles}}
************************************************** */
//<source lang=javascript>//<pre><nowiki>

var editSectionMenu = -1;
var editSectionMenu_CodeUrl = new Array();
var editSectionMenu_ModeleDebut = new Array();
var editSectionMenu_ModeleParametres = new Array();

////////////////////////////////////////////////////////////////// PARTIE PERSONNALISABLE ////////////////////////////////////////////

var editSectionMenu_Autosubmit = true;  // Publication automatique

var editSectionMenu_Pop = "Cliquer pour ajouter : ";
var editSectionMenu_Enrouler = "-";
var editSectionMenu_EnroulerPop = "Cliquer pour enrouler le menu Bandeaux";
var editSectionMenu_Derouler = "+";
var editSectionMenu_DeroulerPop = "Cliquer pour dérouler le menu Bandeaux";

editSectionMenu++
editSectionMenu_CodeUrl[editSectionMenu] = "&vide=1" ;
editSectionMenu_ModeleDebut[editSectionMenu] = "{{..." ;
editSectionMenu_ModeleParametres[editSectionMenu] = "non" ;
editSectionMenu++
editSectionMenu_CodeUrl[editSectionMenu] = "&ebauche=Tous" ;
editSectionMenu_ModeleDebut[editSectionMenu] = "{{Ébauche" ;
editSectionMenu_ModeleParametres[editSectionMenu] = "oui" ;
editSectionMenu++
editSectionMenu_CodeUrl[editSectionMenu] = "&ebauche=Colombie" ;
editSectionMenu_ModeleDebut[editSectionMenu] = "{{Ébauche|Colombie" ;
editSectionMenu_ModeleParametres[editSectionMenu] = "non" ;
editSectionMenu++
editSectionMenu_CodeUrl[editSectionMenu] = "&wikifier=1" ;
editSectionMenu_ModeleDebut[editSectionMenu] = "{{À wikifier" ;
editSectionMenu_ModeleParametres[editSectionMenu] = "non" ;
editSectionMenu++
editSectionMenu_CodeUrl[editSectionMenu] = "&admissibilite=1" ;
editSectionMenu_ModeleDebut[editSectionMenu] = "{{Admissibilité à vérifier" ;
editSectionMenu_ModeleParametres[editSectionMenu] = "non" ;
editSectionMenu++
editSectionMenu_CodeUrl[editSectionMenu] = "&sources=1" ;
editSectionMenu_ModeleDebut[editSectionMenu] = "{{à sourcer" ;
editSectionMenu_ModeleParametres[editSectionMenu] = "non" ;
editSectionMenu++
editSectionMenu_CodeUrl[editSectionMenu] = "&anecdotes=1" ;
editSectionMenu_ModeleDebut[editSectionMenu] = "{{Anecdotes" ;
editSectionMenu_ModeleParametres[editSectionMenu] = "non" ;
editSectionMenu++
editSectionMenu_CodeUrl[editSectionMenu] = "&promotionnel=1" ;
editSectionMenu_ModeleDebut[editSectionMenu] = "{{Promotionnel" ;
editSectionMenu_ModeleParametres[editSectionMenu] = "non" ;

////////////////////////////////////////////////////////////////// FIN DE LA PARTIE PERSONNALISABLE ////////////////////////////////////////////

var editSectionMenu_Page=encodeURI(mw.config.get('wgPageName'));
editSectionMenu_Page=editSectionMenu_Page.replace(/&/g,"%26");
editSectionMenu_Page=editSectionMenu_Page.replace(/'/g,"%27");

var editSectionMenu_Adresse= mw.config.get('wgServer') + mw.config.get('wgScript') + "?title="+editSectionMenu_Page+"&action=edit";

// -------------------------------------------------------------------- Lancements

if(mw.config.get('wgNamespaceNumber')>=0)
$(makeButtons);

if(mw.config.get('wgAction')=="edit"){
      addOnloadHook(doEdit);
}

// -------------------------------------------------------------------- Ajout des liens

function makeButtons(){
      var SousTitre = document.getElementById('siteSub'); // En-tête
      makeEditSectionMenu(SousTitre, 0);
      var EditSections = document.getElementsByTagName('span');  // Sections
      var editSectionCount = 1;
      for(s=0;s<EditSections.length;s++){
            if( $(EditSections[s]).hasClass("editsection") ){
                  makeEditSectionMenu(EditSections[s], editSectionCount)
                  editSectionCount++
            }
      }
}

// -------------------------------------------------------------------- Création d'un menu

function makeEditSectionMenu(element, count){
      if(!element) return;
      if(!count) count = 0;
      element.style.display='inline';
      element.style.border='none';
      var Liens =  '[<a id="editSectionMenuLink_'+count+'" '
                  +' href="javascript:editSectionMenuAfficher('+count+');" title="'+editSectionMenu_DeroulerPop+'" >'+editSectionMenu_Derouler+'</a>]'
                  +' <span id="editSectionMenu_'+count+'" style="display:none;" ><br/>';
      for(a=0;a<editSectionMenu_CodeUrl.length;a++){
            if(editSectionMenu_ModeleParametres[a]=="oui"){
                   Params = "|...";
            }else{
                   Params = "";
            }
            Liens += ' <a href="'+editSectionMenu_Adresse+'&section='+count+editSectionMenu_CodeUrl[a]+'" title="'+editSectionMenu_Pop+editSectionMenu_ModeleDebut[a]+Params+'}}" >'+editSectionMenu_ModeleDebut[a]+Params+'}}</a>'
      }
      Liens += '</span>';
      if(count==0){
            element.innerHTML = Liens;
      }else{
            element.innerHTML = element.innerHTML + ' - ' + Liens;
      }
}

// -------------------------------------------------------------------- Affichage d'un menu

function editSectionMenuAfficher(Id){
      var Lien = document.getElementById("editSectionMenuLink_" + Id);
      Lien.innerHTML = editSectionMenu_Enrouler;
      Lien.title = editSectionMenu_EnroulerPop;
      Lien.href = "javascript:editSectionMenuMasquer("+Id+");";
      var Menu = document.getElementById("editSectionMenu_" + Id);
      Menu.style.display = 'inline';
}

// -------------------------------------------------------------------- Masquage d'un menu

function editSectionMenuMasquer(Id){
      var Lien = document.getElementById("editSectionMenuLink_" + Id);
      Lien.innerHTML = editSectionMenu_Derouler;
      Lien.title = editSectionMenu_DeroulerPop;
      Lien.href = "javascript:editSectionMenuAfficher("+Id+");";
      var Menu = document.getElementById("editSectionMenu_" + Id);
      Menu.style.display = 'none';
}

// -------------------------------------------------------------------- Ajout du modèle et publication

function doEdit(){
    var CodeUrl=0;
        var EditMode = false;
    while(CodeUrl<editSectionMenu_CodeUrl.length){
        if( location.href.indexOf(editSectionMenu_CodeUrl[CodeUrl]) != -1 ){
                        EditMode = true;
            var ModeleDebut = editSectionMenu_ModeleDebut[CodeUrl];
            var ModeleParametres = editSectionMenu_ModeleParametres[CodeUrl];
            break;
        }
        CodeUrl++
    }
        if(EditMode==false) return;
        Parametres = '';
        if(ModeleParametres=="oui"){
                var Param = prompt('Paramètres supplémentaires.\nExemple : ' + ModeleDebut + '|param1=valeur1|param2=valeur2|param3' + '}}');
                if(Param==false) return;
                if(Param!=null) Parametres = Param;
        }
        var Bandeau = ModeleDebut + Parametres + '}}' ;
    var txt=document.getElementById("wpTextbox1").value;
        if( (location.href.indexOf('&section=')!=-1) && (location.href.indexOf('&section=0')==-1) ){  // ---------------------  section avec titre à éviter
                var TitreSection = txt.substring(0, txt.indexOf("\n"));
                var TexteFin  = txt.split(TitreSection).join('');
                var Texte = TitreSection + '\n' + Bandeau + TexteFin;
        }else{  // --------------------- --------------------- --------------  section 0 ou edit simple
                var Texte = Bandeau + '\n' + txt;
        }
        document.getElementById ("wpTextbox1").value = Texte ;
        document.editform.wpSummary.value = document.editform.wpSummary.value + 'Ajout de : ' + Bandeau ;
        if(editSectionMenu_Autosubmit==true) document.editform.submit();
}
//</nowiki></pre></source>