MediaWiki:Gadget-Scriptus.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.//<source lang="javascript" line>
/*
* PapierAjax
*
* La fonction PapierAjax sert à rédiger sur wikipédia de manière naturelle,
* par simple doubleclic et confimation de sauvegarde.
* La définition de ce script se trouve ici :
* http://fr.wikipedia.org/wiki/Wikip%C3%A9dia:Brouillons/interface_ajax
*
* Le code du script est librement inspiré du système de modification-inline de Olivier Lance
* http://olance.developpez.com/articles/web/javascript/modification-inline/
*
* Auteurs : ivo talvet (fr:user:Tavernier)
* Date de dernière révision : 13 septembre 2007
*/
function findBlocPapierAjax(numSection) {
return function(){alert("section " + numSection + " cliquée");};
}
function PapierAjax() {
if (!wgIsArticle) return; //si non editable, sortie
var contenuIntro = wpajaxPapierAjax.http({ url: wgServer+wgScriptPath+'/api.php?action=query&prop=revisions&rvprop=content&titles='+encodeURIComponent(wgTitle),
onSucces: alert("contenu intro : " + contenuIntro)});
alert("type de l'objet ajax : " + typeof(contenuIntro));
var intro = getElementsByClass("firstHeading")[0];
intro.addEventListener("dblclick", findBlocPapierAjax(0), false);
var sections = getElementsByClass("mw-headline");
for each (var section in sections) {
var hrefSection = getElementsByClass("editsection", section.parentNode)[0].getElementsByTagName('a')[0].getAttribute('href');
var numSection = hrefSection.replace(/.*section=([0-9]+)/g, '$1');
section.addEventListener("dblclick", findBlocPapierAjax(numSection), false);
}
}
var wpajaxPapierAjax = { // depuis http://fr.wikipedia.org/wiki/Utilisateur:EDUCA33E/LiveRC.js
http: function(bundle) {
// mandatory: bundle.url
// optional: bundle.async
// optional: bundle.method
// optional: bundle.headers
// optional: bundle.data
// optional: bundle.onSuccess (xmlhttprequest, bundle)
// optional: bundle.onFailure (xmlhttprequest, bundle)
// optional: bundle.otherStuff OK too, passed to onSuccess and onFailure
var xmlhttp;
try {
xmlhttp = new XMLHttpRequest();
} catch(e) {
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
xmlhttp = false
}
}
}
if (xmlhttp) {
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4)
wpajaxPapierAjax.httpComplete(xmlhttp,bundle);
};
xmlhttp.open(bundle.method ? bundle.method : "GET",bundle.url,bundle.async == false ? false : true);
if (bundle.headers) {
for (var field in bundle.headers)
xmlhttp.setRequestHeader(field,bundle.headers[field]);
}
xmlhttp.send(bundle.data ? bundle.data : null);
}
return xmlhttp;
},
httpComplete: function(xmlhttp,bundle) {
if (xmlhttp.status == 200 || xmlhttp.status == 302) {
if (bundle.onSuccess)
bundle.onSuccess(xmlhttp,bundle);
} else if (bundle.onFailure) {
bundle.onFailure(xmlhttp,bundle);
} else {
// A activer en debug mode ?
// alert(xmlhttp.statusText);
}
}
};
addLoadEvent(PapierAjax);
//</source>[[Catégorie:MediaWiki:Fonction Monobook en JavaScript]]