User:Jean-Claude Dusse/monobook.js

/* Tout JavaScript ici sera chargé avec chaque page accédée par n’importe quel utilisateur. */

if(typeof(MonobookToolbar)=="undefined"){ // Test anti-double inclusion

var MonobookToolbar = new Object;

MonobookToolbar.buttons = new Array;

MonobookToolbar.fonctions = new Object;

MonobookToolbar.fonctions.Init = function{ var UseBetaToolbar = (mw.user.options.get('usebetatoolbar') === 1 ); if(UseBetaToolbar && typeof(MonobookToolbar.forceMonobookToolbar)==="undefined") return; var toolbar = document.getElementById("toolbar"); if(toolbar) toolbar.parentNode.removeChild(toolbar); var newtoolbar = document.createElement('div'); newtoolbar.id = "MonobookToolbar"; var Textarea = document.getElementById("wpTextbox1"); if(Textarea){ Textarea.parentNode.insertBefore(newtoolbar, Textarea); MonobookToolbar.fonctions.InitButtons; } }

MonobookToolbar.fonctions.InitButtons = function{ for(var a=0,l=MonobookToolbar.buttons.length;a<l;a++){ MonobookToolbar.fonctions.InsertButton(a); }   if(typeof(mwCustomEditButtons)==="object"){ for(var a=0,l=mwCustomEditButtons.length;a<l;a++){ if(mwCustomEditButtons[a].inserted) continue; mwCustomEditButtons[a].inserted = true; MonobookToolbar.fonctions.InsertButton(a, true); }   } }

MonobookToolbar.fonctions.InsertButton = function(index, old){ var parent = document.getElementById("MonobookToolbar"); var item = MonobookToolbar.buttons[index]; if(old && mwCustomEditButtons) item = mwCustomEditButtons[index]; if(!parent || !item) return false; if(item.imageId && document.getElementById(item.imageId)) return; var image = document.createElement("img"); image.width = 23; image.height = 22; if (item.imageId) image.id = item.imageId; image.src = item.imageFile; image.border = 0; image.alt = item.speedTip; var link = document.createElement("a"); link.className = "mw-toolbar-editbutton"; link.title = item.speedTip; link.href = "#"; link.onclick = function { MonobookToolbar.fonctions.insertTags(item.tagOpen, item.tagClose, item.sampleText); return false; };    link.appendChild(image); parent.appendChild(link); return true; }

MonobookToolbar.fonctions.insertTags = function(tagOpen, tagClose, sampleText){ var txtarea = document.getElementById("wpTextbox1"); if (!txtarea){ // some alternate form? take the first one we can find var areas = document.getElementsByTagName('textarea'); txtarea = areas[0]; }   var selText, isSample = false; if (document.selection && document.selection.createRange) { // IE/Opera //save window scroll position if (document.documentElement && document.documentElement.scrollTop) var winScroll = document.documentElement.scrollTop else if (document.body) var winScroll = document.body.scrollTop; //get current selection txtarea.focus; var range = document.selection.createRange; selText = range.text; //insert tags checkSelectedText; range.text = tagOpen + selText + tagClose; //mark sample text as selected if (isSample && range.moveStart) { if (window.opera) tagClose = tagClose.replace(/\n/g,''); range.moveStart('character', - tagClose.length - selText.length); range.moveEnd('character', - tagClose.length); }       range.select; //restore window scroll position if (document.documentElement && document.documentElement.scrollTop) document.documentElement.scrollTop = winScroll else if (document.body) document.body.scrollTop = winScroll; } else if (txtarea.selectionStart || txtarea.selectionStart == '0') { // Mozilla //save textarea scroll position var textScroll = txtarea.scrollTop; //get current selection txtarea.focus; var startPos = txtarea.selectionStart; var endPos = txtarea.selectionEnd; selText = txtarea.value.substring(startPos, endPos); //insert tags checkSelectedText; txtarea.value = txtarea.value.substring(0, startPos) + tagOpen + selText + tagClose + txtarea.value.substring(endPos, txtarea.value.length); //set new selection if (isSample) { txtarea.selectionStart = startPos + tagOpen.length; txtarea.selectionEnd = startPos + tagOpen.length + selText.length; } else { txtarea.selectionStart = startPos + tagOpen.length + selText.length + tagClose.length; txtarea.selectionEnd = txtarea.selectionStart; }       //restore textarea scroll position txtarea.scrollTop = textScroll; }    function checkSelectedText{ if (!selText) { selText = sampleText; isSample = true; } else if (selText.charAt(selText.length - 1) == ' ') { //exclude ending space char selText = selText.substring(0, selText.length - 1); tagClose += ' ' }   } }

MonobookToolbar.fonctions.CreateButton = function(imageFile, speedTip, tagOpen, tagClose, sampleText, imageId){ var NewIndex = MonobookToolbar.buttons.length; MonobookToolbar.buttons[NewIndex] = { "imageId": imageId, "imageFile": imageFile, "speedTip": speedTip, "tagOpen": tagOpen, "tagClose": tagClose, "sampleText": sampleText };   if(document.getElementById("MonobookToolbar")){ if(imageId && !document.getElementById(imageId)){ MonobookToolbar.fonctions.InsertButton(NewIndex); }   } }

$(MonobookToolbar.fonctions.Init);

if(typeof(getVarValue)=="undefined"){ getVarValue = function(nom_variable, val_defaut){ var result = null; try { result = eval(nom_variable.toString); } catch (e) { result = val_defaut; } 	return(result); } }

if(typeof(getStrDateToday)=="undefined"){ getStrDateToday = function(format){ var str_mois = new Array; with (str_mois){ push("janvier"); push("février"); push("mars"); push("avril"); push("mai"); push("juin"); push("juillet"); push("août"); push("septembre"); push("octobre"); push("novembre"); push("décembre"); } var today = new Date; var day = today.getDate; var year = today.getYear; if (year < 2000) year = year + 1900; var str_date = format; var regex = /j/gi; str_date = str_date.replace(regex, day.toString); regex = /a/gi; str_date = str_date.replace(regex, year.toString); regex = /m/gi; str_date = str_date.replace(regex, str_mois[today.getMonth]); return (str_date); } } } // Fin test anti-double inclusion

if(typeof(MonobookToolbar)!="undefined"){

/************************************* Insérer ici les boutons standards *************************************/ //

MonobookToolbar.fonctions.CreateButton("//upload.wikimedia.org/wikipedia/commons/4/40/Apos_dact_typo.PNG", "Apostrophes", "“", "”", "texte", "mw-editbutton-apo");

MonobookToolbar.fonctions.CreateButton("//upload.wikimedia.org/wikipedia/commons/d/d2/BoutonsDefaut11.png", "Tiret", "—", "", "", "mw-editbutton-tiret");

MonobookToolbar.fonctions.CreateButton("//upload.wikimedia.org/wikipedia/commons/e/e2/Button_bold.png", "Texte en gras", "", "", "texte en gras", "mw-editbutton-bold");

MonobookToolbar.fonctions.CreateButton("//upload.wikimedia.org/wikipedia/commons/1/1d/Button_italic.png", "Texte en italique", "", "", "texte en italique", "mw-editbutton-italic");

MonobookToolbar.fonctions.CreateButton("//upload.wikimedia.org/wikipedia/commons/6/6a/Button_sup_letter.png", "Texte en exposant", "", "", "texte en exposant", "mw-editbutton-sup");

MonobookToolbar.fonctions.CreateButton("//upload.wikimedia.org/wikipedia/commons/8/89/Button_bigger.png", "Texte en grand", " ", " ", "texte en grand", "mw-editbutton-big");

MonobookToolbar.fonctions.CreateButton("//upload.wikimedia.org/wikipedia/commons/0/0d/Button_smaller.png", "Texte en petit", " ", " ", "texte en petit", "mw-editbutton-small");

MonobookToolbar.fonctions.CreateButton("//upload.wikimedia.org/wikipedia/commons/7/78/Button_head_A2.png", "Chapitre de niveau 2", "== ", " ==", "Nom du chapitre", "mw-editbutton-headline2");

MonobookToolbar.fonctions.CreateButton("//upload.wikimedia.org/wikipedia/commons/4/4f/Button_head_A3.png", "Chapitre de niveau 3", "=== ", " ===", "Nom du chapitre", "mw-editbutton-headline3");

MonobookToolbar.fonctions.CreateButton("//upload.wikimedia.org/wikipedia/commons/c/c0/Button_link.png", "Lien interne", "", "", "titre de la page", "mw-editbutton-link");

MonobookToolbar.fonctions.CreateButton("//upload.wikimedia.org/wikipedia/commons/e/ec/Button_extlink.png", "Lien externe", "[", "]", "http://www.example.com titre du lien", "mw-editbutton-extlink");

MonobookToolbar.fonctions.CreateButton("//upload.wikimedia.org/wikipedia/commons/b/b4/Button_category03.png", "Catégorie", '", 'nom de la catégorie', "mw-editbutton-category");

MonobookToolbar.fonctions.CreateButton("//upload.wikimedia.org/wikipedia/commons/3/3b/Button_template_alt.png", "Modèle", '", 'modèle ou page à inclure', "mw-editbutton-template");

MonobookToolbar.fonctions.CreateButton("//upload.wikimedia.org/wikipedia/commons/d/de/Button_image.png", "Média", "[[Media:", "|thumb|Description du média.]]", "Exemple.ogg", "mw-editbutton-media");

MonobookToolbar.fonctions.CreateButton("//upload.wikimedia.org/wikipedia/commons/8/82/Nowiki_icon.png", "Ignorer le format wiki", "", "", "", "mw-editbutton-nowiki");

MonobookToolbar.fonctions.CreateButton("//upload.wikimedia.org/wikipedia/commons/c/c8/Button_redirect.png", "Redirection", "#REDIRECT", "", "nom de la destination", "mw-editbutton-redirect");

MonobookToolbar.fonctions.CreateButton("//upload.wikimedia.org/wikipedia/commons/1/13/Button_enter.png", "Saut de ligne", "", "", "mw-editbutton-br");

MonobookToolbar.fonctions.CreateButton("//upload.wikimedia.org/wikipedia/commons/c/c4/Button_ref.png", "Référence", " ", "référence, citation ou lien", "mw-editbutton-ref");

MonobookToolbar.fonctions.CreateButton("//upload.wikimedia.org/wikipedia/commons/6/64/Buttonrefvs8.png", "Index des références", '== Notes et références ==\n', "", "", "mw-editbutton-references");

// /************************************* Fin des boutons standards *************************************/

} // Fin test anti-double inclusion