MediaWiki:Gadget-LiveRC.js/Extensions/BandeauPortail.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) ;

Chrome / Internet Explorer / Opera : maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl-F5.
/* 
 --------------------------------------------------------------------------------------
 ---------LLLL---------III--------------------------RRRRRRRRRR--------CCCCC------------
 ---------LLLL---------III--------------------------RRRRRRRRRRRR----CCCCCCCCC----------
 ---------LLLL--------------------------------------RRR------RRR---CCC-----CCC---------
 ---------LLLL---------III--VV-----VV--EEEEEEEEE----RRR------RRR--CCC------------------
 ---------LLLL---------III---VV---VV---EEE----------RRRRRRRRRRR---CCC------------------
 ---------LLLL---------III---VV---VV---EEEEEE-------RRRRRRRRRR----CCC------------------
 ---------LLLL---------III----VV-VV----EEEEEE-------RRR-----RRR----CCC-----CCC---------
 ---------LLLLLLLLLLL--III----VVVVV----EEE----------RRR------RRR----CCCCCCCCC----------
 ---------LLLLLLLLLLL--III-----VVV-----EEEEEEEEE----RRR-------RRR-----CCCCC------------
 --------------------------------------------------------------------------------------
 
'''Extension de LiveRC'''
 
Permet d'améliorer la prévisualisation avec les fonctions de [[MediaWiki:Gadget-BandeauxPortails.js|BandeauxPortails]]

* Licence : ...?
* Documentation : [[:fr:Projet:Scripts et gadgets/Notices/BandeauxPortails]]
* Auteur : [[:fr:User:Dr Brains]]
* Développement et maintenance :

 
{{Catégorisation JS|LiveRC}}

<syntaxhighlight lang=javascript> */

if (typeof(LiveRC_AddHook)==="function") { // DÉBUT IF 
LiveRC_Config["InstalledLiveRCExtensions"].push("BandeauPortail");
/* ************************************************************************************************************************************************ */

///////////////////////// VARIABLES ////////////////////////////////////////////////////////

//// PARAMÈTRES PERSONNALISABLES ////

window.lrcBandeauPortailVariables = {
     BP_MinoreditState   : "1",        // Modification mineure ( -1 = défaut ; 0 = jamais ; 1 = toujours )
     BP_WatchthisState   : "nochange", // Suivre la page modifiée ( "watch", "unwatch", "preferences", "nochange" )
     BP_suggestion_delay : 200,   // Délai avant les suggestions, en ms
     BP_list_size        : 5,     // Taille de la liste déroulante (en items)
     BP_list_items       : 10,    // Nombre de bandeaux suggérés lors de la recherche (maximum autorisé : 4999 pour les sysop et les bots, 499 pour les autres utilisateurs)
     BP_list_down        : false, // Permet d'afficher la liste de suggestion vers le bas
     BP_ShowInline       : false, // Afficher sur une seule ligne
     BP_autocommit       : true,  // Permet d'enregistrer automatiquement la modification
     BP_SkipRecap        : false  // Ne pas demander de confirmation
}

//// TEXTES ////

lrcTexts["BP_RemoveLinkText"]   = "(–)";
lrcTexts["BP_RemoveLinkTitle"]  = "Supprimer le bandeau de portail";
lrcTexts["BP_RemoveConfirm"]    = "Voulez-vous vraiment supprimer le bandeau de portail";
lrcTexts["BP_AddLinkText"]      = "(+)";
lrcTexts["BP_AddLinkTitle"]     = "Ajouter un bandeau de portail";
lrcTexts["BP_InputOK"]          = "OK";
lrcTexts["BP_InputCancel"]      = "Annuler";
lrcTexts["BP_ModifyLinkText"]   = "(±)";
lrcTexts["BP_ModifyLinkTitle"]  = "Modifier les bandeaux de portail";
lrcTexts["BP_Minoredit"]        = "Édition mineure";
lrcTexts["BP_Watchthis"]        = "Suivre cette page";
lrcTexts["BP_RadioNoChange"]    = "Pas de changement";
lrcTexts["BP_RadioDefault"]     = "Préférences";
lrcTexts["BP_RadioYes"]         = "Oui";
lrcTexts["BP_RadioNo"]          = "Non";
lrcTexts["BP_TemplateRecap"]    = "Nouveau modèle";

UnTranslatedTexts["BP_CommentStart"] = "[[Projet:Scripts et gadgets/Notices/BandeauxPortails|BandeauxPortails]] : ";


// Paramètres de personnalisation
lrcParamDesc['DesclrcBandeauPortailVariables'] = 'Paramètres de l’extension BandeauPortail';
lrcParamDesc['DesclrcBandeauPortailVariables_short'] = 'BandeauPortail';

lrcParamDesc["DescBP_MinoreditState"]   = "Modification mineure";
lrcParamDesc["DescBP_WatchthisState"]   = "Suivre la page modifiée";
lrcParamDesc["DescBP_suggestion_delay"] = "Délai avant les suggestions, en ms";
lrcParamDesc["DescBP_list_size"]        = "Taille de la liste déroulante (en items)";
lrcParamDesc["DescBP_list_items"]       = "Nombre de bandeaux suggérés lors de la recherche (maximum autorisé : 4999 pour les sysop et les bots, 499 pour les autres utilisateurs)";
lrcParamDesc["DescBP_list_down"]        = "Afficher la liste de suggestion vers le bas";
lrcParamDesc["DescBP_ShowInline"]       = "Afficher sur une seule ligne";
lrcParamDesc["DescBP_autocommit"]       = "Publication automatique";
lrcParamDesc["DescBP_SkipRecap"]        = "Ne pas demander de confirmation";

lrcParamDesc["DescBP_RemoveLinkText"]   = "[BandeauPortail] Texte du lien pour supprimer un bandeau de portail";
lrcParamDesc["DescBP_RemoveLinkTitle"]  = "[BandeauPortail] Infobulle du lien pour supprimer un bandeau de portail";
lrcParamDesc["DescBP_RemoveConfirm"]    = "[BandeauPortail] Message de confirmation";
lrcParamDesc["DescBP_AddLinkText"]      = "[BandeauPortail] Texte du lien pour ajouter un bandeau de portail";
lrcParamDesc["DescBP_AddLinkTitle"]     = "[BandeauPortail] Infobulle du lien pour ajouter un bandeau de portail";
lrcParamDesc["DescBP_InputOK"]          = "[BandeauPortail] Texte du bouton de validation";
lrcParamDesc["DescBP_InputCancel"]      = "[BandeauPortail] Texte du bouton d’annulation";
lrcParamDesc["DescBP_ModifyLinkText"]   = "[BandeauPortail] Texte du lien pour modifier les bandeaux de portail";
lrcParamDesc["DescBP_ModifyLinkTitle"]  = "[BandeauPortail] Infobulle du lien pour modifier les bandeaux de portail";
lrcParamDesc["DescBP_CommentStart"]     = "[BandeauPortail] Début du résumé de modification";
lrcParamDesc["DescBP_Minoredit"]        = "[BandeauPortail] Infobulle pour boutons \"Édition mineure\"";
lrcParamDesc["DescBP_Watchthis"]        = "[BandeauPortail] Infobulle pour boutons \"Suivre cette page\"";
lrcParamDesc["DescBP_RadioNoChange"]    = "[BandeauPortail] Infobulle pour boutons : Pas de changement";
lrcParamDesc["DescBP_RadioDefault"]     = "[BandeauPortail] Infobulle pour boutons : Préférences";
lrcParamDesc["DescBP_RadioYes"]         = "[BandeauPortail] Infobulle pour boutons : Oui";
lrcParamDesc["DescBP_RadioNo"]          = "[BandeauPortail] Infobulle pour boutons : Non";
lrcParamDesc["DescBP_TemplateRecap"]    = "[BandeauPortail] Texte \"Nouveau modèle\" dans le récapitulatif";


//// VARIABLES NON PERSONNALISABLES ////

LiveRC_Config["BandeauPortail"] = new Array();

LiveRC_Config["BandeauPortail"]["Matrix"] = {
     Li              : new Array(),
     Form            : new Array(),
     Input           : new Array(),
     Select          : new Array(),
     Exist           : new Array(),
     BandeauName     : new Array(),
     suggest_running : new Array()
}

LiveRC_Config["BandeauPortail"]
LiveRC_Config["BandeauPortail"]["NewBandeauIndex"] = 2000;
LiveRC_Config["BandeauPortail"]["Multi_Edit"] = false ;
LiveRC_Config["BandeauPortail"]["running"] = 0 ;
LiveRC_Config["BandeauPortail"]["last_v"] = "" ;
LiveRC_Config["BandeauPortail"]["last_key"] = "";
LiveRC_Config["BandeauPortail"]["OldDefaultSort"] = "";
LiveRC_Config["BandeauPortail"]["OldPageContent"] = "";
LiveRC_Config["BandeauPortail"]["Form_Index"] = 1000;
LiveRC_Config["BandeauPortail"]["CatNamespace"] = mw.config.get('wgFormattedNamespaces')[14]+':';
LiveRC_Config["BandeauPortail"]["CurrentPage"] = false;
LiveRC_Config["BandeauPortail"]["IsEditMode"] = false;
LiveRC_Config["BandeauPortail"]["NewBandeaux"] = new Array();
LiveRC_Config["BandeauPortail"]["MinorEditStatus"] = false;
LiveRC_Config["BandeauPortail"]["WatchStatus"] = false;

window.lrcBandeauPortailVariables_Custom = new Array(); 
window.Custom_lrcBandeauPortailVariables = new Array(); 
window.LiveRC_getBandeauPortailVariables = function(text){
  if(typeof(lrcBandeauPortailVariables_Custom[text])!="undefined") return lrcBandeauPortailVariables_Custom[text];
  if(typeof(Custom_lrcBandeauPortailVariables[text])!="undefined") return Custom_lrcBandeauPortailVariables[text];
  return lrcBandeauPortailVariables[text];
}

///////////////////////// LANCEMENT ////////////////////////////////////////////////////////

mw.loader.addStyleTag("" +
"#bandeau-portail-form {" +
"  border: solid #AAAAAA 1px;" +
"  padding: 4px;" +
"  background-color: #F9F9F9;" +
"  text-align: center;" +
"  margin-top: 1em;" +
"  margin-left: 0;" +
"  clear: both;" +
"} " +
"#bandeau-portail-form li {display: inline;margin-left:0.5em;margin-right:0.5em; } " +
"#bandeau-portail-form form {display: inline; } "
);


window.lrcRunBandeauPortail = function(data){
    LiveRC_Config["BandeauPortail"]["IsEditMode"] = false;
    LiveRC_Config["BandeauPortail"]["MinorEditStatus"] = LiveRC_getBandeauPortailVariables("BP_MinoreditState");
    LiveRC_Config["BandeauPortail"]["WatchStatus"] = LiveRC_getBandeauPortailVariables("BP_WatchthisState");
    var Preview = document.getElementById("livePreview");
    if(!Preview || !data) return;
    LiveRC_Config["BandeauPortail"]["CurrentPage"] = data.page
    if(getNamespaceInfoFromPage(LiveRC_Config["BandeauPortail"]["CurrentPage"])!=0) return;
    for(var El in LiveRC_Config["BandeauPortail"]["Matrix"]){
        while(LiveRC_Config["BandeauPortail"]["Matrix"][El].length!=0) LiveRC_Config["BandeauPortail"]["Matrix"][El].pop();
    }
    while(LiveRC_Config["BandeauPortail"]["NewBandeaux"].length!=0) LiveRC_Config["BandeauPortail"]["NewBandeaux"].pop();
    var Homonymie = getElementWithId("homonymie", "*", Preview);
    var UlBandeaux = getElementWithId('bandeau-portail', "ul", Preview);
    if( Homonymie && !UlBandeaux) return; 
    if(!UlBandeaux) UlBandeaux = lrcBandeauxPortails_CreateUl(Preview);
    lrcBandeauxPortails_AddLink(UlBandeaux);
    lrcBandeauPortail_getOldPageContent(LiveRC_Config["BandeauPortail"]["CurrentPage"], true);
}
 
window. lrcBandeauPortail_AvoidEditMode = function(){
    LiveRC_Config["BandeauPortail"]["IsEditMode"] = false;
}

////////////////////////////////////////// HOOKS
 
LiveRC_AddHook("AfterPreviewArticle", lrcRunBandeauPortail); 


LiveRC_AddHook("AfterPreviewDiff", lrcBandeauPortail_AvoidEditMode);
LiveRC_AddHook("AfterPreviewHistory", lrcBandeauPortail_AvoidEditMode);
LiveRC_AddHook("AfterPreviewContribs", lrcBandeauPortail_AvoidEditMode);
LiveRC_AddHook("AfterPreviewDeletedContribs", lrcBandeauPortail_AvoidEditMode);
LiveRC_AddHook("AfterPreviewLog", lrcBandeauPortail_AvoidEditMode);
LiveRC_AddHook("AfterPreviewFilter", lrcBandeauPortail_AvoidEditMode);
LiveRC_AddHook("AfterPreviewMove", lrcBandeauPortail_AvoidEditMode);
LiveRC_AddHook("AfterPreviewProtect", lrcBandeauPortail_AvoidEditMode);
LiveRC_AddHook("AfterPreviewDelete", lrcBandeauPortail_AvoidEditMode);
LiveRC_AddHook("AfterPreviewBlock", lrcBandeauPortail_AvoidEditMode);
LiveRC_AddHook("AfterPreviewRevisiondelete", lrcBandeauPortail_AvoidEditMode);
LiveRC_AddHook("AfterPreviewWhatlinkshere", lrcBandeauPortail_AvoidEditMode);
LiveRC_AddHook("AfterPreviewFeedback", lrcBandeauPortail_AvoidEditMode);
LiveRC_AddHook("AfterPreviewStabilization", lrcBandeauPortail_AvoidEditMode);
LiveRC_AddHook("AfterPreviewInterwiki", lrcBandeauPortail_AvoidEditMode);


window.defineCustomBandeauPortailVariable = function(textcode, BandeauPortailVariable){
  if(typeof(lrcBandeauPortailVariables[textcode])!=="undefined")
    Custom_lrcBandeauPortailVariables[textcode] = BandeauPortailVariable;
}
LiveRC_AddHook("AfterFillParamPanel", function(){
    LiveRC_ManageParams_Fill(lrcBandeauPortailVariables, "lrcBandeauPortailVariables");
});

window.lrcBandeauxPortails_TransformOptions = function(){
  var InputsToTransform = new Array();
  var MEOptions = [
   {value:"-1",text:lrcMakeText("BP_RadioDefault")},
   {value:"0",text:lrcMakeText("BP_RadioNo")},
   {value:"1",text:lrcMakeText("BP_RadioYes")}
  ];
  InputsToTransform["BP_MinoreditState"] = MEOptions;
  var WLOptions = [
   {value:"nochange",text:lrcMakeText("BP_RadioNoChange")},
   {value:"preferences",text:lrcMakeText("BP_RadioDefault")},
   {value:"unwatch",text:lrcMakeText("BP_RadioNo")},
   {value:"watch",text:lrcMakeText("BP_RadioYes")}
  ];
  InputsToTransform["BP_WatchthisState"] = WLOptions;
  LiveRC_ManageParams_CheckInputsToTransform(InputsToTransform)
}
LiveRC_AddHook("AfterCreateParamPanel", lrcBandeauxPortails_TransformOptions);



//<syntaxhighlight lang=javascript><pre><nowiki>

window.lrcBandeauxPortails_CreateUl = function(Preview){
      var Bandeau = document.createElement('ul');
      Bandeau.id = 'bandeau-portail';
      Bandeau.className = 'bandeau-portail';
      var CatLinks = getElementWithId('catlinks', 'div', Preview);
      if(CatLinks){
            CatLinks.parentNode.insertBefore(Bandeau,CatLinks);
      }else{
            Preview.appendChild(Bandeau);
      }
      return Bandeau;
}

window.lrcBandeauxPortails_AddLink = function(UlBandeaux){
      var Li = document.createElement('li');
      var Link = document.createElement('a');
      Link.appendChild(document.createTextNode(lrcMakeText("BP_ModifyLinkText")));
      Link.title = lrcMakeText("BP_ModifyLinkTitle");
      Link.href = "javascript:;";
      Link.onclick = function (){
            lrcBandeauxPortails_ModifyUl(lrcBandeauxPortails_CheckBandeaux(LiveRC_Config["BandeauPortail"]["OldPageContent"]));
            return false;
      };
      Li.appendChild(Link);
      UlBandeaux.appendChild(Li);
}

// RÉCUPÉRATION DU CONTENU ACTUEL DE LA PAGE PREVISUALISEE (asynchrone ou synchrone)
 
window.lrcBandeauPortail_getOldPageContent = function(Page, Mode){
    var URL = lrcGetUglyPageURL(Page,'&action=raw');
    wpajax.http({ url: URL, 
                  async : Mode,
                  onSuccess: lrcBandeauPortail_UpdateOldPageContent
    });
}

window.lrcBandeauPortail_UpdateOldPageContent = function(Req, data){
    try{
        LiveRC_Config["BandeauPortail"]["OldPageContent"] = Req.responseText;
    }catch(e){
        LiveRC_Config["BandeauPortail"]["OldPageContent"] = "";
    }
}

window.lrcBandeauxPortails_CheckBandeaux = function(Contenu){
    var Bandeaux = new Array();
    Contenu = Contenu.replace(/\{\{portail/ig, "\{\{Portail");
    Contenu = Contenu.replace(/\{\{Portail /ig, "\{\{Portail\|");
    var Reg = new RegExp("\\{\\{Portail\\|[^\\}]*\\}\\}", "ig")
    var matches = Contenu.match(Reg);
    if(matches!=null){
        for(var a=0,l=matches.length;a<l;a++){
            var ParamsModele = matches[a].split('{{Portail|')[1].split('}}')[0] + '|';
            ParamsModele = lrcBandeauxPortails_CleanModele(ParamsModele);
            while(ParamsModele.indexOf('|')!=-1){
                var NewParam = ParamsModele.split('|')[0];
                if(NewParam!='') Bandeaux.push(NewParam);
                ParamsModele = ParamsModele.split(NewParam+'|')[1];               
            }
        }
    }
    return Bandeaux;
}

// Nettoyage modèle (espaces, retour à la ligne, pipes)
window. lrcBandeauxPortails_CleanModele = function(Modele){
          Modele = Modele.replace(/\n/ig, ""); 
          Modele = Modele.replace(/ \|/ig, "\|");
          Modele = Modele.replace(/\| /ig, "\|");
          Modele = Modele.replace(/\|\|/ig, "\|");
          Modele = Modele.replace(/\|\}/ig, "\}");
          return Modele;
}

///////////////////////// TRANSFORMATIONS ////////////////////////////////////////////////////////

window.lrcBandeauxPortails_ModifyUl = function(Bandeaux){
      var Preview = document.getElementById("livePreview");
      if(!Preview) return;
      var BandeauUl = getElementWithId('bandeau-portail', 'ul', Preview);
      if(!BandeauUl) return;
      var OldBandeauUlForm = getElementWithId('bandeau-portail-form', 'ul', Preview);
      if(OldBandeauUlForm) OldBandeauUlForm.parentNode.removeChild(OldBandeauUlForm);
      for(var El in LiveRC_Config["BandeauPortail"]["Matrix"]){
            while(LiveRC_Config["BandeauPortail"]["Matrix"][El].length!=0) LiveRC_Config["BandeauPortail"]["Matrix"][El].pop();
      }
      var BandeauForm = document.createElement('ul');
      BandeauForm.id = 'bandeau-portail-form';
      for(var a=0,l=Bandeaux.length;a<l;a++){
            if(a>2000 || !Bandeaux[a]) continue;
            var NewLI = document.createElement('li');
            BandeauForm.appendChild(NewLI);
            NewLI.appendChild(lrcBandeauxPortails_CreateForm(Bandeaux[a], a));
            LiveRC_Config["BandeauPortail"]["Matrix"].Li[a] = NewLI;
      }
      var Inputs = lrcBandeauxPortails_CreateInputs();
      BandeauForm.appendChild(Inputs);
      BandeauUl.style.display = "none";
      BandeauUl.parentNode.insertBefore(BandeauForm, BandeauUl);
      if(Bandeaux.length==0) lrcBandeauxPortails_AddNewForm(Inputs.getElementsByTagName('input')[0]);
      BandeauForm.getElementsByTagName("input")[0].focus();
}

window.lrcBandeauxPortails_CreateForm = function(Bandeau, Index){
      var Li = document.createElement('li')
      var Form = document.createElement("form");
      Form.onsubmit = function(){
            lrcBandeauPortail_CheckForms();
            return false;
      };
      var Input = document.createElement("input");
      Input.className = "Bandeau_Input";
      Input.type = "text";
      Input.value = Bandeau;
      Input.onkeyup = function () { 
            var FormIndex = lrcBandeauPortail_getIndex(this, LiveRC_Config["BandeauPortail"]["Matrix"].Input);
            window.setTimeout("lrcBandeauPortail_TextChanged("+FormIndex+");", LiveRC_getBandeauPortailVariables("BP_suggestion_delay "));
      }
      var Select = document.createElement('select');
      Select.style.display = "none";
      Select.onclick = function () { 
            var FormIndex = lrcBandeauPortail_getIndex(this, LiveRC_Config["BandeauPortail"]["Matrix"].Select);
            lrcBandeauPortailText_replace(FormIndex);
      }
      var ExistIcon = document.createElement('span');
      ExistIcon.innerHTML = lrcMakeIcon("SuggestNoExistIcon").split("$1").join("").split("  ").join(" ");
      var SupLink = document.createElement('input');
      SupLink.value = lrcMakeText("BP_RemoveLinkText");
      SupLink.title = lrcMakeText("BP_RemoveLinkTitle") + " « "+Bandeau+" »";
      SupLink.type = "button";
      SupLink.onclick = function(){
            lrcBandeauxPortails_DeleteForm(this)
            return false;
      }
      SupLink.onselect = function(){
            lrcBandeauxPortails_DeleteForm(this)
            return false;
      }
      Form.appendChild(Input);
      Form.appendChild(Select);
      Form.appendChild(ExistIcon);
      Form.appendChild(SupLink);
      LiveRC_Config["BandeauPortail"]["Matrix"].Form[Index] = Form;
      LiveRC_Config["BandeauPortail"]["Matrix"].Input[Index] = Input;
      LiveRC_Config["BandeauPortail"]["Matrix"].Select[Index] = Select;
      LiveRC_Config["BandeauPortail"]["Matrix"].Exist[Index] = ExistIcon;
      LiveRC_Config["BandeauPortail"]["Matrix"].BandeauName[Index] = Bandeau;
      LiveRC_Config["BandeauPortail"]["Matrix"]["suggest_running"][Index] = false;
      Li.appendChild(Form);
      lrcBandeauPortail_TextChanged(Index);
      return Li;
}

window.lrcBandeauxPortails_CreateInputs = function(){
      var Li = document.createElement("li");
      var Form = document.createElement("form");
      Form.style.display = "inline";
      Form.onsubmit = function(){
            return false;
      };
      var AddInput = document.createElement('input');
      AddInput.value = lrcMakeText("BP_AddLinkText");
      AddInput.title = lrcMakeText("BP_AddLinkTitle");
      AddInput.type = "button";
      AddInput.onclick = function (){
            lrcBandeauxPortails_AddNewForm(this);
            return false;
      };
      AddInput.onselect = function (){
            lrcBandeauxPortails_AddNewForm(this);
            return false;
      };
      var OKInput = document.createElement("input");
      OKInput.type = "button";
      OKInput.value = lrcMakeText("BP_InputOK");
      OKInput.onclick = function(){
            lrcBandeauPortail_CheckForms();
      };
      OKInput.onselect = function(){
            lrcBandeauPortail_CheckForms();
      };
      var CancelInput = document.createElement("input");
      CancelInput.type = "button";
      CancelInput.value = lrcMakeText("BP_InputCancel");
      CancelInput.onclick = function(){
            lrcBandeauPortail_CloseForms();
      };
      CancelInput.onselect = function(){
            lrcBandeauPortail_CloseForms();
      };
      Form.appendChild(AddInput);
      if(!LiveRC_getBandeauPortailVariables("BP_ShowInline")) Form.appendChild(document.createElement("br"));
      Form.appendChild(OKInput);
      Form.appendChild(CancelInput);
      Form.appendChild(lrcBandeauxPortails_CreateMinoreditAndWatchthisButtons());
      Li.appendChild(Form);
      return Li;
}

window.lrcBandeauxPortails_CreateMinoreditAndWatchthisButtons = function(){
  var Span = document.createElement('span');
  Span.id = "lrcBandeauxPortails_RadioBoxes";

  var MinorValue = LiveRC_Config["BandeauPortail"]["MinorEditStatus"];
  var WatchValue = LiveRC_Config["BandeauPortail"]["WatchStatus"];
 
  var MinorOneChecked =   ( (MinorValue=="-1") ? 'checked="checked" ' : '' );
  var MinorTwoChecked =   ( (MinorValue=="0")  ? 'checked="checked" ' : '' );
  var MinorThreeChecked = ( (MinorValue=="1")  ? 'checked="checked" ' : '' );
  var WatchOneChecked =   ( (WatchValue=="preferences") ? 'checked="checked" ' : '' );
  var WatchTwoChecked =   ( (WatchValue=="unwatch")     ? 'checked="checked" ' : '' );
  var WatchThreeChecked = ( (WatchValue=="watch")       ? 'checked="checked" ' : '' );
  var WatchFourChecked =  ( (WatchValue=="nochange")    ? 'checked="checked" ' : '' );

  var RadioBox = '&nbsp;&nbsp;'
               + '<span style="border:1px dotted silver;padding:0.2em;padding-top:0.5em">'
               + '<label for="MinorEditStatus">'+lrcMakeText("BP_Minoredit")+'</label>'
               + '&nbsp;'
               + '<input value="-1" type="radio" name="MinorEditStatus" '+MinorOneChecked+' style="cursor:pointer;" '
               + 'title="'+lrcMakeText("BP_Minoredit")+' : '+lrcMakeText("BP_RadioDefault")+'" />'
               + '<input value="0" type="radio" name="MinorEditStatus" '+MinorTwoChecked+' style="cursor:pointer;" '
               + 'title="'+lrcMakeText("BP_Minoredit")+' : '+lrcMakeText("BP_RadioNo")+'" />'
               + '<input value="1" type="radio" name="MinorEditStatus" '+MinorThreeChecked+' style="cursor:pointer;" '
               + 'title="'+lrcMakeText("BP_Minoredit")+' : '+lrcMakeText("BP_RadioYes")+'" />'
               + '</span>'
               + '&nbsp;&nbsp;'
               + '<span style="border:1px dotted silver;padding:0.2em;padding-top:0.5em">'
               + '<label for="WatchStatus">'+lrcMakeText("BP_Watchthis")+'</label>'
               + '&nbsp;'
               + '<input value="preferences" type="radio" name="WatchStatus" '+WatchOneChecked+' style="cursor:pointer;" '
               + 'title="'+lrcMakeText("BP_Watchthis")+' : '+lrcMakeText("BP_RadioDefault")+'" />'
               + '<input value="unwatch" type="radio" name="WatchStatus" '+WatchTwoChecked+' style="cursor:pointer;" '
               + 'title="'+lrcMakeText("BP_Watchthis")+' : '+lrcMakeText("BP_RadioNo")+'" />'
               + '<input value="watch" type="radio" name="WatchStatus" '+WatchThreeChecked+' style="cursor:pointer;" '
               + 'title="'+lrcMakeText("BP_Watchthis")+' : '+lrcMakeText("BP_RadioYes")+'" />'
               + '<input value="nochange" type="radio" name="WatchStatus" '+WatchFourChecked+' style="cursor:pointer;" '
               + 'title="'+lrcMakeText("BP_Watchthis")+' : '+lrcMakeText("BP_RadioNoChange")+'" />'
               + '</span>'
  Span.innerHTML = RadioBox;
  return Span;
}  

window.lrcBandeauxPortails_DeleteForm = function(Input){
      var ThisForm = Input.parentNode;
      var FormIndex = lrcBandeauPortail_getIndex(ThisForm, LiveRC_Config["BandeauPortail"]["Matrix"].Form);
      var Text = lrcMakeText("BP_RemoveConfirm") + " « "+LiveRC_Config["BandeauPortail"]["Matrix"].BandeauName[FormIndex]+" »"
      var ConfirmFunction = function(){
            var ThisLi = ThisForm.parentNode;
            ThisLi.parentNode.removeChild(ThisLi);
      }
      if(LiveRC_getBandeauPortailVariables("BP_SkipRecap")){
            ConfirmFunction();
      }else{
            LiveRC_confirm(Text, ConfirmFunction);
      }
}

window.lrcBandeauxPortails_AddNewForm = function(Input){
      LiveRC_Config["BandeauPortail"]["NewBandeauIndex"]++;
      var Li = Input.parentNode.parentNode;
      var NewLi = document.createElement('li');
      Li.parentNode.insertBefore(NewLi, Li);
      NewLi.appendChild(lrcBandeauxPortails_CreateForm("", LiveRC_Config["BandeauPortail"]["NewBandeauIndex"]));
      LiveRC_Config["BandeauPortail"]["Matrix"].Li[LiveRC_Config["BandeauPortail"]["NewBandeauIndex"]] = NewLi;
}

window.lrcBandeauPortail_CloseForms = function(){
      var Preview = document.getElementById("livePreview");
      if(!Preview) return;
      var BandeauUl = getElementWithId('bandeau-portail', 'ul', Preview);
      if(!BandeauUl) return;
      var OldBandeauUlForm = getElementWithId('bandeau-portail-form', 'ul', Preview);
      if(OldBandeauUlForm) OldBandeauUlForm.parentNode.removeChild(OldBandeauUlForm);
      BandeauUl.style.display = "";
}

////////////////////////////////////////////////////// SUGGESTIONS


window.lrcBandeauPortail_TextChanged = function(FormIndex){
    if ( LiveRC_Config["BandeauPortail"]["Matrix"]["suggest_running"][FormIndex] ) return ;
    var text = LiveRC_Config["BandeauPortail"]["Matrix"].Input[FormIndex];
    var v = text.value ;
    if(v==="") return;
    LiveRC_Config["BandeauPortail"]["Matrix"]["suggest_running"][FormIndex] = true ;
    var APILimit = LiveRC_Config["UserInfos"].APIlimit;
    if(LiveRC_getBandeauPortailVariables("BP_list_items")>APILimit) lrcBandeauPortailVariables_Custom.list_items = APILimit; // API max
    var URL =  lrcGetAPIURL('format=xml&action=query&generator=allpages&gapnamespace=10')
            + '&gaplimit='+LiveRC_getBandeauPortailVariables("BP_list_items")
            + '&gapfrom=Portail%20'+encodeURIComponent(v)
            + '&prop=info';
    wpajax.http({ url: URL, 
                  onSuccess: lrcBandeauPortailText_changed_getSuggests,
                  index:FormIndex
    });
}

window.lrcBandeauPortailText_changed_getSuggests = function(Req, data){
    var xml = Req.responseXML ;
    if ( xml == null ) return ;
    var titles = new Array();
    var isredirect = new Array();
    var pages = xml.getElementsByTagName("page") ;
    for( var i=0,l=pages.length;i<l;i++) {
        var s = pages[i].getAttribute("title").replace(/Modèle:Portail /, "");
        titles.push ( s ) ;
        var R = pages[i].getAttribute("redirect");
        var Redirect = (R==null ? false : true);
        isredirect.push(Redirect);
    }
    lrcBandeauPortail_show_suggestions(titles, isredirect, data.index) ;
    LiveRC_Config["BandeauPortail"]["Matrix"]["suggest_running"][data.index] = false ;
}

// AFFICHAGE DES SUGGESTIONS

window.lrcBandeauPortail_show_suggestions  = function(titles, isredirect, FormIndex) {
    var text = LiveRC_Config["BandeauPortail"]["Matrix"].Input[FormIndex] ;
    var list = LiveRC_Config["BandeauPortail"]["Matrix"].Select[FormIndex] ;
    var ExistIcon = LiveRC_Config["BandeauPortail"]["Matrix"].Exist[FormIndex];
    if(titles.length==0){
        list.style.display = "none" ;
        ExistIcon.innerHTML = lrcMakeIcon("SuggestNoExistIcon").split("$1").join("").split("  ").join(" ");
        return ;
    }  
    var TailleListe = LiveRC_getBandeauPortailVariables("BP_list_size");
    if (titles.length < TailleListe ) TailleListe = titles.length;
    var listh = TailleListe * 20 ;
    list.size = TailleListe ;
    list.style.align = "left" ;
    list.style.zIndex = 5 ;
    list.style.position = "relative" ;
    list.style.width = text.offsetWidth + "px" ;
    list.style.height = listh + "px" ;
    if (LiveRC_getBandeauPortailVariables("BP_list_down")) {
        list.style.top = parseInt(text.offsetHeight) + "px";
        list.style.marginBottom = "-" + ((TailleListe * 20) + parseInt(text.offsetHeight)) + "px" ;
    }else{
        list.style.marginTop = "-" + (TailleListe * 20) + "px" ;
    }
    list.style.marginLeft = "-" + text.offsetWidth + "px" ;

    while ( list.firstChild ) list.removeChild ( list.firstChild ) ;
    for ( var i = 0 ; i < titles.length ; i++ ) {
        var opt = document.createElement ( "option" ) ;
        var ot = document.createTextNode ( titles[i] ) ;
        opt.appendChild ( ot ) ;
        opt.value = titles[i];
        list.appendChild ( opt ) ;
        if(isredirect[i]) opt.setAttribute('style', 'font-style:italic !important;');
    }  
    list.onkeyup = lrcBandeauPortail_KeypressedOnList;
    list.style.display = "inline" ;
    var first_title = titles.shift () ;
    LiveRC_Config["BandeauPortail"]["last_v"] = text.value;
    ExistIcon.innerHTML = lrcMakeIcon("SuggestExistIcon").split("$1").join("Modèle:Portail "+first_title);
    if ( first_title == LiveRC_Config["BandeauPortail"]["last_v"] ) return ;
    var suggestion = first_title;
    if (text.createTextRange) {
        var ra = text.createTextRange();
        ra.moveStart("character", LiveRC_Config["BandeauPortail"]["last_v"].length);
        ra.moveEnd("character", suggestion.length);
        ra.select();
    } else if( text.setSelectionRange ) {
        text.setSelectionRange( LiveRC_Config["BandeauPortail"]["last_v"].length, suggestion.length );
    } else {
        text.selectionStart = LiveRC_Config["BandeauPortail"]["last_v"].length ;
        text.selectionEnd = suggestion.length ;
    }
}

// SÉLECTION D'UNE SUGGESTION AU CLAVIER

window.lrcBandeauPortail_KeypressedOnList = function(e){
    if (!e) var e = window.event;
    if (e.keyCode != 13) return;
    lrcBandeauPortailText_replace(lrcBandeauPortail_getIndex(this, LiveRC_Config["BandeauPortail"]["Matrix"].Select))
}

// REMPLACEMENT DU CHAMP DE TEXTE PAR UNE SUGGESTION

window.lrcBandeauPortailText_replace = function(Index){
    var Text = LiveRC_Config["BandeauPortail"]["Matrix"].Input[Index];
    var TextValue = Text.value;
    var List = LiveRC_Config["BandeauPortail"]["Matrix"].Select[Index];
    var Options = List.getElementsByTagName('option');
    for(var a=0;a<Options.length;a++){
        if(Options[a].selected){
            var ListValue = Options[a].value;
            Text.value = ListValue;
            lrcBandeauPortail_TextChanged(Index) ;
            Text.focus();
            return;
        }
    }
}

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

// VALIDATION DU FORMULAIRE + LISTING DES BANDEAUX À ENLEVER/MODIFIER/AJOUTER 

window.lrcBandeauPortail_CheckForms = function(){
      var Preview = document.getElementById("livePreview");
      if(!Preview) return;
      var OldBandeauUlForm = getElementWithId('bandeau-portail-form', 'ul', Preview);
      var RadioBoxes = document.getElementById("lrcBandeauxPortails_RadioBoxes");
      if(!OldBandeauUlForm || !RadioBoxes) return;
      while(LiveRC_Config["BandeauPortail"]["NewBandeaux"].length!=0) LiveRC_Config["BandeauPortail"]["NewBandeaux"].pop();
      var Inputs = lrcGetElementsByClass("Bandeau_Input", OldBandeauUlForm, "input");
      if(Inputs.length==0) return;
      for(var a=0,l=Inputs.length;a<l;a++){
            if(Inputs[a].value!="") LiveRC_Config["BandeauPortail"]["NewBandeaux"].push(Inputs[a].value);
      }
      var RecapText = "<ul>"+ lrcMakeText("BP_TemplateRecap")+" : "
                      +"<li>{{Portail|"+LiveRC_Config["BandeauPortail"]["NewBandeaux"].join("|")+"}}</li>"
                      +"</ul>";

      var RadioNameTexts = {"MinorEditStatus":"BP_Minoredit","WatchStatus":"BP_Watchthis"};
      var RadioValueTexts = {"watch":"BP_RadioYes","unwatch":"BP_RadioNo","preferences":"BP_RadioDefault","nochange":"BP_RadioNoChange","1":"BP_RadioYes","0":"BP_RadioNo","-1":"BP_RadioDefault"};

      var Radios = RadioBoxes.getElementsByTagName('input');
      for(var a=0,l=Radios.length;a<l;a++){
          var Radio = Radios[a];
          if(Radio.type!="radio") continue;
          if(!Radio.checked) continue;
          var BoxName = Radio.name;
          var Value = Radio.value;
          LiveRC_Config["BandeauPortail"][BoxName] = Value;
          RecapText += "<ul>"+lrcMakeText(RadioNameTexts[BoxName])+" : "
                     + "<li>"+lrcMakeText(RadioValueTexts[Value]) + "</li>"
                     +"</ul>";
      }
      var LaunchEditFunction = function(){
        LiveRC_Config["BandeauPortail"]["IsEditMode"] = true;
        liveEdit(LiveRC_Config["BandeauPortail"]["CurrentPage"]);
      }
      if(LiveRC_getBandeauPortailVariables("BP_SkipRecap")){
            LaunchEditFunction();
      }else{
            LiveRC_confirm(RecapText, LaunchEditFunction);
      }
}

window.lrcBandeauPortail_DoEdit = function(){
    var Preview = document.getElementById("livePreview");
    if(!Preview || !LiveRC_Config["BandeauPortail"]["IsEditMode"]) return;
    var TextArea = getElementWithId('wpTextbox1', 'textarea', Preview);
    if(!TextArea) return;
    if(LiveRC_getBandeauPortailVariables("BP_autocommit")) getElementWithId('editform', 'form', Preview).style.display = "none";
    var prevent_autocommit = 0;
    var NewTemplate = "{{Portail|"+LiveRC_Config["BandeauPortail"]["NewBandeaux"].join("|")+"}}";
    var OldText = TextArea.value;
    OldText = OldText.replace(/\{\{portail/ig, "\{\{Portail");
    OldText = OldText.replace(/\{\{Portail /ig, "\{\{Portail\|");
    var Reg = new RegExp("\\{\\{Portail\\|[^\\}]*\\}\\}", "ig")
    var matches = OldText.match(Reg);
    if(matches!=null){
        var Replaced = false;
        for(var a=0,l=matches.length;a<l;a++){
            if(Replaced){
                OldText = OldText.replace(matches[a], "");
            }else{
                OldText = OldText.replace(matches[a], NewTemplate);
                Replaced = true;
            }
        }
    }else{          
        if((OldText.indexOf('{{DEFAULTSORT:')!=-1)||(OldText.indexOf('[[Catégorie:')!=-1)||(OldText.indexOf('[[catégorie:')!=-1)||(OldText.indexOf('[[Categorie:')!=-1)||(OldText.indexOf('[[categorie:')!=-1)){
// ------------------------------------------------------------------------------------ Il y a des catégories
            var DebutModele1 = OldText.substring(0, OldText.indexOf('{{DEFAULTSORT:'));
            var DebutModele2 = OldText.substring(0, OldText.indexOf('[[Catégorie:'));
            var DebutModele3 = OldText.substring(0, OldText.indexOf('[[catégorie:'));
            var DebutModele4 = OldText.substring(0, OldText.indexOf('[[Categorie:'));
            var DebutModele5 = OldText.substring(0, OldText.indexOf('[[categorie:'));    
            var SuiteModele = OldText.split(DebutModele1).join('').split(DebutModele2).join('').split(DebutModele3).join('').split(DebutModele4).join('').split(DebutModele5).join('')      
               var DebutModele = OldText.split(SuiteModele).join('');
        }else{
// ------------------------------------------------------------------------------------ Il n'y a pas de catégories 
            var interWiki = new RegExp('^\\s*\\[\\[([a-z][a-z].?(x?-[^\\]]+)?|simple|tokipona):([^\\]]*)\\]\\]\\s*$');
            var blank = new RegExp('^\\s*$');
            var lines = OldText.split('\n');
            var DebutModele = '';
            var SuiteModele = '';
            for (var lineId = lines.length - 1; lineId >= 0; --lineId){
                if (!interWiki.test(lines[lineId]) && !blank.test(lines[lineId])){
                    DebutModele = lines.slice(0, lineId + 1).join('\n') + '\n\n';
                    SuiteModele = lines.slice(lineId + 1).join('\n');
                    break;
                }
            }
            if (DebutModele === '') {
                // edge case: source has nothing else than interwikis
                SuiteModele = OldText;
            }
            while(SuiteModele.indexOf('\n\n')!=-1){
                SuiteModele = SuiteModele.split("\n\n").join("\n");
            }
            SuiteModele = SuiteModele.replace(/^\n/, "");
        }
        OldText = DebutModele + NewTemplate + SuiteModele;
    } 
    var Summary = lrcMakeText("RESUMESTART") +lrcMakeText("BP_CommentStart")+NewTemplate;
    var IsMinor = LiveRC_Config["BandeauPortail"]["MinorEditStatus"];
    var MinorEditCheckBox = getElementWithId("wpMinoredit", "input", Preview); 
    var MustWatchthis  = LiveRC_Config["BandeauPortail"]["WatchStatus"];
    var WathThisCheckBox = getElementWithId("wpWatchthis", "input", Preview);
    getElementWithId("wpTextbox1", "textarea", Preview).value = OldText;
    getElementWithId("wpSummary", "input", Preview).value = Summary;
    if(IsMinor==="1") MinorEditCheckBox.checked = true;
    if(IsMinor==="0") MinorEditCheckBox.checked = false;
    if(MustWatchthis=="watch") WathThisCheckBox.checked = true;
    if(MustWatchthis=="unwatch") WathThisCheckBox.checked = false;
    if(MustWatchthis=="nochange") WathThisCheckBox.checked = !!(LiveRC_Config["Suivi"][LiveRC_Config["BandeauPortail"]["CurrentPage"]]);
    if((LiveRC_getBandeauPortailVariables("BP_autocommit"))&&(prevent_autocommit != 1)){
        var Input = getElementWithId("Live_wpSave", "input", Preview);
        if(Input){
          var Params = getFormParams(Preview);
          var EditParam = new Array();
          EditParam["token"] = document.getElementsByName("wpEditToken")[0].value;
          EditParam["text"] = OldText;
          EditParam["summary"] = Summary;
          EditParam["title"] = LiveRC_Config["BandeauPortail"]["CurrentPage"];
          EditParam["watchlist"] = MustWatchthis;
          EditParam[((MinorEditCheckBox.checked ? "" : "not")+"minor")] = "1";
          EditParam["nocreate"] = "1";
          var ParamsInURL = new Array();
          for(var P in EditParam){
            if(typeof(EditParam[P])=="string") ParamsInURL.push(P+"="+encodeURIComponent(EditParam[P]));
          }
          ParamsInURL  = ParamsInURL.join("&")+"&wpSave=1";
          var action = lrcGetAPIURL('action=edit');
          var headers = new Array();
          headers['Content-Type'] = 'application/x-www-form-urlencoded';
          wpajax.http({ url: action,
                        method: "POST",
                        headers: headers,
                        data: ParamsInURL,
                        onSuccess:lrcBandeauPortail_EditDone,
                        page:EditParam["title"]
          });
        }else{
            prevent_autocommit = 1;
        }
    }
    if(prevent_autocommit == 1) getElementWithId("editform", "form", Preview).style.display = "";
    LiveRC_Config["BandeauPortail"]["IsEditMode"] = false;
}
LiveRC_AddHook("AfterPreviewEdit", lrcBandeauPortail_DoEdit);

window.lrcBandeauPortail_EditDone = function(Req, data){
  var Page = data.page;  
  liveArticle(Page);
}

///////////////////////// DIVERS ////////////////////////////////////////////////////////

// RÉCUPÉRATION DU N° D'INDEX

window.lrcBandeauPortail_getIndex = function( Element, TheArray ){
    for(var a in TheArray){
        if(Element === TheArray[a]) return a;
    }
    return null;
}

// PREMIÈRE LETTRE EN MAJUSCULE

String.prototype.ucFirst = function () {
    return this.substr(0,1).toUpperCase() + this.substr(1,this.length);
}

// PREMIÈRE LETTRE EN MINUSCULE

String.prototype.lcFirst = function () {
    return this.substr(0,1).toLowerCase() + this.substr(1,this.length);
}

/* ************************************************************************************************************************************************ */
} // FIN IF
//</syntaxhighlight>