« 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)
mAucun résumé des modifications
Ligne 7 : Ligne 7 :
*
*
* Auteurs : Pabix, Phe
* Auteurs : Pabix, Phe
* Date de dernière révision : 11 mars 2007
* Date de dernière révision : 14 août 2007
*/
*/


Ligne 22 : Ligne 22 :


function ancrer(){
function ancrer(){
function noeud_precedent(noeud) {
function noeud_precedent(noeud) {
while (noeud.previousSibling.nodeType!=1)
while (noeud.previousSibling.nodeType!=1)
noeud = noeud.previousSibling;
noeud = noeud.previousSibling;
return 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");
var i = 0;
var i = 0;
var titre_courant;
var titre_courant;
boucle1 : while (titre_courant=titres[i]){
for (i = 0 ; i < titres.length ; i++){
var titre_courant = titres[i].parentNode;
i++;
if (titre_courant.className.match(/mw-headline/g)) {
if (!titres[i].className.match(/mw-headline/g)) continue;
if (!noeud_precedent(titre_courant)) continue;
var ancre_nom;
if (noeud_precedent(titre_courant.parentNode).lastChild) {
if (!noeud_precedent(titre_courant).lastChild) continue;
if (noeud_precedent(titre_courant.parentNode).lastChild.name) {
if (!noeud_precedent(titre_courant).lastChild.name) continue;
ancre_nom = noeud_precedent(titre_courant.parentNode).lastChild.name;
var ancre_nom = noeud_precedent(titre_courant).lastChild.name;
var small;
} else continue boucle1;
var link;
} else continue boucle1;
if (AncreTitres_afficheE) {
var 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;
}
}
var link = document.createElement('a'); with(link) {
link = document.createElement('a'); with(link) {
setAttribute("ancre", wgServer + wgScriptPath + "/index.php?title=" + wgPageName + "#" + ancre_nom) ;
setAttribute("ancre", wgServer + wgScriptPath + "/index.php?title=" + wgPageName + "#" + ancre_nom) ;
setAttribute("onclick", "window.prompt('Lien : ', this.getAttribute('ancre'));");
setAttribute("onclick", "window.prompt('Lien : ', this.getAttribute('ancre'));");
appendChild(small);
appendChild(small);
}
}
if (AncreTitres_afficheE) titre_courant.parentNode.appendChild(link);
titre_courant.appendChild(link);
small = document.createElement('small'); with(small) {
}
innerHTML=AncreTitres_nom_lien_interne;
if (AncreTitres_afficheI) {
title=AncreTitres_descinterne;
small = document.createElement('small'); with(small) {
style.color=AncreTitres_linkcolor;
innerHTML=AncreTitres_nom_lien_interne;
style.fontSize=AncreTitres_fontSize;
title=AncreTitres_descinterne;
}
style.color=AncreTitres_linkcolor;
link = document.createElement('a'); with(link) {
style.fontSize=AncreTitres_fontSize;
setAttribute("ancre", "[[" + wgPageName + "#" + ancre_nom + "]]");
}
setAttribute("onclick", "window.prompt('Lien : ', this.getAttribute('ancre'));");
link = document.createElement('a'); with(link) {
appendChild(small);
setAttribute("ancre", "[[" + wgPageName + "#" + ancre_nom + "]]");
}
setAttribute("onclick", "window.prompt('Lien : ', this.getAttribute('ancre'));");
if (AncreTitres_afficheI) titre_courant.parentNode.appendChild(link);
appendChild(small);
}
}
}
titre_courant.appendChild(link);
}
}
}
}
addOnloadHook(ancrer);
addOnloadHook(ancrer);
//
//</source>[[Catégorie:MediaWiki:Fonction Monobook en JavaScript]]

Version du 14 août 2007 à 08:27

//[[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 : 14 août 2007
 */

//////////////////////ZONE PERSONNALISABLE//////////////////////
var AncreTitres_nom_ancre = "[URL]";                                // Texte lien externe
var AncreTitres_nom_lien_interne = "[[lien]]";                      // Texte lien interne
var AncreTitres_description = "Obtenir une URL vers cette section"; // Infobulle du lien
var AncreTitres_descinterne = "Obtenir [[Lien#interne]]";           // Infobulle du lien
var AncreTitres_linkcolor="blue";                                   // Couleur du lien
var AncreTitres_fontSize="50%";                                     // Taille du lien
var AncreTitres_afficheE="true";                                    // Afficher le lien externe
var AncreTitres_afficheI="true";                                    // Afficher le lien interne
/////////////////FIN DE LA ZONE PERSONNALISABLE/////////////////

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

	}
	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/g)) continue;
		if (!noeud_precedent(titre_courant)) continue;
		if (!noeud_precedent(titre_courant).lastChild) continue;
		if (!noeud_precedent(titre_courant).lastChild.name) continue;
		var ancre_nom = noeud_precedent(titre_courant).lastChild.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'); with(link) {
				setAttribute("ancre", wgServer + wgScriptPath + "/index.php?title=" + wgPageName + "#" + ancre_nom) ;
				setAttribute("onclick", "window.prompt('Lien : ', this.getAttribute('ancre'));");
				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'); with(link) {
				setAttribute("ancre", "[[" + wgPageName + "#" + ancre_nom + "]]");
				setAttribute("onclick", "window.prompt('Lien : ', this.getAttribute('ancre'));");
				appendChild(small);
			}
			titre_courant.appendChild(link);
		}
	}
}
addOnloadHook(ancrer);
//