« MediaWiki:Gadget-AncreTitres.js » : différence entre les versions

Un livre de Wikilivres.
Contenu supprimé Contenu ajouté
Pabix (discussion | contributions)
mAucun résumé des modifications
Pabix (discussion | contributions)
m et voilà, ça marche mieux maintenant !
Ligne 7 : Ligne 7 :
*
*
* Auteurs : Pabix, Phe
* Auteurs : Pabix, Phe
* Date de dernière révision : 14 août 2007
* Date de dernière révision : 15 août 2007
*/
*/

var AncreTitres={
//////////////////////ZONE PERSONNALISABLE//////////////////////
nom_ancre : "[URL]",
var AncreTitres_nom_ancre = "[URL]"; // Texte lien externe
nom_lien_interne : "[[lien]]",
var AncreTitres_nom_lien_interne = "[[lien]]"; // Texte lien interne
var AncreTitres_description = "Obtenir une URL vers cette section"; // Infobulle du lien
description : "Obtenir une URL vers cette section",
var AncreTitres_descinterne = "Obtenir [[Lien#interne]]"; // Infobulle du lien
descinterne : "Obtenir un [[Lien#interne]]",
linkcolor : "blue",
var AncreTitres_linkcolor="blue"; // Couleur du lien
fontSize : "50%",
var AncreTitres_fontSize="50%"; // Taille du lien
afficheE : true,
var AncreTitres_afficheE="true"; // Afficher le lien externe
afficheI : true,
var AncreTitres_afficheI="true"; // Afficher le lien interne
noeud_precedent : function(noeud) {
/////////////////FIN DE LA ZONE PERSONNALISABLE/////////////////
while (noeud.previousSibling.nodeType!=1){

noeud = noeud.previousSibling;
if (noeud==null) return undefined;
}
return noeud.previousSibling;
}
}
function ancrer(){
function ancrer(){
function noeud_precedent(noeud) {
while (noeud.previousSibling.nodeType!=1)
noeud = noeud.previousSibling;
return noeud.previousSibling;

}
if (!document.getElementById('content')) return;
if (!document.getElementById('content')) return;
var titres = document.getElementsByTagName("span");
var titres = document.getElementsByTagName("span");
Ligne 34 : Ligne 34 :
for (i = 0 ; i < titres.length ; i++){
for (i = 0 ; i < titres.length ; i++){
var titre_courant = titres[i].parentNode;
var titre_courant = titres[i].parentNode;
if (!titres[i].className.match(/mw-headline/g)) continue;
if (!(titres[i].className.match(/mw-headline/gi))) continue;
if (!noeud_precedent(titre_courant)) continue;
if (!AncreTitres.noeud_precedent(titre_courant)) continue;
var ancre_nom;
if (!noeud_precedent(titre_courant).lastChild) continue;
if (!noeud_precedent(titre_courant).lastChild.name) continue;
if (AncreTitres.noeud_precedent(titre_courant).lastChild != null){
var ancre_nom = noeud_precedent(titre_courant).lastChild.name;
ancre_nom = AncreTitres.noeud_precedent(titre_courant).lastChild.name;
} else {
ancre_nom = AncreTitres.noeud_precedent(titre_courant).name;
}
var small;
var small;
var link;
var link;
if (AncreTitres_afficheE) {
if (AncreTitres.afficheE) {
small = document.createElement('small'); with(small) {
small = document.createElement('small'); with(small) {
innerHTML=AncreTitres_nom_ancre;
innerHTML=AncreTitres.nom_ancre;
title=AncreTitres_description;
title=AncreTitres.description;
style.color=AncreTitres_linkcolor;
style.color=AncreTitres.linkcolor;
style.fontSize=AncreTitres_fontSize;
style.fontSize=AncreTitres.fontSize;
}
link = document.createElement('a'); with(link) {
setAttribute("ancre", wgServer + wgScriptPath + "/index.php?title=" + wgPageName + "#" + ancre_nom) ;
setAttribute("onclick", "window.prompt('Lien : ', this.getAttribute('ancre'));");
appendChild(small);
}
}
link = document.createElement('a');
link.setAttribute("ancre", wgServer + "/w/index.php?title=" + wgPageName + "#" + ancre_nom) ;
link.setAttribute("onclick", "window.prompt('Lien : ', this.getAttribute('ancre'));");
link.appendChild(small);
titre_courant.appendChild(link);
titre_courant.appendChild(link);
}
}
if (AncreTitres_afficheI) {
if (AncreTitres.afficheI) {
small = document.createElement('small'); with(small) {
small = document.createElement('small'); with(small) {
innerHTML=AncreTitres_nom_lien_interne;
innerHTML=AncreTitres.nom_lien_interne;
title=AncreTitres_descinterne;
title=AncreTitres.descinterne;
style.color=AncreTitres_linkcolor;
style.color=AncreTitres.linkcolor;
style.fontSize=AncreTitres_fontSize;
style.fontSize=AncreTitres.fontSize;
}
link = document.createElement('a'); with(link) {
setAttribute("ancre", "[[" + wgPageName + "#" + ancre_nom + "]]");
setAttribute("onclick", "window.prompt('Lien : ', this.getAttribute('ancre'));");
appendChild(small);
}
}
link = document.createElement('a');
link.setAttribute("ancre", "[[" + wgPageName + "#" + ancre_nom + "]]");
link.setAttribute("onclick", "window.prompt('Lien : ', this.getAttribute('ancre'));");
link.appendChild(small);
titre_courant.appendChild(link);
titre_courant.appendChild(link);
}
}
}
}
}
}
addOnloadHook(ancrer);
addOnLoadHook(ancrer);
//

Version du 15 août 2007 à 11:03

//[[Image:AncreTitres JS.png|thumb|300px|Illustration]]<source lang="javascript" line="">
/*
 * AncreTitres
 *
 * Cette fonction fournit un lien vers une section de page en cliquant
 * sur le lien [ancre] à droite du titre de section.
 *
 * Auteurs : Pabix, Phe
 * Date de dernière révision : 15 août 2007
 */
 
var AncreTitres={
nom_ancre : "[URL]",
nom_lien_interne : "[[lien]]",
description : "Obtenir une URL vers cette section",
descinterne : "Obtenir un [[Lien#interne]]",
linkcolor : "blue",
fontSize : "50%",
afficheE : true,
afficheI : true,
noeud_precedent : function(noeud) {
        while (noeud.previousSibling.nodeType!=1){
    	    noeud = noeud.previousSibling;
	    if (noeud==null) return undefined;
        }
        return noeud.previousSibling;
}
}
function ancrer(){
	if (!document.getElementById('content')) return;
	var titres = document.getElementsByTagName("span");
	var i = 0;
	var titre_courant;
	for (i = 0 ; i < titres.length ; i++){
		var titre_courant = titres[i].parentNode;	
		if (!(titres[i].className.match(/mw-headline/gi))) continue;
		if (!AncreTitres.noeud_precedent(titre_courant)) continue;
		var ancre_nom;
		if (AncreTitres.noeud_precedent(titre_courant).lastChild != null){
			ancre_nom = AncreTitres.noeud_precedent(titre_courant).lastChild.name;
		} else {
			ancre_nom = AncreTitres.noeud_precedent(titre_courant).name;
		}
		var small;
		var link;
		if (AncreTitres.afficheE) {
			small = document.createElement('small'); with(small) {
				innerHTML=AncreTitres.nom_ancre;
				title=AncreTitres.description;
				style.color=AncreTitres.linkcolor;
				style.fontSize=AncreTitres.fontSize;
			}
			link = document.createElement('a'); 
			link.setAttribute("ancre", wgServer + "/w/index.php?title=" + wgPageName + "#" + ancre_nom) ;
			link.setAttribute("onclick", "window.prompt('Lien : ', this.getAttribute('ancre'));");
			link.appendChild(small);
			titre_courant.appendChild(link);
		}
		if (AncreTitres.afficheI) {
			small = document.createElement('small'); with(small) {
				innerHTML=AncreTitres.nom_lien_interne;
				title=AncreTitres.descinterne;
				style.color=AncreTitres.linkcolor;
				style.fontSize=AncreTitres.fontSize;
			}
			link = document.createElement('a');
			link.setAttribute("ancre", "[[" + wgPageName + "#" + ancre_nom + "]]");
			link.setAttribute("onclick", "window.prompt('Lien : ', this.getAttribute('ancre'));");
			link.appendChild(small);
			titre_courant.appendChild(link);
		}
	}
}
addOnLoadHook(ancrer);