changeset 1672:be1d08c529c4

Clean up tooltip.js and make it work with stricter content security settings.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 26 Jan 2017 21:36:12 +0200
parents 1b7d970c2e02
children f54c268a3a6e
files tooltip.js
diffstat 1 files changed, 78 insertions(+), 65 deletions(-) [+]
line wrap: on
line diff
--- a/tooltip.js	Sat Jan 21 01:05:53 2017 +0200
+++ b/tooltip.js	Thu Jan 26 21:36:12 2017 +0200
@@ -1,117 +1,130 @@
+//
 // 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)
+function shc(uid, ucolor)
 {
-	document.getElementById(n).style['background'] = k;
+  document.getElementById(uid).style['background'] = ucolor;
 }
 
 
 // Hilite map and list elements of given number
-function qh(n)
+function qh(marker)
 {
-	if (myhl >= 0) qn(myhl);
-	shc('maploc'+n, 'white');
-	shc('listloc'+n, 'white');
-	myhl = n;
+  if (myhl >= 0) qn(myhl);
+  shc('maploc'+marker, 'white');
+  shc('listloc'+marker, 'white');
+  myhl = marker;
 }
 
 // Unlite
-function qn(n)
+function qn(marker)
 {
-	shc('maploc'+n, 'black');
-	shc('listloc'+n, 'black');
-	myhl = -1;
-	htt();
+  shc('maploc'+ marker, 'black');
+  shc('listloc'+ marker, 'black');
+  myhl = -1;
+  htt();
 }
 
 
 // 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;
-		var boxW = mytt.clientWidth + 25, boxH = mytt.clientHeight + 25;
+  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;
+    var boxW = mytt.clientWidth + 25, boxH = mytt.clientHeight + 25;
 
-		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;
-		}
+    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;
+    }
 
-		if (x + boxW + 15 >= winW)
-			x -= boxW;
-		else
-			x += 15;
+    if (x + boxW + 15 >= winW)
+      x -= boxW;
+    else
+      x += 15;
 
-		if (y + boxH + 15 >= winH)
-			y -= boxH;
-		else
-			y += 15;
+    if (y + boxH + 15 >= winH)
+      y -= boxH;
+    else
+      y += 15;
 
-		myx = x; myy = y;
+    myx = x; myy = y;
 
-		mytt.style.left = x + "px";
-		mytt.style.top 	= y + "px";
-	}
+    mytt.style.left = x + "px";
+    mytt.style.top  = y + "px";
+  }
 }
 
 // Show tooltip
 function stt(id)
 {
-	if (mytt) {
-		mytt.style.display = "none";
-	}
+  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";
+  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";
-	}
+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)
+
+function httBlink(marker)
 {
-	httST = !httST;
-	var mcolor = httST ? "white" : "black";
-	shc("maploc"+id, mcolor);
-	shc("listloc"+id, mcolor);
+  httST = !httST;
+  var mcolor = httST ? "white" : "black";
+  shc("maploc"+ marker, mcolor);
+  shc("listloc"+ marker, mcolor);
 }
 
 
 function httOnLoad()
 {
-	var s = window.location.href;
-	if (s.indexOf("?") >= 0) {
-		var n = unescape(s.substr(s.indexOf("?")+1).toLowerCase());
-		httID = setInterval("httBlink('"+n+"')", 500);
-	}
+  var hstr = window.location.href;
+  if (hstr.indexOf("?") >= 0)
+  {
+    var name = unescape(hstr.substr(hstr.indexOf("?") + 1).toLowerCase());
+    httID = setInterval(function (qname) { httBlink(qname); }, 500, name);
+  }
 }