« MediaWiki:Common.js » : différence entre les versions
De BoyWiki
(test) |
Aucun résumé des modifications |
||
Ligne 559 : | Ligne 559 : | ||
/* Gestion tag <video> temporaire */ | /* Gestion tag <video> temporaire */ | ||
if (wgAction == 'edit') return; | function appendvideotag() { | ||
if (wgAction == 'edit') return; | |||
var divs = document.getElementById('bodyContent').getElementsByTagName('div'); | var divs = document.getElementById('bodyContent').getElementsByTagName('div'); | ||
for (var i = 0; i < divs.length ; i++) { | for (var i = 0; i < divs.length ; i++) { | ||
if (divs[i].className == "video") { | |||
var params = divs[i].getElementsByTagName('span')[0].innerHTML; | |||
var text = divs[i].lastChild.innerHTML; | |||
var style = divs[i].lastChild.getAttribute('style'); | |||
divs[i].innerHTML = '<video '+params+'>'+'</video><p style="'+style+'">'+text+'</p>'; | |||
} | |||
} | } | ||
} | } | ||
addOnloadHook (appendvideotag); | |||
Version du 13 décembre 2015 à 19:24
/* Tout JavaScript ici sera chargé avec chaque page accédée par n’importe quel utilisateur. */
/* Fonctions importées de Wikipédia */
/**
* Diverses fonctions manipulant les classes (utilisées par les boîtes déroulantes)
* Utilise des expressions régulières et un cache pour de meilleures perfs
* isClass et whichClass depuis http://fr.wikibooks.org/w/index.php?title=MediaWiki:Common.js&oldid=140211
* hasClass, addClass, removeClass et eregReplace depuis http://drupal.org.in/doc/misc/drupal.js.source.html
* surveiller l'implémentation de .classList http://www.w3.org/TR/2008/WD-html5-diff-20080122/#htmlelement-extensions
*/
function isClass(element, classe) {
return hasClass(element, classe);
}
function whichClass(element, classes) {
var s=" "+element.className+" ";
for(var i=0;i<classes.length;i++)
if (s.indexOf(" "+classes[i]+" ")>=0) return i;
return -1;
}
function hasClass(node, className) {
if (node.className == className) {
return true;
}
var reg = new RegExp('(^| )'+ className +'($| )')
if (reg.test(node.className)) {
return true;
}
return false;
}
function addClass(node, className) {
if (hasClass(node, className)) {
return false;
}
node.className += ' '+ className;
return true;
}
function removeClass(node, className) {
if (!hasClass(node, className)) {
return false;
}
node.className = eregReplace('(^|\\s+)'+ className +'($|\\s+)', ' ', node.className);
return true;
}
function eregReplace(search, replace, subject) {
return subject.replace(new RegExp(search,'g'), replace);
}
/**
* Boîtes déroulantes
*
* Pour [[Modèle:Méta palette de navigation]]
*/
var autoCollapse = 2;
var collapseCaption = '[ Enrouler ]';
var expandCaption = '[ Dérouler ]';
function collapseTable( tableIndex ) {
var Button = document.getElementById( "collapseButton" + tableIndex );
var Table = document.getElementById( "collapsibleTable" + tableIndex );
if ( !Table || !Button ) return false;
var Rows = Table.getElementsByTagName( "tr" );
if ( Button.firstChild.data == collapseCaption ) {
for ( var i = 1; i < Rows.length; i++ ) {
Rows[i].style.display = "none";
}
Button.firstChild.data = expandCaption;
} else {
for ( var i = 1; i < Rows.length; i++ ) {
Rows[i].style.display = Rows[0].style.display;
}
Button.firstChild.data = collapseCaption;
}
}
function createCollapseButtons() {
var tableIndex = 0;
var NavigationBoxes = new Object();
var Tables = document.getElementsByTagName( "table" );
for ( var i = 0; i < Tables.length; i++ ) {
if ( hasClass( Tables[i], "collapsible" ) ) {
NavigationBoxes[ tableIndex ] = Tables[i];
Tables[i].setAttribute( "id", "collapsibleTable" + tableIndex );
var Button = document.createElement( "span" );
var ButtonLink = document.createElement( "a" );
var ButtonText = document.createTextNode( collapseCaption );
Button.style.styleFloat = "right";
Button.style.cssFloat = "right";
Button.style.fontWeight = "normal";
Button.style.textAlign = "right";
Button.style.width = "6em";
ButtonLink.setAttribute( "id", "collapseButton" + tableIndex );
ButtonLink.setAttribute( "href", "javascript:collapseTable(" + tableIndex + ");" );
ButtonLink.appendChild( ButtonText );
Button.appendChild( ButtonLink );
var Header = Tables[i].getElementsByTagName( "tr" )[0].getElementsByTagName( "th" )[0];
/* only add button and increment count if there is a header row to work with */
if (Header) {
Header.insertBefore( Button, Header.childNodes[0] );
tableIndex++;
}
}
}
for (var i = 0; i < tableIndex; i++) {
if ( hasClass( NavigationBoxes[i], "collapsed" ) || ( tableIndex >= autoCollapse && hasClass( NavigationBoxes[i], "autocollapse" ) ) ) collapseTable( i );
}
}
addOnloadHook(createCollapseButtons);
/**
* Pour [[Modèle:Boîte déroulante]]
*/
var NavigationBarShowDefault = 0;
function toggleNavigationBar(indexNavigationBar) {
var NavToggle = document.getElementById("NavToggle" + indexNavigationBar);
var NavFrame = document.getElementById("NavFrame" + indexNavigationBar);
if (!NavFrame || !NavToggle) return;
// surcharge des libellés dérouler/enrouler grâce a l'attribut title
// exemple : title="[déroulade]/[enroulade]"
var caption = [expandCaption, collapseCaption];
if (NavFrame.title && NavFrame.title.length > 0) {
caption = NavFrame.title.split("/");
if (caption.length < 2) caption.push(collapseCaption);
}
// if shown now
if (NavToggle.firstChild.data == caption[1]) {
for ( var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
if (hasClass(NavChild, 'NavPic')) NavChild.style.display = 'none';
if (hasClass(NavChild, 'NavContent')) NavChild.style.display = 'none';
if (hasClass(NavChild, 'NavToggle')) NavChild.firstChild.data = caption[0];
}
// if hidden now
} else if (NavToggle.firstChild.data == caption[0]) {
for ( var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
if (hasClass(NavChild, 'NavPic')) NavChild.style.display = 'block';
if (hasClass(NavChild, 'NavContent')) NavChild.style.display = 'block';
if (hasClass(NavChild, 'NavToggle')) NavChild.firstChild.data = caption[1];
}
}
}
// adds show/hide-button to navigation bars
function createNavigationBarToggleButton() {
var indexNavigationBar = 0;
var NavFrame;
// iterate over all < div >-elements
for( var i=0; NavFrame = document.getElementsByTagName("div")[i]; i++ ) {
// if found a navigation bar
if (hasClass(NavFrame, "NavFrame")) {
indexNavigationBar++;
var NavToggle = document.createElement("a");
NavToggle.className = 'NavToggle';
NavToggle.setAttribute('id', 'NavToggle' + indexNavigationBar);
NavToggle.setAttribute('href', 'javascript:toggleNavigationBar(' + indexNavigationBar + ');');
// surcharge des libellés dérouler/enrouler grâce a l'attribut title
var caption = collapseCaption;
if (NavFrame.title && NavFrame.title.indexOf("/") > 0) {
caption = NavFrame.title.split("/")[1];
}
var NavToggleText = document.createTextNode(caption);
NavToggle.appendChild(NavToggleText);
// add NavToggle-Button as first div-element
// in <div class="NavFrame">
NavFrame.insertBefore( NavToggle, NavFrame.firstChild );
NavFrame.setAttribute('id', 'NavFrame' + indexNavigationBar);
}
}
// if more Navigation Bars found than Default: hide all
if (NavigationBarShowDefault < indexNavigationBar) {
for( var i=1; i<=indexNavigationBar; i++ ) {
toggleNavigationBar(i);
}
}
}
addOnloadHook(createNavigationBarToggleButton);
/*-----------------------------------------------------------------*/
/* Fonctions utilitaires autres */
/* Spécifique IE qui partage apparemment un unique curseur d'insertion pour tout le document */
var text_cursor_position;
/* Retourne la position du curseur dans un champ texte */
function getpositiontxtcursor(objtxtarea) {
/* IE */
if (!document.selection || !document.selection.createRange) return -1;
/* sauve le contenu avant modification */
objtxtarea.focus();
var oldtxt = objtxtarea.value;
var range = document.selection.createRange();
var oldrangetxt = range.text;
/* chaine marqueur identifiable */
/*var tag = String.fromCharCode(28)+String.fromCharCode(29)+String.fromCharCode(30);*/
var tag = '§;¤;§';
/* insère marqueur à emplacement curseur */
range.text = oldrangetxt + tag; range.moveStart('character', (0 - oldrangetxt.length - tag.length));
/* sauve nouvelle chaine */
var newtxt = objtxtarea.value;
/* reinit contenu à ancienne valeur */
range.text = oldrangetxt;
/* recherche marqueur dans nouvelle chaine et retourne la position */
/*for (i=0; i <= newtxt.length; i++) {
var sTemp = newtxt.substring(i, i + tag.length);
if (sTemp == tag) {
var cursorpos = (i - oldrangetxt.length);*/
var i = newtxt.search(tag);
var cursorpos = (i - oldrangetxt.length);
return cursorpos;
}
/* Insère texte à position curseur */
function insertxtatcursorpos(objtxtarea,cursorpos,txt) {
/* IE */
if (!document.selection || !document.selection.createRange) return -1;
/* si position curseur inconnue insère txt à la fin */
if (typeof(cursorpos) == 'undefined') {
objtxtarea.value += txt;
}else {
var start = objtxtarea.value.substring(0, cursorpos);
var end = objtxtarea.value.substring(cursorpos,objtxtarea.value.length);
objtxtarea.value = start + txt + end;
}
}
/*-----------------------------------------------------------------*/
/* Création objet http pour requête serveur */
function createxhrobject() {
if (window.XMLHttpRequest) { // Firefox
return new XMLHttpRequest();
}
else if (window.ActiveXObject) { // IE
return new ActiveXObject("Msxml2.XMLHTTP");
}
else return null;
}
/*-----------------------------------------------------------------*/
/* Ajoute un menu portlet (voir addPortletLink dans wikibits.js) */
/* text = (string) titre du menu
* id = (string) identifiant unique (p-cactions, p-personal, p-logo, p-navigation, p-search, p-tb : déjà utilisés)
* nextnode = (node) pour insérer avant un menu existant, par défaut ajout à la fin (optionnel)
*/
function addPortletMenu(text, id, nextnode) {
var marge = document.getElementById('column-one');
if (marge == null) return;
var menu = document.createElement('div');
menu.className = 'portlet';
menu.setAttribute('id', id);
menu.innerHTML = '<h5>' + text + '</h5><div class="pBody"><ul></ul></div>';
marge.insertBefore(menu, nextnode);
}
/*-----------------------------------------------------------------*/
/* Tri alphabétique ou par dates */
/* Ordre alphabétique des caractères latins et équivalents non accentués */
var alphabeticordereplmap = {'a':'a','à':'a','á':'a','â':'a','ã':'a','ä':'a','å':'a','ā':'a','ă':'a','æ':'ae','b':'b','c':'c','ć':'c','č':'c','ç':'c','d':'d','ð':'d','e':'e','è':'e','é':'e','ê':'e','ë':'e','ē':'e','ĕ':'e','f':'f','g':'g','h':'h','i':'i','ì':'i','í':'i','î':'i','ï':'i','ī':'i','ĭ':'i','j':'j','k':'k','l':'l','m':'m','n':'n','ñ':'n','o':'o','ò':'o','ó':'o','ô':'o','õ':'o','ö':'o','ō':'o','ŏ':'o','ø':'o','ǿ':'o','œ':'oe','p':'p','q':'q','r':'r','s':'s','ś':'s','š':'s','ş':'s','t':'t','u':'u','ù':'u','ú':'u','û':'u','ü':'u','ū':'u','ŭ':'u','v':'v','w':'w','x':'x','y':'y','ý':'y','z':'z','ž':'z','0':'0','1':'1','2':'2','3':'3','4':'4','5':'5','6':'6','7':'7','8':'8','9':'9','ο':'zz','θ':'zz'}
//var alphabeticorder = 'aàáâãäåāăæbcćčçdðeèéêëēĕfghiìíîïīĭjklmnñoòóôõöōŏøǿœpqrsśšştuùúûüūŭvwxyýzž0123456789 -';
//var alphareplcorder = 'aaaaaaaaaabccccddeeeeeeefghiiiiiiijklmnnooooooooooopqrsssstuuuuuuuvwxyyzz0123456789 -';
/* Comparaison externe de 2 mots pour sort */
function alphacompare(a,b) {
var aa = '';
var bb = '';
var n = Math.min(a.length,b.length);
for (var i = 0; i < n ; i++) aa = aa.concat(alphabeticordereplmap[a[i].toLowerCase()] || "");
for (var i = 0; i < n ; i++) bb = bb.concat(alphabeticordereplmap[b[i].toLowerCase()] || "");
var n = Math.min(aa.length,bb.length);
aa = aa.substr(0,n);
bb = bb.substr(0,n);
if (aa < bb) return -2;
if (aa > bb) return 2;
// si aa = bb
if (a.length < b.length) return -1;
if (a.length > b.length) return 1;
return 0;
}
/* Ordre des mois */
var datemonthorder = 'janv Janv févr Févr mars Mars avri Avri mai Mai juin Juin juil Juil août Août sept Sept octo Octo nove Nove déce Déce';
/* Comparaison externe de 2 chaines-date-mois ou ans ou siecle pour sort */
function datecymcompare(a,b) {
var aa = a.split(' ');
var bb = b.split(' ');
// cas 2 années ou 2 mois
if (aa.length==1 && bb.length==1) {
// 2 années
if (parseInt(a)) return parseInt(a) - parseInt(b);
// 2 mois
else return datemonthorder.search(a.substr(0,4)) - datemonthorder.search(b.substr(0,4));
}
// cas 2 siecles
if (aa.length>=2 && bb.length>=2 && aa[1].match(/siècle/)) {
if (aa[2] && aa[2].match(/AEC/)) {
if (bb[2] && bb[2].match(/AEC/)) {return romantoarab(bb[0]) - romantoarab(aa[0]);}
else return -1;
} else {
if (bb[2] && bb[2].match(/AEC/)) return 1;
else {return romantoarab(aa[0]) - romantoarab(bb[0]);}
}
}
// cas 2 dates+mois
if (aa.length==2 && bb.length==2) {
var dm = datemonthorder.search(aa[1].substr(0,4)) - datemonthorder.search(bb[1].substr(0,4));
if (dm==0) return parseInt(aa[0]) - parseInt(bb[0]);
else return dm;
}
// cas 1 année + 1 siecle
// if (aa.length==1 && bb.length==2 && bb[1].match(/siècle/)) return 1;
// cas 1 année + 1 mois
if (aa.length==1 && bb.length==2) return -1;
return 1;
}
/*
***************** Ajout scripts Monobook de l'ancienne version **********************
*/
/* Gestion aide création références bibliographiques */
/* Affichage formulaire de saisie */
/* Création de sous-page édition et maj page oeuvre */
importScript('Utilisateur:Pinocchio/création_référence_biblio.js');
/*--------------------------------------------------------------------------------*/
/* Gestion citation et image du jour */
/* - tirage aléatoire et préparation jours futurs
/* - identification, ajout num id aléatoire dans {{Extrait}} et {{Image texte}} à la création */
/* Formulaire commentaire des images */
importScript('Utilisateur:Pinocchio/citation_du_jour.js');
/*--------------------------------------------------------------------------------*/
/* Gestion index des pages articles */
importScript('Utilisateur:Pinocchio/index_pages_articles.js');
/*--------------------------------------------------------------------------------*/
/* Gestion pseudo modèle Navigtemps (ex yearnav) */
importScript('Utilisateur:Pinocchio/yearnav.js');
/*--------------------------------------------------------------------------------*/
/* Init Timeline */
//importScript('Utilisateur:Pinocchio/timeline_init.js');
/*--------------------------------------------------------------------------------*/
/* Snowfall */
// main page only
//var bodyclass = document.body.className;
//if (bodyclass.match(/Accueil/) && wgAction == 'view') {
// importScript('Utilisateur:Pinocchio/snowfall.js');
//}
/*--------------------------------------------------------------------------------*/
/* Gestion infographie - chargement du code si nécessaire */
function infographic_load() {
if (document.getElementById('infographic') && (wgAction == 'view' || wgAction == 'submit')) {
importScript('Utilisateur:Pinocchio/infographie.js');
var x = setTimeout("infographic_load_wait()",500);
}
}
function infographic_load_wait() {
if (typeof(infographic_change_scale) == 'function') infographic_init();
else var x = setTimeout("infographic_load_wait()",500);
}
addOnloadHook(infographic_load);
/*--------------------------------------------------------------------------------*/
/* Automate - chargement code si nécessaire */
function bot_load() {
if (wgPageName != 'Utilisateur:Pinocchio/Automate' || wgAction != 'view') return;
if (wgUserGroups == null || wgUserGroups.join(" ").match(/sysop|bureaucrat/) == null) return;
importScript('Utilisateur:Pinocchio/automate.js');
var x = setTimeout("bot_load_wait()",500);
}
function bot_load_wait() {
if (typeof(botfieldsdisable) == 'function') botcreateform();
else var x = setTimeout("bot_load_wait()",500);
}
addOnloadHook(bot_load);
/*--------------------------------------------------------------------------------*/
/* Insère appel à fonction() sur action submit avant envoi de la page */
function initeventpostform() {
if (wgAction == 'edit' || wgAction == 'submit') {
if (document.forms['editform'] == undefined || document.forms['editform'].elements['wpTextbox1'] == undefined) return;
document.forms['editform'].onsubmit = function() {
/* pour les pages de citations ajoute un identifiant aux nouveaux modèles Extrait */
ident_citation_du_jour();
/* pour les pages commentaires images ajoute un identifiant aux nouveaux modèles */
ident_image_du_jour();
/* pour les pages années maj du tableau des dates lors de la création */
yearnav_collect();
/* pour pages agora: ajout titre date si nouvelle page */
pgagora_insert_topsection();
}
}
}
addOnloadHook(initeventpostform);
/*--------------------------------------------------------------------------------*/
/* Ajoute lien Agora dans le menu Navigation (si connecté)
/* et lien index des pages dans menu Navigation */
function addlinkportletmenu() {
if (wgUserName != null)
addPortletLink("p-navigation", "https://www.boywiki.org/fr/BoyWiki:Agora", "Agora", "n-agora", "échanger ou se documenter sur la gestion et la rédaction de BoyWiki");
addPortletLink("p-navigation", "https://www.boywiki.org/fr/BoyWiki:Index des pages","Index des pages","n-idxallpg","toutes les pages articles",'',document.getElementById('n-randompage'));
}
addOnloadHook(addlinkportletmenu);
/*--------------------------------------------------------------------------------*/
/* Pour les pages 'dialogue' affecte la classe dialog à body */
/* utilisé par css pour l'encadrement colorisé des dialogues indentés dans Agora */
function attrib_class_dialog() {
/* seulement pour les pages Agora ou discussion */
var bodyclass = document.body.className;
if (bodyclass.match(/page-BoyWiki_Agora/) || bodyclass.match(/ns-talk/))
document.body.className = bodyclass + ' dialog';
}
addOnloadHook(attrib_class_dialog);
/*--------------------------------------------------------------------------------*/
/* Pages Agora : si création nouvelle sous-page ajoute un lien-titre-date principal (appelé sur submit) */
function pgagora_insert_topsection() {
/* seulement pages agora nouvelle et ayant droit en écriture */
if (wgAction != 'edit' && wgAction != 'submit') return true;
if (wgUserGroups == null || wgUserGroups.join(" ").match(/user|sysop|bureaucrat/) == null) return true;
if (wgPageName == null || wgPageName.match(/^BoyWiki:Agora\//) == null) return true;
if (wgTitle == null) return true;
if (wgArticleId != 0) return true;
if (document.forms['editform'].elements['wpSummary'] == undefined) return true;
if (document.getElementById('wpSummaryLabel').firstChild.firstChild.data.match(/Sujet.*\/.*titre/) == null) return true;
/* récup texte */
var content = document.forms['editform'].elements['wpTextbox1'].value;
/* si lien titre déjà présent */
if (content.match(/^\n?=\[\[[^\]\/]*Agora\/[^\]]*\]\]=/)) return true;
/* sinon copie sujet sous-titre */
var sujet = document.forms['editform'].elements['wpSummary'].value;
document.forms['editform'].elements['wpSummary'].value = "";
if (sujet.length) sujet = "=="+sujet+"==\n";
/* et insère titre en début page et sujet en dessous */
var titre = "=[[BoyWiki:"+wgTitle+"|"+wgTitle+"]]=\n";
/* ajout catégorie par défaut */
var categ = "\n\n"+"[[Catégorie:Agora]]";
document.forms['editform'].elements['wpTextbox1'].value = titre + sujet + content + categ;
return true;
}
/*--------------------------------------------------------------------------------*/
/* Gestion tag <video> temporaire */
function appendvideotag() {
if (wgAction == 'edit') return;
var divs = document.getElementById('bodyContent').getElementsByTagName('div');
for (var i = 0; i < divs.length ; i++) {
if (divs[i].className == "video") {
var params = divs[i].getElementsByTagName('span')[0].innerHTML;
var text = divs[i].lastChild.innerHTML;
var style = divs[i].lastChild.getAttribute('style');
divs[i].innerHTML = '<video '+params+'>'+'</video><p style="'+style+'">'+text+'</p>';
}
}
}
addOnloadHook (appendvideotag);
/*--------------------------------------------------------------------------------*/
/* Ajoute un message d'aide sur la page création de compte */
//function pgcreataccountaddmsg() {
// if (!wgPageName.match(/Sp.cial:Connexion/)) return;
// var ulg = document.forms['userlogin'].getElementsByClassName('mw-form-header')[0];
// if (ulg == null) return;
// var txt = "<p><i><b>Afin que vous puissiez modifier des articles ou en créer de nouveaux, votre compte devra être enregistré.";
// txt += " À cet effet, merci de contacter fr.info@boywiki.org (prévoyez cependant un délai pouvant se compter en jours pour ";
// txt += "obtenir une réponse à votre courriel).</b></i></p>";
// ulg.innerHTML = ulg.innerHTML+txt;
//}
//addOnloadHook (pgcreataccountaddmsg);
/*--------------------------------------------------------------------------------*/
/* Montrer/Masquer les liens dans les citations (appelé par bouton en haut de page ou bandeau citation) */
/* ajout ou retrait de la classe masquelien au(x) div citation longue pour application style */
function togglevisibilitylink() {
var divs = document.getElementById('bodyContent').getElementsByTagName('div');
for (var i = 0; i < divs.length ; i++) {
if (divs[i].className.match(/^citelong.+masquelien/)) {
divs[i].className = divs[i].className.replace(/ masquelien/,'');
document.getElementById('togglevisibilitylink').firstChild.value = 'Masquer les liens dans les citations';
}
else if (divs[i].className.match(/^citelong/)) {
divs[i].className = divs[i].className + ' masquelien';
document.getElementById('togglevisibilitylink').firstChild.value = 'Afficher les liens dans les citations';
}
}
}
/* Montrer les liens dans les citations imposé pour le mode prévisualiser */
/* retrait de la classe masquelien au(x) div citation longue */
function togglevisibilitylinkpreview() {
if (wgAction != 'submit' || wgPageName.match(/Agora/)) return;
var divs = document.getElementById('bodyContent').getElementsByTagName('div');
for (var i = 0; i < divs.length ; i++) {
if (divs[i].className.match(/^citelong/)) {
divs[i].className = divs[i].className.replace(/ masquelien/,'');
}
}
}
addOnloadHook(togglevisibilitylinkpreview);
/* Création bouton Montrer/Masquer liens pour les citations (haut de page ou bandeau citation)
*/
function creatogglevisibilitylink() {
if (wgAction != 'view' || !wgIsArticle || wgPageName.match(/Agora/)) return;
var cont = document.getElementById('mw-content-text');
var divs = cont.getElementsByTagName('div');
/* seulement si un espace citation présent et option sanslien absente */
for (var i = 0; i < divs.length ; i++) {
if (divs[i].className.match(/citelong/) && !divs[i].className.match(/sanslien/)) {
var btn = document.getElementById('togglevisibilitylink');
/* si div inexistant ajout en haut de page (div existe si bouton dans bandeau) */
if(!btn) {
var idx = document.getElementById('bandeaucite');
if (!idx) idx = document.getElementById('jump-to-nav');
if (!idx) idx = document.getElementById('contentSub');
btn = document.createElement('div');
btn.setAttribute('id', 'togglevisibilitylink');
cont = document.getElementById('bodyContent');
}
btn.innerHTML = '<input type="button" value="Afficher les liens dans les citations" title="Montrer/Masquer les liens qui ont été rajoutés au texte originel pour naviguer vers d’autres pages de BoyWiki" onclick="togglevisibilitylink()" />';
if (idx) cont.insertBefore(btn, idx.nextSibling);
break;
}
}
}
addOnloadHook(creatogglevisibilitylink);
/*--------------------------------------------------------------------------------*/
/* Fonction bouton Montrer / Masquer les marges (agrandir la zone de lecture) */
function togglehidemargin() {
var cont = document.getElementById('content');
var bdcont = document.getElementById('bodyContent');
var foot = document.getElementById('footer');
var logo = document.getElementById('p-logo');
var btn = document.getElementById('togglehidemargin');
if (foot.style.display == 'none') {
cont.setAttribute('style', 'margin:2.8em 0 0 12.2em; padding:1.5em; z-index:2; transition:margin .5s ease');
bdcont.setAttribute('style', 'z-index:2;');
logo.setAttribute('style', 'left:0.5em;');
foot.style.display = '';
btn.src = 'http://www.boywiki.org/media/images/e/ee/Groom_o.jpg';
}
else {
cont.setAttribute('style', 'margin:0; padding:13px; z-index:5; transition:margin .5s ease;');
bdcont.setAttribute('style', 'z-index:5; background-color:white;');
logo.setAttribute('style', 'left:-10em;');
foot.style.display = 'none';
btn.src = 'http://www.boywiki.org/media/images/f/fd/Groom_c.jpg';
}
}
/* Creation bouton Effacement des marges */
function creatogglehidemargin() {
if (wgAction != 'view' || !wgIsArticle || wgNamespaceNumber != 0 || wgPageName == "Accueil") return;
var cont = document.getElementById('content');
var fh = cont.getElementsByClassName("firstHeading")[0];
if (!fh) return;
btn = document.createElement("input");
btn.type = "image";
btn.id = "togglehidemargin";
btn.src = "http://www.boywiki.org/media/images/e/ee/Groom_o.jpg";
btn.title = "Masquer/Montrer les marges";
btn.alt= "Groom_o";
btn.onclick = togglehidemargin;
cont.insertBefore(btn, fh);
}
addOnloadHook(creatogglehidemargin);
/*--------------------------------------------------------------------------------*/
/* Popup 'infobulle' sur les liens 'ref' affichant les notes de citations en pied de page */
var popupreftimout; /* utilisée par timeout */
/* Délai exécution nécessaire */
function initeventlinkref() {
var x = setTimeout("initeventlinkref_run()",1000);
}
/* Pour chaque lien ref de la page installe gestion event onmouse */
function initeventlinkref_run() {
/* seulement dans la partie utile de la page */
var page = document.getElementById('bodyContent');
if (page == null) return;
/* pour tout les liens de la page */
var lnk = page.getElementsByTagName('a');
for (var i = 0; i < lnk.length ; i++) {
/* seulement les lien vers note citation */
if (lnk[i].getAttribute('href') && lnk[i].getAttribute('href').match(/#cite_note-|#refnote-/)) {
lnk[i].onmouseover = delaypopupref;
/*lnk[i].onmouseout = closepopupref;*/
lnk[i].onmouseout = function(e) {clearTimeout(popupreftimout); closepopup('popup_ref'); };
}
}
}
/* Récup position souris et Temporisation affichage popup */
function delaypopupref(e) {
var event = e || window.event;
var x = event.clientX;
var y = event.clientY;
if (event.target) var tgt = event.target;
else if (event.srcElement) var tgt = event.srcElement;
if (tgt.href) popupreftimout = setTimeout (function() { openpopupref(x,y,tgt.href); }, 100);
}
/* Création et affichage popup */
function openpopupref(x,y,adr) {
/* récup texte contenu dans destination du lien qui pointe vers id=n°_de_note */
var dest = adr.split ('#');
if (!document.getElementById(dest[1])) return;
if (dest[1].match(/^cite_note/)) var content = document.getElementById(dest[1]).getElementsByTagName('span')[2].innerHTML;
if (dest[1].match(/^refnote/)) var content = document.getElementById(dest[1]).innerHTML.replace(/^<a[^<]*<\/a>/i,'');
/* création */
var popup = document.createElement('div');
popup.setAttribute('id', 'popup_ref');
popup.innerHTML = content;
document.body.appendChild(popup);
/* positionnement */
var xpage = x + (document.body.scrollLeft || document.documentElement.scrollLeft);
var ypage = y + (document.body.scrollTop || document.documentElement.scrollTop);
var popwidth = document.getElementById('popup_ref').offsetWidth;
var left = xpage - (popwidth * Math.min(x / document.body.clientWidth, 0.98));
var top = ypage + 15;
positionpopup(popup,top,left);
}
/* Suppression popup (fonction générique) */
function closepopup(name) {
while (document.getElementById(name))
document.body.removeChild(document.getElementById(name));
}
/* Passage des attributs top et left du popup selon navigateur (fonction générique) */
function positionpopup(elem,top,left) {
if (document.all) {
elem.style.top = top +'px';
elem.style.left = left +'px';
} else {
elem.setAttribute('style', 'top:'+top+'px; left:'+left+'px; opacity:1;');
}
}
addOnloadHook(initeventlinkref);
/*--------------------------------------------------------------------------------*/
/* Choix du mode d'affichage des références bibliographiques et filmographiques
/* (l'ordre de cette liste doit correspondre a celui du Modèle:Édition) */
function addBibSubsetMenu() {
var specialBib = document.getElementById('specialBib');
if (specialBib) {
//specialBib.style.display = 'block';
var menu = "<select style=\"display:inline;\" onChange=\"chooseBibSubset(selectedIndex)\">";
menu += "<option>Liste</option>";
if (specialBib.className == 'refilmo') {
menu += "<option selected>Référence longue</option>";
menu += "<option>Cadre</option>";
menu += "<option>Référence courte</option>";
menu += "<option>Référence tournage</option>";
}
else {
menu += "<option selected>ISBD</option>";
menu += "<option>ISBDmod</option>";
menu += "<option>Référence courte</option>";
}
menu += "</select>";
specialBib.innerHTML = specialBib.innerHTML + menu;
}
/* sélection par défaut */
chooseBibSubset(1);
}
/* Sélection type affichage biblio et filmo */
function chooseBibSubset(s) {
var lst = document.getElementsByTagName('div');
for (var i = 0; i < lst.length ; i++) {
if(lst[i].className == 'BibList') lst[i].style.display = s == 0 ? 'block' : 'none';
else if(lst[i].className == 'ISBD') lst[i].style.display = s == 1 ? 'block' : 'none';
else if(lst[i].className == 'ISBDmod') lst[i].style.display = s == 2 ? 'block' : 'none';
else if(lst[i].className == 'BibRef') lst[i].style.display = s == 3 ? 'block' : 'none';
else if(lst[i].className == 'filmolist') lst[i].style.display = s == 0 ? 'block' : 'none';
else if(lst[i].className == 'filmolong') lst[i].style.display = s == 1 ? 'block' : 'none';
else if(lst[i].className == 'filmocadre') lst[i].style.display = s == 2 ? 'block' : 'none';
else if(lst[i].className == 'filmocourt') lst[i].style.display = s == 3 ? 'block' : 'none';
else if(lst[i].className == 'filmotourn') lst[i].style.display = s == 4 ? 'block' : 'none';
}
}
addOnloadHook(addBibSubsetMenu);
/*--------------------------------------------------------------------------------*/
/* Pour les pages 'édition' ajout de boutons à la barre d'outils */
function addCustomButton(imageFile, imageText, tagOpen, tagClose, insertText) {
mw.toolbar.addButton({"imageFile": imageFile,
"speedTip": imageText,
"tagOpen": tagOpen,
"tagClose": tagClose,
"sampleText": insertText});
}
if (wgAction == 'edit' || wgAction == 'submit') {
addCustomButton('http://www.boywiki.org/media/images/0/04/Button_array.png','Assistant Tableau','','','');
addCustomButton('http://www.boywiki.org/media/images/e/eb/Button_plantilla.png','Liste des Modèles','','','nom de modèle ou page à inclure');
addCustomButton('http://www.boywiki.org/media/images/5/59/Button_replace.png','Chercher-Remplacer','','','');
addCustomButton('http://www.boywiki.org/media/images/4/49/Button_coords.png','Coordonnées image infographie','','','');
addCustomButton('http://www.boywiki.org/media/images/c/c9/Button_strike.png','Rayé','<s>','</s>','');
addCustomButton('http://www.boywiki.org/media/images/8/88/Btn_toolbar_enum.png','Liste énumération','\n# ','\n# B\n# C','A');
addCustomButton('http://www.boywiki.org/media/images/1/11/Btn_toolbar_liste.png','Liste à puces','\n* ','\n* B\n* C','A');
addCustomButton('http://www.boywiki.org/media/images/c/c4/Button_ref.png','Référence','<ref group="groupe de notes">','</ref>','référence, citation, lien');
addCustomButton('http://www.boywiki.org/media/images/6/64/Buttonrefvs8.png','Index des références','== Notes et références ==\n<references group="groupe de notes" />','','');
// addCustomButton('http://www.boywiki.org/media/images/0/0c/Button_Link_DifferentName.png','Catégorie','\[\[catégorie:','\|\]\]','nom de catégorie');
addCustomButton('http://www.boywiki.org/media/images/1/13/Button_enter.png','Saut à la ligne','<br />','','');
addCustomButton('http://www.boywiki.org/media/images/2/26/Button_latinas.png','Guillemets','« ',' »','texte');
addCustomButton('http://www.boywiki.org/media/images/5/50/Button_hellip.png','Points de suspension','…','','');
addCustomButton('http://www.boywiki.org/media/images/2/2d/Button_ndash.png','Tiret demi-cadratin','–','','');
addCustomButton('http://www.boywiki.org/media/images/c/cd/Button_mdash.png','Tiret cadratin','—','','');
addCustomButton('http://www.boywiki.org/media/images/4/4b/Button_nbsp.png','Espace insécable (inutile avec : ; ! ? % « »)',' \;','','');
addCustomButton('http://www.boywiki.org/media/images/a/a4/Button_nbthsp.png','Espace fine insécable',' \;','','');
}
/*--------------------------------------------------------------------------------*/
/* Pour les pages 'édition' ajoute une liste déroulante pour afficher des jeux de caractères spéciaux */
/* version simplifiée inspirée de [http://fr.wikipedia.org/wiki/Utilisateur:Zelda/Edittools] */
var CustomEditCharsetMenu = new Array();
/* Insertion dans la page : barre 'caractères spéciaux', liste déroulante et jeux de caractères */
function addcharsetmenu() {
/* Création espace d'accueil dans la page si existe pas */
if (document.getElementsByClassName('mw-editTools').length == 1) {
var specialchars = document.getElementById('specialcharsets');
if (specialchars == null) {
specialchars = document.createElement('div');
specialchars.setAttribute('id', 'specialcharsets');
//document.getElementById('bodyContent').insertBefore(specialchars,document.getElementById('editform'));
document.getElementById('editform').insertBefore(specialchars,document.getElementById('wpTextbox1'));
}
}
if (specialchars == null) return;
/* Création liste déroulante */
var charsetselect = document.createElement('select');
charsetselect.setAttribute('style', 'display:inline');
charsetselect.onchange = function () {changecharset(this.selectedIndex);};
for (var i = 0; i < CustomEditCharsetMenu.length ; i++) {
/* Création paragraphes par jeu de caractères */
var p = document.createElement('p');
p.style.display = 'none';
p.innerHTML = CustomEditCharsetMenu[i][1];
specialchars.appendChild(p);
/* Ajout noms des jeux de caractères dans liste déroulante */
var opt = document.createElement('option');
var txt = document.createTextNode(CustomEditCharsetMenu[i][0]);
opt.appendChild(txt);
charsetselect.appendChild(opt);
}
specialchars.insertBefore(charsetselect, specialchars.childNodes[0]);
/* Choix par défaut */
changecharset(0);
}
/* Affichage des caractères du jeu sélectionné */
function changecharset(index) {
var p = document.getElementById('specialcharsets').getElementsByTagName('p');
for (var i = 0; i < p.length ; i++) {
/* Init et affiche jeu de caractères sélectionné */
if (i == index) {
initcharsubset(p[i]);
p[i].style.display = 'inline';
p[i].style.visibility = 'visible';
}
else {
/* cache les autres */
p[i].style.display = 'none';
p[i].style.visibility = 'hidden';
}
}
}
/* Init jeu de caractères sélectionné - transforme chaque chaine en lien actif */
function initcharsubset(p) {
var spans = p.getElementsByTagName("span");
if (!spans) return;
/* Pour chaque <span> du paragraphe */
for (var j = 0; j < spans.length; j++) {
if (spans[j].childNodes.length == 0 || spans[j].childNodes[0].nodeType != 3) continue;
/* Pour chaque chaine du <span> séparée par un espace */
var chars = spans[j].childNodes[0].nodeValue.split(' ');
for (var k = 0; k < chars.length; k++) {
var a = document.createElement('a');
var tags = chars[k];
/* création du lien insertTag(tagBegin, tagEnd, defaultValue) */
var tagBegin = tags;
var tagEnd = '';
var defaultValue = '';
a.href = "javascript:mw.toolbar.insertTags('" + tagBegin + "','" + tagEnd + "', '" + defaultValue + "')";
a.appendChild(document.createTextNode(tagBegin + tagEnd));
spans[j].appendChild(a);
spans[j].appendChild(document.createTextNode(" "));
}
/* suppression ancien contenu */
spans[j].removeChild(spans[j].firstChild);
}
}
/* Ajout des jeux de caractères dans la barre 'caractères spéciaux' */
/* charsetname: nom du jeu de carctères affiché dans la liste déroulante */
/* charlist: liste des caractères séparés par un espace et encadrée par <span> </span>*/
function addCustomCharsetMenu(charsetname, charlist) {
var nextitem = CustomEditCharsetMenu.length;
CustomEditCharsetMenu[nextitem] = new Array(2);
CustomEditCharsetMenu[nextitem][0] = charsetname;
CustomEditCharsetMenu[nextitem][1] = charlist;
}
addOnloadHook(addcharsetmenu);
addCustomCharsetMenu('Français', '<span>À à  â Ä ä Æ æ É é È è Ê ê Ë ë Î î Ï ï Ô ô Ö ö Œ œ Ù ù Û û Ü ü Ç ç ’</span>');
addCustomCharsetMenu('Autres (Latin)', '<span>Å å Ã ã Á á Ā ā Ă ă Ć ć Č č Đ đ Ē ē Ĕ ĕ Í í Ì ì Ī ī Ĭ ĭ İ ı Ł ł Ñ ñ Õ õ Ò ò Ó ó Ō ō Ŏ ŏ Ǿ ǿ Ø ø Ś ś Š š Ş ş ŭ Ú ú Ū ū Ŭ ŭ Ý ý ÿ</span>');
addCustomCharsetMenu('Allemand', '<span>Ä ä Ö ö ß Ü ü</span>');
addCustomCharsetMenu('Arabe (transcription)', '<span>’ ‘ ° Å å Ā ā ã À à Á á ä ą Ċ ċ Đ đ Ḍ ḍ Ğ ğ Ġ ġ Ħ ħ Ḥ ḥ Ī ī ĩ Ì ì Í í ł Ø ø Š š Ṣ ṣ Ŧ ŧ Ṭ ṭ ẗ Ū ū ũ ù ú ẃ ý Ż ż Ẓ ẓ</span>');
addCustomCharsetMenu('Cyrillique', '<span>А Б В Г Д Е Ж З И Й К Л М Н О П Р С Т У Ф Х Ц Ч Ш Щ Ъ Ы Ь Э Ю Я а б в г д е ж з и й к л м н о п р с т у ф х ц ч ш щ ъ ы ь э ю я</span>');
addCustomCharsetMenu('Espagnol', '<span>¿? ¡! Á á É é Í í Ñ ñ Ó ó Ú ú Ü ü ª º</span>');
addCustomCharsetMenu('Esperanto', '<span>Ĉ ĉ Ĝ ĝ Ĥ ĥ Ĵ ĵ Ŝ ŝ Ŭ ŭ</span>');
addCustomCharsetMenu('Grec (alphabet)', '<span>Α Β Γ Δ Ε Ζ Η Θ Ι Κ Λ Μ Ν Ξ Ο Π Ρ Σ Τ Υ Φ Χ Ψ Ω</span> - <span>Ϝ Ϻ ϟ Ϡ Ϛ Ϸ Ῥ</span> - <span>α β ϐ γ δ ε ζ η θ ϑ ι κ ϰ λ μ ν ξ ο π ϖ ρ ϱ σ ς τ υ φ ϕ χ ψ ω</span> - <span>ϝ ϻ ϟ ϡ ϛ ϸ ῤ ῥ</span>');
addCustomCharsetMenu('Grec (sans esprit)', 'accent aigu <span>Ά Έ Ή Ί Ό Ύ Ώ</span> - <span>ά έ ή ί ό ύ ώ</span> - <span>ᾴ ῄ ῴ</span> accent grave <span>Ὰ Ὲ Ὴ Ὶ Ὸ Ὺ Ὼ</span> - <span>ὰ ὲ ὴ ὶ ὸ ὺ ὼ</span> - <span>ᾲ ῂ ῲ</span> accent circonflexe <span>ᾶ ῆ ῖ ῦ ῶ</span> - <span>ᾷ ῇ ῷ</span> tréma <span>ῗ ῧ</span> - <span>ῒ ῢ</span> - <span>ΐ ΰ</span> diphtongues <span>ᾼ ῌ ῼ</span> - <span>ᾳ ῃ ῳ</span> voyelles courtes <span>Ᾰ ᾰ Ῐ ῐ Ῠ ῠ</span> voyelles longues <span>Ᾱ ᾱ Ῑ ῑ Ῡ ῡ</span>');
addCustomCharsetMenu('Grec (esprit doux)', 'sans accent <span>Ἀ Ἐ Ἠ Ἰ Ὀ Υ̓ Ὠ</span> - <span>ᾈ ᾘ ᾨ</span> - <span>ἀ ἐ ἠ ἰ ὀ ὐ ὠ</span> - <span>ᾀ ᾐ ᾠ</span> accent aigu <span>Ἄ Ἔ Ἤ Ἴ Ὄ Ὤ</span> - <span>ᾌ ᾜ ᾬ</span> - <span>ἄ ἔ ἤ ἴ ὄ ὔ ὤ</span> - <span>ᾄ ᾔ ᾤ</span> accent grave <span>Ἂ Ἒ Ἢ Ἲ Ὂ Ὢ</span> - <span>ᾊ ᾚ ᾪ</span> - <span>ἂ ἒ ἢ ἲ ὂ ὒ ὢ</span> - <span>ᾂ ᾒ ᾢ</span> accent circonflexe <span>Ἆ Ἦ Ἶ Ὦ</span> - <span>ᾎ ᾞ ᾮ</span> - <span>ἆ ἦ ἶ ὖ ὦ</span> - <span>ᾆ ᾖ ᾦ</span>');
addCustomCharsetMenu('Grec (esprit rude)', 'sans accent <span>Ἁ Ἑ Ἡ Ἱ Ὁ Ὑ Ὡ</span> - <span>ἁ ἑ ἡ ἱ ὁ ὑ ὡ</span> accent aigu <span>Ἅ Ἕ Ἥ Ἵ Ὅ Ὕ Ὥ</span> - <span>ᾍ ᾝ ᾭ</span> - <span>ἅ ἕ ἥ ἵ ὅ ὕ ὥ</span> - <span>ᾅ ᾕ ᾥ</span> accent grave <span>Ἃ Ἓ Ἣ Ἳ Ὃ Ὓ Ὣ</span> - <span>ᾋ ᾛ ᾫ</span> - <span>ἃ ἓ ἣ ἳ ὃ ὓ ὣ</span> - <span>ᾃ ᾓ ᾣ</span> accent circonflexe <span>Ἇ Ἧ Ἷ Ὗ</span> - <span>ᾏ ᾟ ᾯ</span> - <span>ἇ ἧ ἷ ὗ ὧ</span> - <span>ᾇ ᾗ ᾧ</span>');
addCustomCharsetMenu('Néerlandais', '<span>Ä ä Ë ë Ï ï Ö ö Ü ü Ÿ ÿ Á á É é Í í Ó ó Ú ú À à È è Ì ì Ò ò Ù ù Â â Ê ê Î î Ô ô Û û IJ ij ſ ƒ €</span>');
addCustomCharsetMenu('Phonétique', '<span>a ɑ e ɛ ə i o ɔ u y ø œ ɔ̃ ɑ̃ ɛ̃ œ̃ j w ɥ ː ‿ _́ _̀ _̌ _̂ b k ʃ d f ɡ h ʒ l m n ɲ ŋ p r s t v z ʀ ʁ</span>');
addCustomCharsetMenu('Symboles', '<span>© ℅ € № ® ™ º ¹ ² ³ ⁿ ª † ‡ ¼ ½ ¾ ⅛ ⅜ ⅝ ⅞ ‘ ’ “ ” „ ‰ ‹ › ≤ ≥ ‼ ± × ÷ ≈ ≠ ≡ ≅ ← → ↔ ⇐ ⇒ ⇔ □ ▪ ▫ ◊ ● • ◦ ♂ ♀</span>');
/*--------------------------------------------------------------------------------*/
/* Popup paramètres (dialogbox) - init event onclick pour les boutons du toolbar */
/* Délai exécution nécessaire: les boutons toolbox sont installés par js (onload) */
function initeventtoolbarbutton() {
var x = setTimeout("initeventtoolbarbutton_run()",1000);
}
/* Installe gestion event onclick sur les boutons désignés - appelé au chargement (onload) */
function initeventtoolbarbutton_run() {
/* si toolbar existe */
var tb = document.getElementById('toolbar');
if (tb == null) return;
var eb = tb.getElementsByClassName('mw-toolbar-editbutton');
for (var n = 0; n < eb.length ; n++) {
/* bouton 'Assistant Tableau' si existe dans toolbar */
if (eb[n].title.match(/Assistant [tT]ableau/)) {
eb[n].onclick = openpopuparamtable;
}
/* bouton 'Liste Modèles' si existe dans toolbar */
if (eb[n].title.match(/Liste .*[mM]odèle/)) {
eb[n].onclick = openpopuparamtemplate;
}
/* bouton 'Chercher-Remplacer' si existe dans toolbar */
if (eb[n].title.match(/[Rr]emplace/)) {
eb[n].onclick = openpopupsearchreplace;
}
/* bouton 'Coordonnées img infographie' si existe dans toolbar */
if (eb[n].title.match(/[Cc]oordonn/)) {
eb[n].onclick = openpopupinfographicoords;
}
}
}
addOnloadHook(initeventtoolbarbutton);
/* Assistant construction tableau - suite click bouton 'Assistant Tableau' dans 'toolbox' */
/* Création popup paramétrage tableau */
function openpopuparamtable(e) {
/* position bouton */
var event = e || window.event;
var x = event.clientX + (document.body.scrollLeft || document.documentElement.scrollLeft);
var y = event.clientY + (document.body.scrollTop || document.documentElement.scrollTop);
/* si un popup déjà ouvert */
if (document.getElementById('popup_param')) return;
/* création fenêtre */
var popup = document.createElement('div');
popup.setAttribute('id', 'popup_param');
var content = '<p id="titr">Paramètres du tableau</p>';
content += '<form method="post" action="#" name="popup_param_frm"><table>';
content += '<tr><td colspan="2">Style <select name="tabclass"><option value="wikitable" selected>Wikitable</option><option value="alterne">Alterné</option><option value="noborder">Sans bordure </option><option value="encadre">Encadré</option></select></td></tr>';
content += '<tr><td colspan="2">Position <input name="tabpos" type="radio" value="centre" checked />centre<input name="tabpos" type="radio" value="gauche" />gauche<input name="tabpos" type="radio" value="droite" />droite</td></tr>';
content += '<tr><td colspan="2">Intitulé <input name="tabintitul" type="text" size="25" /></td></tr>';
content += '<tr><td>Largeur relative</td><td><input name="tabwidth" type="text" size="1" /> %</td></tr>';
content += '<tr><td>Nombre de lignes</td><td><input name="tabnbrow" type="text" size="1" value="0" /></td></tr>';
content += '<tr><td>Nombre de colonnes</td><td><input name="tabnbcol" type="text" size="1" value="0" /></td></tr>';
content += '<tr><td>Titres de lignes</td><td><input name="tabtitlrow" type="checkbox" /></td></tr>';
content += '<tr><td>Titres de colonnes</td><td><input name="tabtitlcol" type="checkbox" /></td></tr>';
content += '<tr><td colspan="2">Justifié <input name="tabalign" type="radio" value="cellcentre" />centre<input name="tabalign" type="radio" value="cellgauche" checked />gauche<input name="tabalign" type="radio" value="celldroite" />droite</td></tr>';
content += '</table>';
content += '<span id="btn"><input type="button" value="Insérer" onclick="creatwikitable()" /><input type="button" value="Annuler" onclick="closepopup(\'popup_param\')" /><input type="button" value="?" onclick="helpopuparamtable()" /></span>';
content += '</form>';
popup.innerHTML = content;
document.body.appendChild(popup);
positionpopup(popup,(y+10),(x-20));
/* IE - recup position curseur avant popup */
text_cursor_position = getpositiontxtcursor(document.forms['editform'].elements['wpTextbox1']);
popup.focus();
}
/* Création code tableau syntaxe wiki insertion dans zone édition - appelé par bouton 'Insérer' du popup param tableau */
function creatwikitable() {
var row, col, wdt, pos, align;
var frm = document.forms['popup_param_frm'];
if (frm.elements['tabnbrow'].value.match(/^[0-9]+$/)) row = frm.elements['tabnbrow'].value;
if (frm.elements['tabnbcol'].value.match(/^[0-9]+$/)) col = frm.elements['tabnbcol'].value;
if (row < 1 || col < 1) return;
if (frm.elements['tabwidth'].value.match(/^[0-9]{1,3}$/)) wdt = frm.elements['tabwidth'].value;
if (wdt == undefined || wdt == 0) wdt = '';
else if (wdt < 10) wdt = 'width="10%"';
else if (wdt > 99) wdt = 'width="99%"';
else wdt = 'width="'+wdt+'%"';
/* récup sélection bouton radio */
for (var i = 0; i < frm.elements['tabpos'].length; i++) {
if (frm.elements['tabpos'][i].checked) pos = frm.elements['tabpos'][i].value;
}
for (var i = 0; i < frm.elements['tabalign'].length; i++) {
if (frm.elements['tabalign'][i].checked) align = frm.elements['tabalign'][i].value;
}
/* init début tableau + classes et style */
var result = '{| class="'+frm.elements["tabclass"].value+' '+pos+' '+align+'" '+wdt+'\n';
if (frm.elements['tabintitul'].value.length) result += '|+ '+frm.elements["tabintitul"].value+'\n';
result += '|------------------\n';
/* init entêtes de colonnes */
if (frm.elements['tabtitlcol'].checked) {
var x = 0;
if (frm.elements['tabtitlrow'].checked) x = -1;
for (var c = x; c < col ; c++) {
if (c == -1) {
result += '! scope=col |\n';
} else {
result += '! scope=col | Titre_col_'+(c+1)+'\n';
}
}
result += '|------------------\n';
}
/* cas style couleurs lignes alternées */
var enlight = 0;
if (frm.elements["tabclass"].value.match(/alterne/)) enlight = 1;
/* init cellules */
for (var r = 0; r < row ; r++){
if (frm.elements['tabtitlrow'].checked) result += '! scope=row | Titre_ligne_'+(r+1)+'\n';
for (var c = 0; c < col ; c++) result += '|Cellule_c'+(c+1)+'_r'+(r+1)+'\n';
if (enlight && !(r%2)) {
result += '|------ class="enlight"\n';
} else {
result += '|------------------\n';
}
}
result += '|}\n';
/* IE - positionne le curseur dans zone édition à position initiale avant insertion */
if (document.selection && document.selection.createRange) { // IE
insertxtatcursorpos(document.forms['editform'].elements['wpTextbox1'], text_cursor_position, result);
} else {
mw.toolbar.insertTags('', '', result);
}
closepopup('popup_param');
}
/* Affiche aide en ligne - appelé par bouton '?' du popup param tableau */
function helpopuparamtable() {
var popup = document.getElementById('popup_param');
/* si aide deja ouverte */
if (popup.innerHTML.match(/<ul id=.?aide/i)) return;
var aidetxt = "<ul id='aide'>";
aidetxt += "<li><b>Style</b> choisi parmi les modèles graphiques prédéfinis</li>";
aidetxt += "<li><b>Position</b> du tableau dans la page ('flottant' pour gauche et droite)</li>";
aidetxt += "<li><b>Intitulé</b> légende optionnelle du tableau</li>";
aidetxt += "<li><b>Largeur relative</b> du tableau en % de la page (optionnelle)</li>";
aidetxt += "<li><b>Titres lignes et colonnes</b> ajoutent les entêtes respectives (optionnels)</li>";
aidetxt += "<li><b>Justification</b> du texte dans les cellules</li>";
aidetxt += "</ul>";
popup.innerHTML += aidetxt;
}
/*---------------------------------*/
/* Liste et aide sur les modèles disponibles - suite click bouton 'Liste Modèles' dans 'toolbox' */
/* Création popup liste modèles */
function openpopuparamtemplate(e) {
/* position bouton */
var event = e || window.event;
var x = event.clientX + (document.body.scrollLeft || document.documentElement.scrollLeft);
var y = event.clientY + (document.body.scrollTop || document.documentElement.scrollTop);
/* si un popup deja ouvert */
if (document.getElementById('popup_param')) return;
if (window.XMLHttpRequest) { // Firefox
xhr_object = new XMLHttpRequest();
xhr_object2 = new XMLHttpRequest();
}
else if (window.ActiveXObject) { // IE
xhr_object = new ActiveXObject("Msxml2.XMLHTTP");
xhr_object2 = new ActiveXObject("Msxml2.XMLHTTP");
}
else return;
/* init requete serveur cherche liste des modèles */
xhr_object.open('GET', '/fr/api.php?action=query&list=allpages&apfilterredir=nonredirects&apnamespace=10&aplimit=500&format=xml&apfrom=!', true);
/* prépare action sur réponse liste différée */
xhr_object.onreadystatechange = function() {
if (xhr_object.readyState == 4 && xhr_object.status == 200) {
var pglst = xhr_object.responseXML.documentElement;
pglst = pglst.getElementsByTagName('allpages')[0].childNodes;
// recup chaque title
var tabmodl = new Array();
tabmodl[0] = '<Choisir un modèle>';
for (var i=0; i<pglst.length; i++) {
ti = pglst[i].getAttribute('title');
if (ti.match(/Documentation$/)) continue;
ti = ti.replace(/Modèle:[ÈÉÊËèéêë]/g, 'Modèle:E');
tabmodl[tabmodl.length] = ti;
}
tabmodl = tabmodl.sort();
/* remplit liste déroulante avec résultat */
var lsd = document.forms['popup_param_frm'].elements['list'];
lsd.removeChild(lsd.firstChild);
for (var i = 0; i < tabmodl.length ; i++) {
/* ajoute option dans liste */
var opt = document.createElement('option');
opt.setAttribute('value', '/fr/'+tabmodl[i]);
var val = document.createTextNode(tabmodl[i]);
opt.appendChild(val);
lsd.appendChild(opt);
}
/* action sur sélection dans liste */
lsd.onchange = function () {
var adrdoc = this.value;
var txtnod = document.getElementById('popup_param_txt');
/* requete serveur doc du modèle sélectionné */
xhr_object2.open('GET', adrdoc, true);
/* prépare action sur réponse doc différée */
xhr_object2.onreadystatechange = function() {
if (xhr_object2.readyState == 4 && xhr_object2.status == 200) {
/* filtre zone utile dans la page réponse */
var usesyntx = xhr_object2.responseText;
/* copie contenu <pre>...</pre> en conservant les \n */
var idxpre = usesyntx.search(/<pre>/i);
if (idxpre >0) {
var strpre = '';
for (var i = idxpre; i < usesyntx.length; i++) {
strpre += usesyntx[i];
if (usesyntx[i] == '>' && usesyntx[i-1] == 'e' && usesyntx[i-2] == 'r' && usesyntx[i-3] == 'p' && usesyntx[i-4] == '/' && usesyntx[i-5] == '<') break;
}
}
/* seulement paragraphes utilisation et syntaxe */
var usesyntx = usesyntx.replace(/\n/g, '');
usesyntx = usesyntx.match(/<dl><dt> ?(Utilisation|But).*<dt> ?Paramètre|<dl><dt> ?(Utilisation|But).*<dt> ?Exemple|<dl><dt> ?(Utilisation|But).*<dt> ?Voir aussi|<dl><dt> ?(Utilisation|But).*<\/dd><\/dl>/i);
if (usesyntx == null) txtnod.innerHTML = '(no text)';
else {
usesyntx = usesyntx[0].replace(/(<dl>)?<dt> ?(Paramètre|Exemple|Voir aussi)/i, '');
/* recopie contenu <pre>...</pre> avec les \n */
usesyntx = usesyntx.replace(/<pre>.*<\/pre>/i, strpre);
txtnod.innerHTML = usesyntx;
}
}
}
xhr_object2.send('');
txtnod.innerHTML = 'Requête en cours...';
}
}
}
xhr_object.send('');
/* création objet */
var popup = document.createElement('div');
popup.setAttribute('id', 'popup_param');
var content = '<p id="titr">Liste des Modèles</p>';
content += '<form method="post" action="#" name="popup_param_frm">';
content += '<div id="espace">';
content += '<select name="list" id="list"><option value="0" selected>Recherche en cours...</option></select>';
content += '<span id="popup_param_txt"></span>';
content += '</div>';
content += '<span id="btn"><input type="button" value="Insérer" onclick="insertselpopuptemplate(eval(\'xhr_object2.responseText\'))" /><input type="button" value="Ouvrir" onclick="opendocpopuptemplate(eval(\'xhr_object2.responseText\'))" /><input type="button" value="Annuler" onclick="closepopup(\'popup_param\')" /></span>';
content += '</form>';
popup.innerHTML = content;
document.body.appendChild(popup);
positionpopup(popup,(y+10),(x-20));
/* IE - recup position curseur avant popup */
text_cursor_position = getpositiontxtcursor(document.forms['editform'].elements['wpTextbox1']);
popup.focus();
}
/* Ouvre fenêtre doc complète modèle sélectionné */
function opendocpopuptemplate(page) {
if (page == null) return;
var popdoc = window.open('about:blank','popupdoctemplate','height=600,width=900,scrollbars=yes,dependent=yes');
popdoc.document.write(page);
popdoc.document.close();
}
/* Insère dans zone édit le modèle choisi - appelé par bouton 'insérer' du popup liste modèles */
function insertselpopuptemplate(page) {
if (page == null) return;
/* filtre champs syntaxe */
var modl = page.replace(/\n/g,'');
modl = modl.match(/<.?d[ld]><dt>Syntaxe[^{]*\{\{[^}{]*(\{\{[^}]*\}\})*[^}]*\}\}/gi);
modl = modl[0].replace(/^[^{]*/g,'');
/* IE - positionne le curseur dans zone édition à position initiale avant insertion */
if (document.selection && document.selection.createRange) {
insertxtatcursorpos(document.forms['editform'].elements['wpTextbox1'], text_cursor_position, modl);
} else {
mw.toolbar.insertTags('', '', modl);
}
closepopup('popup_param');
}
/*---------------------------------*/
/* Chercher-Remplacer - suite click bouton 'Chercher-Remplacer' dans 'toolbox' */
/* Création popup remplacer */
function openpopupsearchreplace(e) {
/* position bouton */
var event = e || window.event;
var x = event.clientX + (document.body.scrollLeft || document.documentElement.scrollLeft);
var y = event.clientY + (document.body.scrollTop || document.documentElement.scrollTop);
/* si un popup déjà ouvert */
if (document.getElementById('popup_param')) return;
/* création fenêtre */
var popup = document.createElement('div');
popup.setAttribute('id', 'popup_param');
var content = '<p id="titr">Chercher-Remplacer</p>';
content += '<form method="post" action="#" name="popup_param_frm"><table>';
content += '<tr><td><input name="srchrepl" type="radio" value="1"/></td><td>remplace espaces simples par insécables après "«"<br>et avant "»" dans un lien local</td></tr>';
content += '<tr><td><input name="srchrepl" type="radio" value="2"/></td><td>remplace espaces simples par insécables après<br>tiret quadratin en début de ligne</td></tr>';
content += '<tr><td><input name="srchrepl" type="radio" value="0" checked/></td><td>remplacement libre :</td></tr>';
content += '<tr><td>expr. </td><td><input name="srchrplC" type="text" size="48" /></td></tr>';
content += '<tr><td>repl. </td><td><input name="srchrplR" type="text" size="48" /></td></tr>';
content += '<tr><td></td><td>global <input name="srchrplG" type="checkbox" /> nocase <input name="srchrplI" type="checkbox" /> multiline <input name="srchrplM" type="checkbox" /></td></tr>';
content += '</table>';
content += '<span id="btn"><input type="button" value="Remplacer" onclick="execsearchreplace()" /><input type="button" value="Rétablir" onclick="undosearchreplace()" /><input type="button" value="Fermer" onclick="closepopup(\'popup_param\')" /><input type="button" value="?" onclick="helpopupsearchreplace()" /></span>';
content += '</form>';
popup.innerHTML = content;
document.body.appendChild(popup);
positionpopup(popup,(y+10),(x-20));
/* IE - recup position curseur avant popup */
//text_cursor_position = getpositiontxtcursor(document.forms['editform'].elements['wpTextbox1']);
popup.focus();
}
/* Exec chercher-remplacer - appelé par bouton 'Remplacer' du popup remplacer */
var contentsearchreplace;
function execsearchreplace() {
var content = document.forms['editform'].elements['wpTextbox1'].value;
contentsearchreplace = content;
var frm = document.forms['popup_param_frm'];
/* récup sélection bouton radio */
for (var i = 0; i < frm.elements['srchrepl'].length; i++) {
if (frm.elements['srchrepl'][i].checked) var sel = frm.elements['srchrepl'][i].value;
}
switch (sel) {
case '1':
content=content.replace(/(\[\[[^|]+\|)(« )([^»]+)( »)([^\]]*\]\])/g, '$1« $3 »$5');
break;
case '2':
content=content.replace(/(\n\:)(—\s)|(\n)(—\s)|(\n\{\{p\|)(—\s)|(\n\{\{p\|([^\|]+\|){1,3})(—\s)/g, '$1$3$5$7— ');
break;
case '0':
var sch = frm.elements['srchrplC'].value;
var rpl = frm.elements['srchrplR'].value;
if (sch.length >0) {
var flg1="",flg2="",flg3="";
if (frm.elements['srchrplG'].checked) flg1 = "g";
if (frm.elements['srchrplI'].checked) flg2 = "i";
if (frm.elements['srchrplM'].checked) flg3 = "m";
var re = new RegExp(sch, flg1+flg2+flg3);
content = content.replace(re, rpl);
}
break;
}
// insertion modifs dans zone edit
document.forms['editform'].elements['wpTextbox1'].value = content;
//closepopup('popup_param');
}
/* Exec chercher-remplacer - appelé par bouton 'Défaire' du popup remplacer */
function undosearchreplace() {
document.forms['editform'].elements['wpTextbox1'].value = contentsearchreplace;
}
/* Affiche aide en ligne - appelé par bouton '?' du popup remplacer */
function helpopupsearchreplace() {
var popup = document.getElementById('popup_param');
/* si aide deja ouverte */
if (popup.innerHTML.match(/<ul id=.?aide/i)) return;
var aidetxt = "<ul id='aide'>";
aidetxt += "<li>Supporte les expressions régulières de la méthode js replace()";
aidetxt += "<br> (voir http://fr.wikipedia.org/wiki/Expression_rationnelle";
aidetxt += "<br> et http://www.pagecolumn.com/tool/regtest.htm).</li>";
aidetxt += "<li>Quelques motifs de remplacement courants sont pré-définis.</li>";
aidetxt += "</ul>";
popup.innerHTML += aidetxt;
}
/*---------------------------------*/
/* Coordonnées infographie - suite click bouton dans 'toolbox' */
/* Création popup */
function openpopupinfographicoords(e) {
/* position bouton */
var event = e || window.event;
var x = event.clientX;
var y = event.clientY;
/* si un popup déjà ouvert */
if (document.getElementById('popup_param')) return;
/* recherche adr img */
var txt = document.getElementById('wpTextbox1').value;
var tabtxt = txt.split(/\{\{[Ii]nfographie[^|]*\|/);
if (tabtxt[1] == undefined) return;
var src = tabtxt[1].replace(/\n/,'');
var src = src.split('|');
src = src[0].replace(/(image=)(<nowiki>)?([^<]+)(<\/nowiki>)?/,'$3');
if (src.length <10) return;
/* création fenêtre popup */
var popup = document.createElement('div');
popup.setAttribute('id', 'popup_param');
popup.setAttribute('style', 'height:60px;');
var content = '<p id="titr">Coordonnées infographie</p>';
content += '<form method="post" action="#" name="popup_param_frm">';
content += '<span><input name="coords" type="text" size="20" /> <input type="button" value="Fermer" onclick="endinfographicoordimg();"</span>';
content += '</form>';
popup.innerHTML = content;
document.body.appendChild(popup);
positionpopup(popup,(y+10),(x-20));
//popup.focus();
/* load img */
var imgfond = new Image();
imgfond.onload = function() {openpopupinfographicoords2(imgfond,(x-250),(y+100));}
imgfond.src = src;
}
/* suite init popup apres load img */
function openpopupinfographicoords2(imgfond,xorg,yorg) {
var newimg = document.createElement('div');
newimg.setAttribute('id', 'newimg');
newimg.setAttribute('style', 'position:absolute; overflow:auto; top:'+yorg+'px; left:'+xorg+'px; height:300px; width:650px; border:1px solid; cursor:crosshair; z-index:10;');
document.body.appendChild(newimg);
// zoom image x2
var imgwidth = (2*imgfond.width);
newimg.innerHTML = '<img id="newmap" src="'+imgfond.src+'" width="'+imgwidth+'" />';
document.getElementById('newmap').onmousemove = runinfographicoordimg;
}
/* gestion coordonnees img */
function runinfographicoordimg(e) {
var div = document.getElementById('newimg');
var event = e || window.event;
var x = event.clientX;
var y = event.clientY;
// affichage
var out = document.forms['popup_param_frm'];
// correction coords zoom img /2
out.elements['coords'].value = "x="+Math.round((x-div.offsetLeft+div.scrollLeft+window.pageXOffset)/2)+" y="+Math.round((y-div.offsetTop+div.scrollTop+window.pageYOffset)/2);
}
function endinfographicoordimg() {
document.body.removeChild(document.getElementById('newimg'));
closepopup('popup_param');
}
/*--------------------------------------------------------------------------------*/