changeset 2374:51ccd3d037bd

Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 04 Nov 2021 03:17:26 +0200
parents 710debf83f53
children 2193e1474d38
files src/colormap.c src/util.js
diffstat 2 files changed, 35 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/colormap.c	Thu Nov 04 02:55:50 2021 +0200
+++ b/src/colormap.c	Thu Nov 04 03:17:26 2021 +0200
@@ -294,7 +294,7 @@
 
     fprintf(outFile,
     "</head>\n"
-    "<body onLoad=\"mapOnLoad();\">\n");
+    "<body onload=\"mapOnLoad();\">\n");
 
     if (!optPosGlue)
     {
@@ -314,11 +314,11 @@
         fprintf(outFile,
         "</div>\n"
         " <form>\n"
-        "  <select id=\"slocation\" onChange=\"mapGotoPos();\" autofocus=\"autofocus\">\n"
+        "  <select id=\"slocation\" autofocus=\"autofocus\">\n"
         "@LOCATIONS@\n"
         "  </select>\n"
         "  <br />\n"
-        "  <input id=\"shide\" onClick=\"mapToggleLabels();\" type=\"checkbox\"%s><label for=\"shide\">Labels</label>\n"
+        "  <input id=\"slabels\" type=\"checkbox\"%s><label for=\"slabels\">Labels</label>\n"
         "  <input id=\"sscroll\" type=\"checkbox\"%s><label for=\"sscroll\">Smooth scroll</label>\n"
         " </form>\n"
         "</div>\n",
--- a/src/util.js	Thu Nov 04 02:55:50 2021 +0200
+++ b/src/util.js	Thu Nov 04 03:17:26 2021 +0200
@@ -10,6 +10,30 @@
 var scrollIndex = 0.0;
 
 
+function mapAddEventOb(obname, evobj, evtype, evcallback)
+{
+  if (evobj == null || typeof(evobj) == 'undefined')
+  {
+    console.log("Event object '"+ obname +"' == null.");
+    return;
+  }
+
+  if (evobj.addEventListener)
+    evobj.addEventListener(evtype, evcallback, false);
+  else
+  if (evobj.attachEvent)
+    evobj.attachEvent("on"+evtype, evcallback);
+  else
+    evobj["on"+evtype] = evcallback;
+}
+
+
+function mapAddEvent(obname, evtype, evcallback)
+{
+  mapAddEventOb(obname, document.getElementById(obname), evtype, evcallback);
+}
+
+
 function mapFindElemCoords(elem)
 {
   var xc = yc = 0;
@@ -142,7 +166,7 @@
 }
 
 
-function mapGotoPos()
+function mapGotoLocation()
 {
   var newLoc = document.getElementById("slocation").value;
   if (currLoc != newLoc)
@@ -173,10 +197,10 @@
 }
 
 
-function mapToggleLabels()
+function mapUpdateLabelVisibility()
 {
   var vcl = document.all ? document.styleSheets[0].rules[0] : document.styleSheets[0].cssRules[0];
-  vcl.style.visibility = document.getElementById("shide").checked ? "visible" : "hidden";
+  vcl.style.visibility = document.getElementById("slabels").checked ? "visible" : "hidden";
 }
 
 
@@ -195,4 +219,9 @@
       currLoc = eid;
     }
   }
+
+  mapAddEvent("slabels", "change", mapUpdateLabelVisibility);
+  mapUpdateLabelVisibility();
+
+  mapAddEvent("slocation", "change", mapGotoLocation);
 }