/*
--------------------------------------------------------------------------------------
---------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 ]
* Licence : ...?
* Documentation : ]
* Auteur : ]
* Développement et maintenance :
{{Catégorisation JS|LiveRC}}
<source lang=javascript> */
if (typeof(lrcHooks)!="undefined") { // DÉBUT IF
///////////////////////// VARIABLES ////////////////////////////////////////////////////////
//// PARAMÈTRES PERSONNALISABLES ////
var 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 = "(–)";
lrcTexts = "Supprimer le bandeau de portail";
lrcTexts = "Voulez-vous vraiment supprimer le bandeau de portail";
lrcTexts = "(+)";
lrcTexts = "Ajouter un bandeau de portail";
lrcTexts = "OK";
lrcTexts = "Annuler";
lrcTexts = "(±)";
lrcTexts = "Modifier les bandeaux de portail";
lrcTexts = "Édition mineure";
lrcTexts = "Suivre cette page";
lrcTexts = "Pas de changement";
lrcTexts = "Préférences";
lrcTexts = "Oui";
lrcTexts = "Non";
lrcTexts = "Nouveau modèle";
UnTranslatedTexts = "] : ";
// Paramètres de personnalisation
lrcParamDesc = 'Paramètres de l’extension BandeauPortail';
lrcParamDesc = 'BandeauPortail';
lrcParamDesc = "Modification mineure";
lrcParamDesc = "Suivre la page modifiée";
lrcParamDesc = "Délai avant les suggestions, en ms";
lrcParamDesc = "Taille de la liste déroulante (en items)";
lrcParamDesc = "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 = "Afficher la liste de suggestion vers le bas";
lrcParamDesc = "Afficher sur une seule ligne";
lrcParamDesc = "Publication automatique";
lrcParamDesc = "Ne pas demander de confirmation";
lrcParamDesc = " Texte du lien pour supprimer un bandeau de portail";
lrcParamDesc = " Infobulle du lien pour supprimer un bandeau de portail";
lrcParamDesc = " Message de confirmation";
lrcParamDesc = " Texte du lien pour ajouter un bandeau de portail";
lrcParamDesc = " Infobulle du lien pour ajouter un bandeau de portail";
lrcParamDesc = " Texte du bouton de validation";
lrcParamDesc = " Texte du bouton d’annulation";
lrcParamDesc = " Texte du lien pour modifier les bandeaux de portail";
lrcParamDesc = " Infobulle du lien pour modifier les bandeaux de portail";
lrcParamDesc = " Début du résumé de modification";
lrcParamDesc = " Infobulle pour boutons \"Édition mineure\"";
lrcParamDesc = " Infobulle pour boutons \"Suivre cette page\"";
lrcParamDesc = " Infobulle pour boutons : Pas de changement";
lrcParamDesc = " Infobulle pour boutons : Préférences";
lrcParamDesc = " Infobulle pour boutons : Oui";
lrcParamDesc = " Infobulle pour boutons : Non";
lrcParamDesc = " Texte \"Nouveau modèle\" dans le récapitulatif";
//// VARIABLES NON PERSONNALISABLES ////
LiveRC_Config = new Array();
LiveRC_Config = {
Li : new Array(),
Form : new Array(),
Input : new Array(),
Select : new Array(),
Exist : new Array(),
BandeauName : new Array(),
suggest_running : new Array()
}
LiveRC_Config
LiveRC_Config = 2000;
LiveRC_Config = false ;
LiveRC_Config = 0 ;
LiveRC_Config = "" ;
LiveRC_Config = "";
LiveRC_Config = "";
LiveRC_Config = "";
LiveRC_Config = 1000;
LiveRC_Config = mw.config.get('wgFormattedNamespaces')+':';
LiveRC_Config = false;
LiveRC_Config = false;
LiveRC_Config = new Array();
LiveRC_Config = false;
LiveRC_Config = false;
var lrcBandeauPortailVariables_Custom = new Array();
var Custom_lrcBandeauPortailVariables = new Array();
function LiveRC_getBandeauPortailVariables(text){
if(typeof(lrcBandeauPortailVariables_Custom)!="undefined") return lrcBandeauPortailVariables_Custom;
if(typeof(Custom_lrcBandeauPortailVariables)!="undefined") return Custom_lrcBandeauPortailVariables;
return lrcBandeauPortailVariables;
}
///////////////////////// LANCEMENT ////////////////////////////////////////////////////////
importStylesheetURI('//fr.wikipedia.org/w/index.php?title='
+ 'MediaWiki:Gadget-LiveRC.js/Extensions/BandeauPortail.css'
+ '&action=raw&ctype=text/css'
);
function lrcRunBandeauPortail(data){
LiveRC_Config = false;
LiveRC_Config = LiveRC_getBandeauPortailVariables("BP_MinoreditState");
LiveRC_Config = LiveRC_getBandeauPortailVariables("BP_WatchthisState");
var Preview = document.getElementById("livePreview");
if(!Preview || !data) return;
LiveRC_Config = data.page
if(getNamespaceInfoFromPage(LiveRC_Config)!=0) return;
for(var El in LiveRC_Config){
while(LiveRC_Config.length!=0) LiveRC_Config.pop();
}
while(LiveRC_Config.length!=0) LiveRC_Config.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, true);
}
function lrcBandeauPortail_AvoidEditMode(){
LiveRC_Config = 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);
function defineCustomBandeauPortailVariable(textcode, BandeauPortailVariable){
if(typeof(lrcBandeauPortailVariables)!=="undefined")
Custom_lrcBandeauPortailVariables = BandeauPortailVariable;
}
LiveRC_AddHook("AfterFillParamPanel", function(){
LiveRC_ManageParams_Fill(lrcBandeauPortailVariables, "lrcBandeauPortailVariables");
});
function lrcBandeauxPortails_TransformOptions(){
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 = 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 = WLOptions;
LiveRC_ManageParams_CheckInputsToTransform(InputsToTransform)
}
LiveRC_AddHook("AfterCreateParamPanel", lrcBandeauxPortails_TransformOptions);
//<source lang=javascript><pre><nowiki>
function lrcBandeauxPortails_CreateUl(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;
}
function lrcBandeauxPortails_AddLink(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));
return false;
};
Li.appendChild(Link);
UlBandeaux.appendChild(Li);
}
// RÉCUPÉRATION DU CONTENU ACTUEL DE LA PAGE PREVISUALISEE (asynchrone ou synchrone)
function lrcBandeauPortail_getOldPageContent(Page, Mode){
var URL = mw.config.get('wgServer') + mw.config.get('wgScript') + '?title=' + encodeURIComponent(Page) + '&action=raw';
wpajax.http({ url: URL,
async : Mode,
onSuccess: lrcBandeauPortail_UpdateOldPageContent
});
}
function lrcBandeauPortail_UpdateOldPageContent(Req, data){
try{
LiveRC_Config = Req.responseText;
}catch(e){
LiveRC_Config = "";
}
}
function lrcBandeauxPortails_CheckBandeaux(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.split('{{Portail|').split('}}') + '|';
ParamsModele = lrcBandeauxPortails_CleanModele(ParamsModele);
while(ParamsModele.indexOf('|')!=-1){
var NewParam = ParamsModele.split('|');
if(NewParam!='') Bandeaux.push(NewParam);
ParamsModele = ParamsModele.split(NewParam+'|');
}
}
}
return Bandeaux;
}
// Nettoyage modèle (espaces, retour à la ligne, pipes)
function lrcBandeauxPortails_CleanModele(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 ////////////////////////////////////////////////////////
function lrcBandeauxPortails_ModifyUl(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){
while(LiveRC_Config.length!=0) LiveRC_Config.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) continue;
var NewLI = document.createElement('li');
BandeauForm.appendChild(NewLI);
NewLI.appendChild(lrcBandeauxPortails_CreateForm(Bandeaux, a));
LiveRC_Config.Li = 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'));
BandeauForm.getElementsByTagName("input").focus();
}
function lrcBandeauxPortails_CreateForm(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.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.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.Form = Form;
LiveRC_Config.Input = Input;
LiveRC_Config.Select = Select;
LiveRC_Config.Exist = ExistIcon;
LiveRC_Config.BandeauName = Bandeau;
LiveRC_Config = false;
Li.appendChild(Form);
lrcBandeauPortail_TextChanged(Index);
return Li;
}
function lrcBandeauxPortails_CreateInputs(){
var Li = document.createElement("li");
var Form = document.createElement("form");
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);
Form.appendChild(OKInput);
Form.appendChild(CancelInput);
Form.appendChild(lrcBandeauxPortails_CreateMinoreditAndWatchthisButtons());
if(!LiveRC_getBandeauPortailVariables("BP_ShowInline")) Li.appendChild(document.createElement("br"))
Li.appendChild(Form);
return Li;
}
function lrcBandeauxPortails_CreateMinoreditAndWatchthisButtons(){
var Span = document.createElement('span');
Span.id = "lrcBandeauxPortails_RadioBoxes";
var MinorValue = LiveRC_Config;
var WatchValue = LiveRC_Config;
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 = ' '
+ '<span style="border:1px dotted silver;padding:0.2em;padding-top:0.5em">'
+ '<label for="MinorEditStatus">'+lrcMakeText("BP_Minoredit")+'</label>'
+ ' '
+ '<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>'
+ ' '
+ '<span style="border:1px dotted silver;padding:0.2em;padding-top:0.5em">'
+ '<label for="WatchStatus">'+lrcMakeText("BP_Watchthis")+'</label>'
+ ' '
+ '<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;
}
function lrcBandeauxPortails_DeleteForm(Input){
var ThisForm = Input.parentNode;
var FormIndex = lrcBandeauPortail_getIndex(ThisForm, LiveRC_Config.Form);
var Text = lrcMakeText("BP_RemoveConfirm") + " « "+LiveRC_Config.BandeauName+" »"
var ConfirmFunction = function(){
var ThisLi = ThisForm.parentNode;
ThisLi.parentNode.removeChild(ThisLi);
}
if(LiveRC_getBandeauPortailVariables("BP_SkipRecap")){
ConfirmFunction();
}else{
LiveRC_confirm(Text, ConfirmFunction);
}
}
function lrcBandeauxPortails_AddNewForm(Input){
LiveRC_Config++;
var Li = Input.parentNode.parentNode;
var NewLi = document.createElement('li');
Li.parentNode.insertBefore(NewLi, Li);
NewLi.appendChild(lrcBandeauxPortails_CreateForm("", LiveRC_Config));
LiveRC_Config.Li] = NewLi;
}
function lrcBandeauPortail_CloseForms(){
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
function lrcBandeauPortail_TextChanged(FormIndex){
if ( LiveRC_Config ) return ;
var text = LiveRC_Config.Input;
var v = text.value ;
if(v==="") return;
LiveRC_Config = true ;
var APILimit = LiveRC_Config.APIlimit;
if(LiveRC_getBandeauPortailVariables("BP_list_items")>APILimit) lrcBandeauPortailVariables_Custom.list_items = APILimit; // API max
var URL = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?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
});
}
function lrcBandeauPortailText_changed_getSuggests(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.getAttribute("title").replace(/Modèle:Portail /, "");
titles.push ( s ) ;
var R = pages.getAttribute("redirect");
var Redirect = (R==null ? false : true);
isredirect.push(Redirect);
}
lrcBandeauPortail_show_suggestions(titles, isredirect, data.index) ;
LiveRC_Config = false ;
}
// AFFICHAGE DES SUGGESTIONS
function lrcBandeauPortail_show_suggestions (titles, isredirect, FormIndex) {
var text = LiveRC_Config.Input ;
var list = LiveRC_Config.Select ;
var ExistIcon = LiveRC_Config.Exist;
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 ) ;
opt.appendChild ( ot ) ;
opt.value = titles;
list.appendChild ( opt ) ;
if(isredirect) opt.setAttribute('style', 'font-style:italic !important;');
}
list.onkeyup = lrcBandeauPortail_KeypressedOnList;
list.style.display = "inline" ;
var first_title = titles.shift () ;
LiveRC_Config = text.value;
ExistIcon.innerHTML = lrcMakeIcon("SuggestExistIcon").split("$1").join("Modèle:Portail "+first_title);
if ( first_title == LiveRC_Config ) return ;
var suggestion = first_title;
if (text.createTextRange) {
var ra = text.createTextRange();
ra.moveStart("character", LiveRC_Config.length);
ra.moveEnd("character", suggestion.length);
ra.select();
} else if( text.setSelectionRange ) {
text.setSelectionRange( LiveRC_Config.length, suggestion.length );
} else {
text.selectionStart = LiveRC_Config.length ;
text.selectionEnd = suggestion.length ;
}
}
// SÉLECTION D'UNE SUGGESTION AU CLAVIER
function lrcBandeauPortail_KeypressedOnList(e){
if (!e) var e = window.event;
if (e.keyCode != 13) return;
lrcBandeauPortailText_replace(lrcBandeauPortail_getIndex(this, LiveRC_Config.Select))
}
// REMPLACEMENT DU CHAMP DE TEXTE PAR UNE SUGGESTION
function lrcBandeauPortailText_replace(Index){
var Text = LiveRC_Config.Input;
var TextValue = Text.value;
var List = LiveRC_Config.Select;
var Options = List.getElementsByTagName('option');
for(var a=0;a<Options.length;a++){
if(Options.selected){
var ListValue = Options.value;
Text.value = ListValue;
lrcBandeauPortail_TextChanged(Index) ;
Text.focus();
return;
}
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// VALIDATION DU FORMULAIRE + LISTING DES BANDEAUX À ENLEVER/MODIFIER/AJOUTER
function lrcBandeauPortail_CheckForms(){
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.length!=0) LiveRC_Config.pop();
var Inputs = OldBandeauUlForm.querySelectorAll('input.Bandeau_Input');
if(Inputs.length==0) return;
for(var a=0,l=Inputs.length;a<l;a++){
if(Inputs.value!="") LiveRC_Config.push(Inputs.value);
}
var RecapText = "<ul>"+ lrcMakeText("BP_TemplateRecap")+" : "
+"<li>{{Portail|"+LiveRC_Config.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;
if(Radio.type!="radio") continue;
if(!Radio.checked) continue;
var BoxName = Radio.name;
var Value = Radio.value;
LiveRC_Config = Value;
RecapText += "<ul>"+lrcMakeText(RadioNameTexts)+" : "
+ "<li>"+lrcMakeText(RadioValueTexts) + "</li>"
+"</ul>";
}
var LaunchEditFunction = function(){
LiveRC_Config = true;
liveEdit(LiveRC_Config);
}
if(LiveRC_getBandeauPortailVariables("BP_SkipRecap")){
LaunchEditFunction();
}else{
LiveRC_confirm(RecapText, LaunchEditFunction);
}
}
function lrcBandeauPortail_DoEdit(){
var Preview = document.getElementById("livePreview");
if(!Preview || !LiveRC_Config) 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.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, "");
}else{
OldText = OldText.replace(matches, 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*\\.?(x?-]+)?|simple|tokipona):(]*)\\]\\]\\s*$');
var blank = new RegExp('^\\s*$');
var lines = OldText.split('\n');
var DebutModele = '';
var SuiteModele = '';
var FoundInterwiki = false;
for (var lineId = lines.length - 1; lineId >= 0; --lineId){
if (!interWiki.exec(lines) && !blank.exec(lines)){
DebutModele = lines.slice(0, lineId + 1).join('\n');
SuiteModele = lines.slice(lineId + 1).join('\n');
break;
}
}
DebutModele = DebutModele + '\n\n';
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;
var MinorEditCheckBox = getElementWithId("wpMinoredit", "input", Preview);
var MustWatchthis = LiveRC_Config;
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]);
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 = document.getElementsByName("wpEditToken").value;
EditParam = OldText;
EditParam = Summary;
EditParam = LiveRC_Config;
EditParam = MustWatchthis;
EditParam = "1";
EditParam = "1";
var ParamsInURL = new Array();
for(var P in EditParam){
if(typeof(EditParam)=="string") ParamsInURL.push(P+"="+encodeURIComponent(EditParam));
}
ParamsInURL = ParamsInURL.join("&")+"&wpSave=1";
var action = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?action=edit';
var headers = new Array();
headers = 'application/x-www-form-urlencoded';
wpajax.http({ url: action,
method: "POST",
headers: headers,
data: ParamsInURL,
onSuccess:lrcBandeauPortail_EditDone,
page:EditParam
});
}else{
prevent_autocommit = 1;
}
}
if(prevent_autocommit == 1) getElementWithId("editform", "form", Preview).style.display = "";
LiveRC_Config = false;
}
LiveRC_AddHook("AfterPreviewEdit", lrcBandeauPortail_DoEdit);
function lrcBandeauPortail_EditDone(Req, data){
var Page = data.page;
liveArticle(Page);
}
///////////////////////// DIVERS ////////////////////////////////////////////////////////
// RÉCUPÉRATION DU N° D'INDEX
function lrcBandeauPortail_getIndex( Element, TheArray ){
for(var a in TheArray){
if(Element === TheArray) 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
//</source>