Utilisateur:Dr Brains/HighLightMaps.js
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.// {{Catégorisation JS}}
//<syntaxhighlight lang=javascript>//<pre>//<nowiki>
if(typeof(HighLightMaps)==="undefined"){
var HighLightMaps = new Object();
HighLightMaps.Variables = new Object();
HighLightMaps.Variables.HighLightBorderColor = "red";
HighLightMaps.Variables.HighLightBackgroundColor = "IndianRed";
HighLightMaps.Variables.Index = new Array();
HighLightMaps.Functions = new Object();
HighLightMaps.Functions.Init = function(){
var Maps = $.makeArray( $(document).find('table.DebutCarte') );
for(var a=0,l=Maps.length;a<l;a++){
HighLightMaps.Functions.InitMap(Maps[a], a);
}
}
HighLightMaps.Functions.InitMap = function(Map, MapIndex){
var Index = HighLightMaps.Variables.Index.length;
var Toponymes = $.makeArray( $(Map).find('span.toponyme') );
for(var t=0,tlen=Toponymes.length;t<tlen;t++){
var Toponyme = Toponymes[t];
var Image = HighLightMaps.Functions.getImageFromToponyme(Toponyme);
if(!Image) continue;
Toponyme.id = "HighLightMaps_toponyme_"+Index;
Image.id = "HighLightMaps_image_"+Index;
Toponyme.onmouseover = function(){ HighLightMaps.Functions.HighLightEnabled(this); };
Toponyme.onmouseout = function(){ HighLightMaps.Functions.HighLightDisabled(this); };
HighLightMaps.Variables.Index.push({"toponyme":Toponyme,"image":Image});
}
}
HighLightMaps.Functions.getImageFromToponyme = function(Toponyme){
var ParentDiv = Toponyme.parentNode;
while(ParentDiv.tagName.toLowerCase() != 'div'){
ParentDiv = ParentDiv.parentNode;
if(!ParentDiv) break;
if(ParentDiv.tagName.toLowerCase() == 'div') break;
}
if(!ParentDiv) return false;
var ImageParentDiv = ParentDiv.previousSibling;
if(!ImageParentDiv || !ImageParentDiv.getElementsByTagName) return false;
var Image = ImageParentDiv.getElementsByTagName('img')[0];
if(!Image) return false;
return Image;
}
HighLightMaps.Functions.HighLightEnabled = function(toponyme){
var Index = toponyme.id.split("HighLightMaps_toponyme_").join("");
var Image = document.getElementById("HighLightMaps_image_"+Index);
if(!Image) return
Image.style.border = "1px solid "+HighLightMaps.Variables.HighLightBorderColor;
Image.style.backgroundColor = HighLightMaps.Variables.HighLightBackgroundColor;
}
HighLightMaps.Functions.HighLightDisabled = function(toponyme){
var Index = toponyme.id.split("HighLightMaps_toponyme_").join("");
var Image = document.getElementById("HighLightMaps_image_"+Index);
if(!Image) return
Image.style.border = "";
Image.style.backgroundColor = "";
}
$(HighLightMaps.Functions.Init);
}
//</nowiki></pre></syntaxhighlight>