Communauté  • Livre d'or
Chats noirs.jpg Actualités, astuces, interview... Venez lire la gazette de ce printemps de Vikidia ! DessinInterview.png

Utilisateur:Vivi-1/monobook.js

Aller à la navigation Aller à la recherche

Note : après avoir enregistré tes préférences, tu devras forcer le rechargement complet du cache de ton navigateur pour voir les changements. Mozilla Firefox / Safari : maintiens la touche Majuscule (Shift) en cliquant sur le bouton Actualiser (Reload) ou presse Maj-Ctrl-R (Maj-Cmd-R sur Apple Mac) ; Internet Explorer / Opera : maintiens la touche Ctrl en cliquant sur le bouton Actualiser ou presse Ctrl-F5.

/**
 * Espace de travail de {{u|vivi-1}}
 *
 */
// Source  : [[:wp:MediaWiki:Gadget-BandeauxEbauches.js]]

//<source lang=javascript>
//<pre><nowiki>
//
////////////////////////////////////////////////////////////////////////////////////////// VARIABLES PERSONNALISABLES
var BandeauxEbauches_MaxParams = 6; // Nombre maximum de paramètres pour le modèle {{Ébauche}}
 
if(typeof(BandeauxEbauches_AutoEdit)=='undefined') var BandeauxEbauches_AutoEdit = true;         // Publication automatique
if(typeof(BandeauxEbauches_MinorEdit)=='undefined') var BandeauxEbauches_MinorEdit = true;       // Modification mineure
if(typeof(BandeauxEbauches_TailleListe)=='undefined') var BandeauxEbauches_TailleListe = 5;      // Nombre de suggestions
if(typeof(BandeauxEbauches_ListeBas)=='undefined') var BandeauxEbauches_ListeBas = true;         // Affichage des suggestions vers le bas
if(typeof(BandeauxEbauches_KeyboardDelay)=='undefined') var BandeauxEbauches_KeyboardDelay = 5;  // Délai (en secondes) lors de la sélection d'une suggestion au clavier
 
 
////////////////////////////////////////////////////////////////////////////////////////// LANCEMENT
 
if(((wgAction=="view")||(wgAction=="purge")||(wgAction=="submit"))&&(wgNamespaceNumber>-1)){
      addOnloadHook(BandeauxMaintenance);
}
 
function BandeauxMaintenance(){
      var AllEbauches = getElementsByClassName(document, 'div', 'bandeau-niveau-maintenance');
      for(var a=0;a<AllEbauches.length;a++){
            var Bandeau = AllEbauches[a];
            var BandeauTable = Bandeau.getElementsByTagName('table')[0];
            BandeauTable.id = 'TableBandeau_'+a;
            var StrongText = Bandeau.getElementsByTagName('strong')[0];
            StrongText.innerHTML += ' (<a href="javascript:BandeauxEbauches_GetBandeaux(\''+a+'\');" title="Modifier le bandeau de maintenance">modifier</a>)';
      }
      if(!AllEbauches[0]){
            var Cactions = document.getElementById('p-cactions');
            if(Cactions){
                  var UL = Cactions.getElementsByTagName('ul')[0];
                  if(UL){
                        var LI = document.createElement('li');
                        LI.innerHTML = '<a href="javascript:BandeauxEbauches_CreateBandeau();" title="Ajouter un bandeau de maintenance">Maintenance</a>';
                        UL.appendChild(LI);
                        removeClass(Cactions, "emptyPortlet");
                  }
            }
      }
}
 
 
////////////////////////////////////////////////////////////////////////////////////////// RECHERCHE DES PARAMÈTRES DU BANDEAU ACTUEL
 
var BandeauxEbauches_APILImit = (wgUserGroups.indexOf("sysop")!=-1 || wgUserGroups.indexOf("bot")!=-1 ? 4999 : 499);
 
function BandeauxEbauches_GetBandeaux(BandeauCount, ListeBandeaux, tlContinue){
      if(!ListeBandeaux) ListeBandeaux = new Array();
      if(!tlContinue) tlContinue = "";
      var url = wgServer + wgScriptPath + '/api.php?format=xml&action=query&prop=templates'
              + '&aplimit='+BandeauxEbauches_APILImit
              + '&titles=' + encodeURIComponent(wgPageName)
              + tlContinue;
      var BandeauxEbauches_Request = sajax_init_object();
      BandeauxEbauches_Request.open("GET", url, true);
      BandeauxEbauches_Request.send(null);
      BandeauxEbauches_Request.onreadystatechange = function() {
            if(BandeauxEbauches_Request.readyState != 4 || BandeauxEbauches_Request.status != 200) return;
            var ObjectXML = BandeauxEbauches_Request.responseXML;
            var tl = ObjectXML.getElementsByTagName('tl');
            for(var a=0;a<tl.length;a++){
                  var TitreTL = tl[a].getAttribute('title');
                  if(TitreTL.match(/Ébauche\/paramètres /)==null) continue;
                  TitreTL = TitreTL.replace(/.*Ébauche\/paramètres /g, '');
                  ListeBandeaux.push(TitreTL);
            }
            var MustContinue = ObjectXML.getElementsByTagName('templates')[0];
            if(MustContinue){
                  var Continue = "&tlcontinue=" + encodeURIComponent(MustContinue.getAttribute('tlcontinue'));
                  BandeauxEbauches_GetBandeaux(BandeauCount, ListeBandeaux, Continue);
            }else{
                   BandeauxEbauches_ModifyBandeau(BandeauCount, ListeBandeaux);
             }
      }
}
 
 
////////////////////////////////////////////////////////////////////////////////////////// FORMULAIRE
 
function BandeauxEbauches_CreateBandeau(){
      var Content = document.getElementById('bodyContent');
      if(!Content) Content = document.getElementById('mw_contentholder');
      if(!Content) Content = document.getElementById('article');
      if(!Content) return;      
      var ListeBandeaux = new Array();
      var NewBandeau = document.createElement('div');
      NewBandeau.className = "plainlinks bandeau-niveau-ebauche bandeau";
      NewBandeau.innerHTML = '<table id="TableBandeau_0" style="background-color: transparent; display: block;"></table>';
      if( (skin=="monobook")||(skin=="chick")||(skin=="myskin")||(skin=="simple")||(skin=="vector") ){
            var ContentSub = document.getElementById('contentSub');
            Content.insertBefore(NewBandeau, ContentSub.nextSibling);
      }else if(skin=="modern"){ 
            var ContentSub = Content.firstChild;
            Content.insertBefore(NewBandeau, ContentSub.nextSibling);
      }else if(skin=="cologneblue"){
            var ContentSub = Content.getElementsByTagName('p')[0];
            Content.insertBefore(NewBandeau, ContentSub.nextSibling);
      }else if(skin=="standard"){
            var ContentSub = document.getElementById('catlinks');
            Content.insertBefore(NewBandeau, ContentSub.nextSibling);
      }else if(skin=="nostalgia"){
            Content.insertBefore(NewBandeau, Content.firstChild);
      }
      BandeauxEbauches_ModifyBandeau(0, ListeBandeaux);
}
 
function BandeauxEbauches_ModifyBandeau(BandeauCount, ListeBandeaux){
      var Table = document.getElementById('TableBandeau_'+BandeauCount);
      Table.style.display = "none";
      var NewDivBandeau = document.createElement('div');
      NewDivBandeau.id = 'DivBandeau_'+BandeauCount;
      Table.parentNode.insertBefore(NewDivBandeau, Table);
      var Liste = ''      
      var AllBandeaux = new Array();
      for(var a=0;a<BandeauxEbauches_MaxParams;a++){
            if(ListeBandeaux[a]){
                  AllBandeaux[a] = ListeBandeaux[a];
                  Liste += 'SPLIT'+ ListeBandeaux[a];
            }else{
                  AllBandeaux[a] = '';
            }
      }
      Liste = encodeURIComponent(Liste.replace(/'/g, "\\'"));
      var Boutons = '<input type="button" onclick="BandeauxEbauches_Edit(\''+BandeauCount+'\',\''+Liste+'\');" onselect="BandeauxEbauches_Edit(\''+BandeauCount+'\',\''+Liste+'\');" value="Valider"/>'
                  + '<input type="button" onclick="BandeauxEbauches_Cancel(\''+BandeauCount+'\',\''+Liste+'\')" onselect="BandeauxEbauches_Cancel(\''+BandeauCount+'\')" value="Annuler"/>';
      var Explication = '<strong><label for"FormBandeau_'+BandeauCount+'">Sélectionner les bandeaux d\'ébauche à apposer.</label></strong>';
      if(BandeauxEbauches_ListeBas){ 
            var TopForme = Explication + '&nbsp;&nbsp;' + Boutons;
            var BottomForme = '';
      }else{
            var TopForme = '';
            var BottomForme = Explication + '&nbsp;&nbsp;' + Boutons;
      }
      var NewDivBandeauHTML = '<form id="FormBandeau_'+BandeauCount+'">';
      NewDivBandeauHTML += TopForme + '<br/>';
      for(var a=0;a<BandeauxEbauches_MaxParams;a++){
           NewDivBandeauHTML += '<select id="SelectBandeau_'+BandeauCount+'_'+a+'" style="display:none;" title="Suggestions de bandeaux" />'
                              + '<input id="InputBandeau_'+BandeauCount+'_'+a+'" type="text" value="'+AllBandeaux[a]+'" onkeyup="BandeauxEbauches_TextChanged('+BandeauCount+','+a+')" />';
      }
      NewDivBandeauHTML += '<br/>' + BottomForme ;
      NewDivBandeauHTML += '</form>';
      NewDivBandeau.innerHTML = NewDivBandeauHTML;
      document.getElementById('InputBandeau_0_0').focus();
      for(var a=0;a<ListeBandeaux.length;a++){
            BandeauxEbauches_TextChanged(BandeauCount,a);
      }
}
 
function BandeauxEbauches_Cancel(id, Liste){
      var BandeauTable = document.getElementById('TableBandeau_'+id);
      BandeauTable.style.display = 'block';
      var BandeauDiv = document.getElementById('DivBandeau_'+id);
      BandeauDiv.parentNode.removeChild(BandeauDiv);
      if(Liste=='')BandeauTable.parentNode.parentNode.removeChild(BandeauTable.parentNode);
}
 
 
////////////////////////////////////////////////////////////////////////////////////////// SUGGESTIONS
 
var BandeauxEbauches_TextChanged_running = new Array ;
for(var run=0;run<BandeauxEbauches_MaxParams;run++){
     BandeauxEbauches_TextChanged_running[run] = 0;
}
var  BandeauxEbauches_Edit_running = 0;
 
function BandeauxEbauches_TextChanged(id1, id2){
     if( ( BandeauxEbauches_TextChanged_running[id2])||(BandeauxEbauches_Edit_running) ) return ;
     var idSelect= 'SelectBandeau_' + id1 + '_' + id2;
     var idInput = 'InputBandeau_' + id1 + '_' + id2;
     var Select = document.getElementById(idSelect ) ;
     var Input = document.getElementById(idInput) ;
     if((!Input)||(!Select)) return;     
     var Value = Input.value;
     if(Value==''){ Select.style.display = 'none'; return; }
     BandeauxEbauches_TextChanged_running[id2] = 1; 
     var url = wgServer + wgScriptPath + '/api.php?format=xml&action=query&list=allpages'
             + '&apnamespace=10&aplimit='+BandeauxEbauches_TailleListe+'&apfrom=Ébauche/paramètres%20'+Value; 
     var BandeauxEbauches_Request = sajax_init_object();
     BandeauxEbauches_Request.open("GET", url, true);
     BandeauxEbauches_Request.send(null);
     BandeauxEbauches_Request.onreadystatechange = function() {
          if(BandeauxEbauches_Request.readyState == 4 && BandeauxEbauches_Request.status == 200) {
               Select.innerHTML = ''; 
               var ObjectXML = BandeauxEbauches_Request.responseXML;
               var pages = ObjectXML.getElementsByTagName('p');
               var NbOptions = 0;
               for(var a=0;a<pages.length;a++){
                    var TitrePage = pages[a].getAttribute('title');
                    TitrePage = TitrePage.split('Ébauche/paramètres ')[1];
                    var TitrePageEncode = TitrePage.replace(/'/g,"\\'");
                    Select.innerHTML +=  '<option value="'+TitrePage+'" '
                                        +'onclick="BandeauxEbauches_TextChanged_Set(\''+idInput+'\', \''+TitrePageEncode+'\'); '
                                        +'BandeauxEbauches_TextChanged(\''+id1+'\',\''+id2+'\');" '
                                             +'>'+TitrePage+'</option>';
                    NbOptions++
               }
               if(NbOptions>0){
                    Select.onchange = function(){
                         var Selected = this.getElementsByTagName('option');
                         for(var a=0;a<Selected.length;a++){
                               if(Selected[a].selected){
                                     var TextSelected = Selected[a].value;
                                     document.getElementById(idInput).value = TextSelected;
                                     //setTimeout("BandeauxEbauches_TextChanged(\''+id1+'\', \''+id2+'\');", BandeauxEbauches_KeyboardDelay*1000);
                               } 
                         }
                    } 
                    Select.size = NbOptions;
                    Select.style.display = 'inline';
                    Select.style.zIndex = 5 ;
                    Select.style.position = "absolute" ;
                    Input.style.width = Select.offsetWidth + "px" ; 
                    if(BandeauxEbauches_ListeBas){
                         Select.style.top = (parseInt(Input.offsetTop) + parseInt(Input.offsetHeight)) + 'px';
                    }else{
                         Select.style.top = (parseInt(Input.offsetTop) - Select.offsetHeight) + 'px';
                    }
                    Select.style.left = (parseInt(Input.offsetLeft ) - 1) + 'px';
               }else{
                    Select.style.display = 'none';
                    Select.innerHTML = '';
               }
               for(var a=0;a<BandeauxEbauches_MaxParams;a++){
                    var AllSelect= document.getElementById('SelectBandeau_' + id1 + '_' + a);
                    var AllInput = document.getElementById('InputBandeau_' + id1 + '_' + a); 
                    AllSelect.style.left = (parseInt(AllInput.offsetLeft ) - 1) + 'px'; 
               }
               BandeauxEbauches_TextChanged_running[id2] = 0;
          }
     }
}
 
function BandeauxEbauches_TextChanged_Set(id, text){
     document.getElementById(id).value = text; 
     document.getElementById(id).focus() ;
}
 
////////////////////////////////////////////////////////////////////////////////////////// EDITION 
 
function BandeauxEbauches_Edit(id, OldListe, Supprimer){
 
      OldListe = decodeURIComponent(OldListe).replace(/SPLIT/g, "|");
      var NewModele = '';
      if(!Supprimer){
            NewModele += '{{Ébauche';
            var BandeauForm = document.getElementById('FormBandeau_'+id);
            var Inputs = BandeauForm.getElementsByTagName('input');
            for(var a=0;a<Inputs.length;a++){
                  if(Inputs[a].type == "text"){
                        var InputValue = Inputs[a].value;
                        if(InputValue !=''){
                              NewModele += '|' + InputValue;
                        }
                  }
            }
            NewModele += '}}\n';
            if(NewModele.indexOf('|')==-1){
                   NewModele = '';
            }
      }
      var OldModele = '{{Ébauche' + OldListe + '}}';
      var SurEtCertain = confirm(OldModele + ' -> ' + NewModele + '\n\nOK ?');
      if(!SurEtCertain){ BandeauxEbauches_Cancel(id, OldListe); return; }
      for(var run=0;run<BandeauxEbauches_MaxParams;run++){
            BandeauxEbauches_TextChanged_running[run] = 1;
      }
      BandeauxEbauches_Edit_running = 1;
      var url = wgServer + wgScript + '?title=' + encodeURIComponent(wgPageName) + '&action=edit&section=0';
      var BandeauxEbauches_Request = sajax_init_object();
      BandeauxEbauches_Request.open("GET", url, true);
      BandeauxEbauches_Request.send(null);
      BandeauxEbauches_Request.onreadystatechange = function() {
            if(BandeauxEbauches_Request.readyState == 4 && BandeauxEbauches_Request.status == 200) {
                  while(document.body.firstChild){ document.body.removeChild(document.body.firstChild); } 
                  document.body.innerHTML = BandeauxEbauches_Request.responseText;
                  if(BandeauxEbauches_AutoEdit) document.editform.style.display = 'none';
 
                  var OldText = document.getElementById('wpTextbox1').value;
 
 
                  var OldModeleRegExp = new RegExp('\\{\\{( |_)*(e|é|E|É)bauche( |_)*\\|[^\\}]+\\}\\}', 'g');
 
                  var OldEbaucheMatch = OldText.match(OldModeleRegExp);
                  if(OldEbaucheMatch==null){
                        alert('Modèle d\'ébauche introuvable !')
                        return;
                  }
                  var TexteFinal = OldText;
                  for(var a=0,l=OldEbaucheMatch.length;a<l;a++){
                        TexteFinal = TexteFinal.replace(OldEbaucheMatch[a], (a==0 ? NewModele : ''));
                  }
                  document.getElementById('wpMinoredit').checked = BandeauxEbauches_MinorEdit;
                  document.getElementById('wpTextbox1').value = TexteFinal;
                  document.getElementById('wpSummary').value = 'Changement [[Modèle:Ébauche|{{Ébauche}}]] ; avec [[MediaWiki:Gadget-BandeauxEbauches.js|BandeauxEbauches]]';
                  if(BandeauxEbauches_AutoEdit) document.editform.submit();
            }
      }
}
 
//</nowiki></pre></source>