make module switching work
[tricorder.git] / js / tricorder.js
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3  * You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 var gStardate, gSDBase;
6
7 window.onload = function() {
8   setTimeout(updateStardate, 0);
9 }
10
11 function updateStardate() {
12   if (!gStardate)
13     gStardate = document.getElementById("stardate");
14
15   var curDate = new Date();
16
17   if (!gSDBase)
18     gSDBase = new Date("September 8, 1966 20:00:00 EST");
19
20   var sdateval = (curDate - gSDBase) / (86400 * 365.2425);
21   gStardate.textContent = sdateval.toFixed(1);
22
23   setTimeout(updateStardate, 5*60*1000);
24 }
25
26 function switchModule(modname) {
27   var sections = document.getElementsByTagName('section');
28   for (var i = 0; i <= sections.length - 1; i++) {
29     sections[i].classList.remove("active");
30   }
31   var navs = document.getElementById('navlist').children;
32   for (var i = 0; i <= navs.length - 1; i++) {
33     navs[i].classList.remove("active");
34   }
35
36   document.getElementById("nav" + modname).classList.add("active");
37   document.getElementById("sect" + modname).classList.add("active");
38 }