MediaWiki:Gadget-BandeauxFaciles.js
Apparence
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}}
************************************************** */
//<syntaxhighlight lang=javascript>//<pre><nowiki>
mw.loader.using(['site', 'user'], function () {
window.editSectionMenu_CodeUrl = [];
window.editSectionMenu_ModeleDebut = [];
window.editSectionMenu_ModeleParametres = [];
////////////////////////////////////////////////////////////////// PARTIE PERSONNALISABLE ////////////////////////////////////////////
// Publication automatique
if (window.editSectionMenu_Autosubmit === undefined) {
window.editSectionMenu_Autosubmit = true;
}
var now = new Date();
var moisAnnee = now.toLocaleString('fr-FR', {month: 'long', year: 'numeric'});
window.editSectionMenu_Pop = "Cliquer pour ajouter : ";
window.editSectionMenu_Enrouler = "-";
window.editSectionMenu_EnroulerPop = "Cliquer pour enrouler le menu Bandeaux";
window.editSectionMenu_Derouler = "+";
window.editSectionMenu_DeroulerPop = "Cliquer pour dérouler le menu Bandeaux";
window.editSectionMenu_CodeUrl.push("&vide=1");
window.editSectionMenu_ModeleDebut.push("{{...");
window.editSectionMenu_ModeleParametres.push("non");
window.editSectionMenu_CodeUrl.push("&ebauche=Tous");
window.editSectionMenu_ModeleDebut.push("{{Ébauche");
window.editSectionMenu_ModeleParametres.push("oui");
window.editSectionMenu_CodeUrl.push("&wikifier=1");
window.editSectionMenu_ModeleDebut.push("{{À wikifier|date=" + moisAnnee);
window.editSectionMenu_ModeleParametres.push("non");
window.editSectionMenu_CodeUrl.push("&admissibilite=1");
window.editSectionMenu_ModeleDebut.push("{{Admissibilité à vérifier|date=" + moisAnnee);
window.editSectionMenu_ModeleParametres.push("non");
window.editSectionMenu_CodeUrl.push("&sources=1");
window.editSectionMenu_ModeleDebut.push("{{à sourcer|date=" + moisAnnee);
window.editSectionMenu_ModeleParametres.push("non");
window.editSectionMenu_CodeUrl.push("&sourcesect=1");
window.editSectionMenu_ModeleDebut.push("{{Section à sourcer");
window.editSectionMenu_ModeleParametres.push("non");
window.editSectionMenu_CodeUrl.push("&anecdotes=1");
window.editSectionMenu_ModeleDebut.push("{{Anecdotes");
window.editSectionMenu_ModeleParametres.push("non");
window.editSectionMenu_CodeUrl.push("&promotionnel=1");
window.editSectionMenu_ModeleDebut.push("{{Promotionnel");
window.editSectionMenu_ModeleParametres.push("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 ) {
$( BandeauxFaciles_makeButtons );
}
if ( mw.config.get( 'wgAction' ) === 'edit' ) {
$( BandeauxFaciles_doEdit );
}
// -------------------------------------------------------------------- Ajout des liens
function BandeauxFaciles_makeButtons(){
if(typeof(BandeauxFaciles_SiteCustom)==="function") BandeauxFaciles_SiteCustom();
if(typeof(BandeauxFaciles_UserCustom)==="function") BandeauxFaciles_UserCustom();
var SousTitre = document.getElementById('siteSub'); // En-tête
BandeauxFaciles_makeEditSectionMenu(SousTitre, 0);
var EditSections = document.querySelectorAll('span.editsection'); // Sections
var editSectionCount = 1;
for(var s=0;s<EditSections.length;s++){
BandeauxFaciles_makeEditSectionMenu(EditSections[s], editSectionCount);
editSectionCount++;
}
}
// -------------------------------------------------------------------- Création d'un menu
function BandeauxFaciles_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:BandeauxFaciles_editSectionMenuAfficher('+count+');" title="'+window.editSectionMenu_DeroulerPop+'" >'+window.editSectionMenu_Derouler+'</a>]'
+' <span id="editSectionMenu_'+count+'" style="display:none;" ><br/>';
for(var a=0;a<window.editSectionMenu_CodeUrl.length;a++){
var Params = "";
if(window.editSectionMenu_ModeleParametres[a]=="oui"){
Params = "|...";
}
var Bandeau = window.editSectionMenu_ModeleDebut[a] + Params + '}}';
Liens += ' <a href="'+editSectionMenu_Adresse+'§ion='+count+window.editSectionMenu_CodeUrl[a]+'" title="'+window.editSectionMenu_Pop+Bandeau+'" >'+Bandeau+'</a>';
}
Liens += '</span>';
if(count==0){
element.innerHTML = Liens;
}else{
element.innerHTML = element.innerHTML + ' - ' + Liens;
}
}
// -------------------------------------------------------------------- Affichage d'un menu
window.BandeauxFaciles_editSectionMenuAfficher = function(Id){
var Lien = document.getElementById("editSectionMenuLink_" + Id);
Lien.innerHTML = window.editSectionMenu_Enrouler;
Lien.title = window.editSectionMenu_EnroulerPop;
Lien.href = "javascript:BandeauxFaciles_editSectionMenuMasquer("+Id+");";
var Menu = document.getElementById("editSectionMenu_" + Id);
Menu.style.display = 'inline';
};
// -------------------------------------------------------------------- Masquage d'un menu
window.BandeauxFaciles_editSectionMenuMasquer = function(Id){
var Lien = document.getElementById("editSectionMenuLink_" + Id);
Lien.innerHTML = window.editSectionMenu_Derouler;
Lien.title = window.editSectionMenu_DeroulerPop;
Lien.href = "javascript:BandeauxFaciles_editSectionMenuAfficher("+Id+");";
var Menu = document.getElementById("editSectionMenu_" + Id);
Menu.style.display = 'none';
};
// -------------------------------------------------------------------- Ajout du modèle et publication
function BandeauxFaciles_doEdit(){
var CodeUrl=0;
var EditMode = false;
while(CodeUrl<window.editSectionMenu_CodeUrl.length){
if( location.href.indexOf(window.editSectionMenu_CodeUrl[CodeUrl]) != -1 ){
EditMode = true;
var ModeleDebut = window.editSectionMenu_ModeleDebut[CodeUrl];
var ModeleParametres = window.editSectionMenu_ModeleParametres[CodeUrl];
break;
}
CodeUrl++;
}
if(EditMode==false) return;
var 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 wpTextbox1 = document.getElementById("wpTextbox1");
var txt = wpTextbox1.value;
if( (location.href.indexOf('§ion=')!=-1) && (location.href.indexOf('§ion=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;
}
wpTextbox1.value = Texte;
document.editform.wpSummary.value = document.editform.wpSummary.value + 'Ajout de : ' + Bandeau ;
if(window.editSectionMenu_Autosubmit==true) document.editform.submit();
}
});
//</nowiki></pre></syntaxhighlight>