Mercurial > hg > batmud > maputils
view tooltip.js @ 945:81184d58133c aprilli2011
Sync.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 14 May 2010 11:18:20 +0000 |
parents | f48f9538cb29 |
children | 03c6e45fe776 |
line wrap: on
line source
// Tooltip and other utility functions in JavaScript for BatMUD maps // by Matti 'ccr' Hamalainen (Ggr Pupunen) <ccr@tnsp.org> var myhl = -1; var mytt = null; var myx = 0; var myy = 0; document.onmousemove = utt; // Change background style of given element function shc(n, k) { document.getElementById(n).style['background'] = k; } // Hilite map and list elements of given number function qh(n) { if (myhl >= 0) qn(myhl); shc('maploc'+n, 'white'); shc('listloc'+n, 'white'); myhl = n; } // Unlite function qn(n) { shc('maploc'+n, 'black'); shc('listloc'+n, 'black'); myhl = -1; } // Update the tooltip box function utt(e) { x = (document.all) ? window.event.x + document.body.scrollLeft : e.pageX; y = (document.all) ? window.event.y + document.body.scrollTop : e.pageY; if (mytt != null) { var winW = 0, winH = 0; if (typeof(window.innerWidth) == 'number') { // Non-MSIE winW = window.innerWidth; winH = window.innerHeight; } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) { // MSIE 6+ in 'standards compliant mode' winW = document.documentElement.clientWidth; winH = document.documentElement.clientHeight; } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) { // MSIE 4 compatible winW = document.body.clientWidth; winH = document.body.clientHeight; } x += 15; y += 15; if (x + 250 > winW) { x -= (x + 250 - winW); } // if (y + 50 > winH) { y -= (y + 50 - winH); } myx = x; myy = y; mytt.style.left = x + "px"; mytt.style.top = y + "px"; } } // Show tooltip function stt(id) { if (mytt) { mytt.style.display = "none"; } mytt = document.getElementById("tt"+id); mytt.style.left = myx + "px"; mytt.style.top = myy + "px"; mytt.style.display = "block"; } // Hide tooltip function htt() { if (mytt) { mytt.style.display = "none"; } } // Highlight one location (by index number) during page load var httID; var httST = 0; function httBlink(id) { httST = !httST; var mcolor = httST ? "white" : "black"; shc("maploc"+id, mcolor); shc("listloc"+id, mcolor); } function httOnLoad() { var s = window.location.href; if (s.indexOf("?") >= 0) { var n = parseInt(unescape(s.substr(s.indexOf("?")+1).toLowerCase())); if (n != NaN) { httID = setInterval("httBlink("+n+")", 500); } } }