changeset 1756:da35721afdad

Various cleanups to the utility Javascript code.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 19 Oct 2017 19:17:58 +0300
parents c97f28d7c4eb
children 7f0b0e5dc420
files util.js
diffstat 1 files changed, 17 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/util.js	Thu Oct 19 18:48:39 2017 +0300
+++ b/util.js	Thu Oct 19 19:17:58 2017 +0300
@@ -107,20 +107,23 @@
   nmelem.className += " nactive";
 
   // Set the active item in the location dropdown
-  var opts = document.forms[0].slocation.options;
-  var found = false;
-  for (var opt, i = 0; opt = opts[i]; i++)
+  var ssel = document.getElementById("slocation");
+  if (ssel)
   {
-    if (opt.value == newLoc)
+    var found = false;
+    for (var opt, i = 0; opt = ssel.options[i]; i++)
     {
-      document.forms[0].slocation.selectedIndex = i;
-      found = true;
-      break;
+      if (opt.value == newLoc)
+      {
+        ssel.selectedIndex = i;
+        found = true;
+        break;
+      }
     }
+
+    if (!found)
+      ssel.selectedIndex = 0;
   }
-
-  if (!found)
-    document.forms[0].slocation.selectedIndex = 0;
 }
 
 
@@ -140,8 +143,8 @@
     var nelem = document.getElementById(newLoc);
     if (nelem)
     {
-      var sscroll = document.forms[0].sscroll.checked;
-      var celem = document.getElementById(currLoc);
+      var sscroll = document.getElementById("sscroll").checked;
+      var celem = currLoc != "" ? document.getElementById(currLoc) : 0;
       if (sscroll && celem)
       {
         if (scrollTimerID != -1)
@@ -183,6 +186,6 @@
 
 function jsToggleLabels()
 {
-  var cl = document.all ? document.styleSheets[0].rules[0] : document.styleSheets[0].cssRules[0];
-  cl.style.visibility = document.forms[0].shide.checked ? "visible" : "hidden";
+  var vcl = document.all ? document.styleSheets[0].rules[0] : document.styleSheets[0].cssRules[0];
+  vcl.style.visibility = document.getElementById("shide").checked ? "visible" : "hidden";
 }