changeset 2166:9eacd101a9df

Improvements to the mkcitymap tooltip and hilight handling.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 11 Oct 2019 08:06:39 +0300
parents b86fcd501e1c
children 02cd710e738c
files mkcitymap.c tooltip.js
diffstat 2 files changed, 30 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/mkcitymap.c	Fri Oct 11 07:42:15 2019 +0300
+++ b/mkcitymap.c	Fri Oct 11 08:06:39 2019 +0300
@@ -104,19 +104,11 @@
 void outputLocationHTML(FILE *outFile, const LocMarker *marker, const int nname)
 {
     fprintf(outFile,
-    "<a class=\"loc\" id=\"listloc%d_%d\" href=\"?%d_%d\" onmouseover=\"qh('%d_%d')",
-    marker->xc, marker->yc,
-    marker->xc, marker->yc,
-    marker->xc, marker->yc);
-
-    if (marker->freeform || marker->nnames > 1)
-    {
-        fprintf(outFile, ";stt('%d_%d');",
-            marker->xc, marker->yc);
-    }
-
-    fprintf(outFile, "\" "
-        "onmouseout=\"qn('%d_%d');\">",
+        "<a class=\"loc\" id=\"listloc%d_%d\" href=\"?%d_%d\" "
+        "onmouseover=\"%s('%d_%d');\" onmouseout=\"qn();\">",
+        marker->xc, marker->yc,
+        marker->xc, marker->yc,
+        (marker->freeform || marker->nnames > 1) ? "sttq" : "qh",
         marker->xc, marker->yc);
 
     if (marker->names[nname].name != NULL)
@@ -381,8 +373,8 @@
                 {
                     fprintf(outFile,
                     "<span class=\"%c\">"
-                    "<a name=\"locpt\" onmouseover=\"stt('%d_%d');\" "
-                    "onmouseout=\"htt();\" "
+                    "<a name=\"locpt\" onmouseover=\"sttq('%d_%d');\" "
+                    "onmouseout=\"qn();\" "
                     "class=\"loc\" id=\"maploc%d_%d\" "
                     "href=\"?%d_%d\">%c</span></a></span>",
                     'a' + col_light_red,
--- a/tooltip.js	Fri Oct 11 07:42:15 2019 +0300
+++ b/tooltip.js	Fri Oct 11 08:06:39 2019 +0300
@@ -3,41 +3,56 @@
 // Programmed by Matti 'ccr' Hamalainen <ccr@tnsp.org>
 // (C) Copyright 2006-2017 Tecnic Software productions (TNSP)
 //
-var myhl = -1;
+var myhl = null;
 var mytt = null;
 var myx = 0;
 var myy = 0;
-document.onmousemove = utt;
+document.onmousemove = mapUpdateTooltip;
 
 
 // Change background style of given element
 function shc(uid, ucolor)
 {
-  document.getElementById(uid).style['background'] = ucolor;
+  var uelem = document.getElementById(uid);
+  if (uelem)
+    uelem.style.background = ucolor;
 }
 
 
 // Hilite map and list elements of given number
 function qh(marker)
 {
-  if (myhl >= 0) qn(myhl);
+  if (myhl != null) qu(myhl);
   shc('maploc'+marker, 'white');
   shc('listloc'+marker, 'white');
   myhl = marker;
 }
 
 // Unlite
-function qn(marker)
+function qu(marker)
 {
   shc('maploc'+ marker, 'black');
   shc('listloc'+ marker, 'black');
-  myhl = -1;
+}
+
+
+function qn()
+{
+  if (myhl != null) qu(myhl);
+  myhl = null;
   htt();
 }
 
 
+function sttq(id)
+{
+  qh(id);
+  stt(id);
+}
+
+
 // Update the tooltip box
-function utt(e)
+function mapUpdateTooltip(e)
 {
   var x = document.all ? (window.event.x + document.body.scrollLeft) : e.pageX;
   var y = document.all ? (window.event.y + document.body.scrollTop)  : e.pageY;
@@ -83,6 +98,7 @@
   }
 }
 
+
 // Show tooltip
 function stt(id)
 {