User:DarkRyder/zonemap.js

/* */

addOnloadHook(function {

function getNoteTip { var tip = document.getElementById("ZoneMapToolTip");

if (!tip) { var tip = document.createElement("div"); //tip.className = "itemtooltip"; tip.id = "ZoneMapToolTip"; tip.style.background = "#111"; tip.style.border = "1px solid #bbb"; tip.style.color = "#fff"; tip.style.display = "none"; tip.style.margin = "0"; tip.style.MozBorderRadius = "0.75ex"; tip.style.padding = "0.3em"; tip.style.position = "absolute"; tip.style.zIndex = "1000";

document.getElementsByTagName("body")[0].appendChild(tip); }

return tip; }

function hideNoteTip { getNoteTip.style.display = "none"; }

function showNoteTip(event) { var elm, tip;

if (!(event = event ? event : window.event)) return; if (!(elm = (event.currentTarget ? event.currentTarget : this))) return; if (!(tip = getNoteTip)) return;

if (event.pageX) { tip.style.left = (event.pageX - event.layerX + 20) + "px"; tip.style.top = (event.pageY - event.layerY) + "px"; } else if (event.clientX) { var body = document.documentElement ? document.documentElement : document.body;

tip.style.left = (event.clientX + body.scrollLeft - event.offsetX + 20) + "px"; tip.style.top = (event.clientY + body.scrollTop - event.offsetY) + "px"; } else { return; // fail silently }

if (elm.getAttribute) { tip.innerHTML = elm.getAttribute("tipHTML"); } else { tip.innerHTML = elm.tipHTML; }

// TODO: this is working in Gecko, but not in MSHTML /*	if (tip.clientWidth) { tip.lastChild.style.left = (tip.clientWidth - tip.lastChild.offsetWidth - tip.lastChild.offsetLeft * 2) + "px"; }*/

tip.style.display = ""; }

var rx_map = /(^|\s)ZoneMapContainer($|\s)/; var rx_note = /(^|\s)ZoneMapNote($|\s)/; var rx_at = /^(.*)[\u00a0\s]+@[\u00a0\s]+(\d+(?:\.\d+)?,\d+(?:\.\d+)?)/; var str_repl = ' $1 $2 ';

var elms = document.getElementsByTagName("img");

for (var i = 0; i < elms.length; i++) { var elm = elms[i];

if (elm.parentNode.parentNode.className.match(rx_note)) { if (elm.setAttribute) { elm.parentNode.setAttribute("tipHTML", ' ' + elm.parentNode.innerHTML + ' ' + elm.parentNode.getAttribute("title").replace(rx_at, str_repl)); elm.parentNode.setAttribute("title", ""); elm.setAttribute("alt", ""); elm.setAttribute("longdesc", ""); } else { elm.parentNode.tipHTML = elm.parentNode.title.replace(rx_at, str_repl); elm.parentNode.title = ""; elm.alt = ""; elm.longdesc = ""; }

if (elm.addEventListener) { elm.parentNode.addEventListener("mouseover", showNoteTip, false); elm.parentNode.addEventListener("mouseout", hideNoteTip, false); } else { elm.parentNode.onmouseover = showNoteTip; elm.parentNode.onmouseout = hideNoteTip; }	} else if (elm.parentNode.parentNode.parentNode.className.match(rx_map)) { if (elm.setAttribute) { elm.parentNode.setAttribute("title", ""); elm.setAttribute("alt", ""); elm.setAttribute("longdesc", ""); } else { elm.parentNode.title = ""; elm.alt = ""; elm.longdesc = ""; }	} }

});

//