X-Git-Url: https://git-public.kairo.at/?p=tricorder.git;a=blobdiff_plain;f=js%2Ftricorder.js;h=2574b01f6fb7e334618e130079fa19b991ddb7bc;hp=2debeec9964f1d1d2c0acd9cab1a0f9895f8b33b;hb=a4a791a5b5715d83bcca9c3e757cc7c4e20d227e;hpb=33a80b5e4b34ab6ab27677a1841014321dd076da diff --git a/js/tricorder.js b/js/tricorder.js index 2debeec..2574b01 100644 --- a/js/tricorder.js +++ b/js/tricorder.js @@ -14,6 +14,17 @@ window.onload = function() { gSounds.keyaction = new Audio("sound/key-action.opus"); gSounds.keypress = new Audio("sound/key-press.opus"); + document.getElementById("fullScreenButton").addEventListener("click", + function(aEvent) { toggleFullscreen(); }, false); + + var navItems = document.getElementById("navlist").children; + for (var i = 0; i <= navItems.length - 1; i++) { + navItems[i].addEventListener("click", + function(aEvent) { + switchModule(aEvent.target.id.replace("nav", "")); + }, false); + } + gSounds.launch.play(); window.addEventListener("beforeunload", function( event ) { gSounds.shutdown.play(); @@ -21,13 +32,20 @@ window.onload = function() { } function updateStardate() { + // Stardate rules foggy at best. See http://en.wikipedia.org/wiki/Stardate + // and the Memory Alpha article linked there for more details. + // We roughly lean on TNG scale by splitting an Earth year into exactly 1000 + // units, but we put the 0 point at the TV premiere of The Original Series. if (!gStardate) gStardate = document.getElementById("stardate"); var curDate = new Date(); if (!gSDBase) - gSDBase = new Date("September 8, 1966 20:00:00 EST"); + // Star Trek premiered on Thursday, September 8, 1966, at 7:30PM or 8:30PM + // depending on time zone in the United States. + // See http://www.startrek.com/article/star-trek-and-newspapers-part-2 + gSDBase = new Date("September 8, 1966 19:30:00 EST"); var sdateval = (curDate - gSDBase) / (86400 * 365.2425); gStardate.textContent = sdateval.toFixed(1); @@ -60,7 +78,7 @@ function toggleFullscreen() { } } -function switchModule(modname) { +function switchModule(aModname) { gSounds.keyaction.play(); var sections = document.getElementsByTagName('section'); for (var i = 0; i <= sections.length - 1; i++) { @@ -74,10 +92,13 @@ function switchModule(modname) { navs[i].classList.remove("active"); } - document.getElementById("nav" + modname).classList.add("active"); - document.getElementById("sect" + modname).classList.add("active"); + var navItem = document.getElementById("nav" + aModname); + navItem.classList.add("active"); + document.getElementById("sect" + aModname).classList.add("active"); + document.getElementById("mainHeader").textContent = + (aModname == "Other") ? "Web Tricorder" : navItem.textContent; - window["gMod" + modname].activate(); + window["gMod" + aModname].activate(); } var gModPos = { @@ -116,13 +137,15 @@ var gModPos = { document.getElementById("posHead").textContent = "..."; document.getElementById("posSpd").textContent = "..."; document.getElementById("posTime").textContent = "..."; + setTimeout(function() { gModPos.deactivate(); }, 5000); } else { document.getElementById("posunavail").style.display = "block"; document.getElementById("posavail").style.display = "none"; } + gSounds.scan.pause(); }, - {enableHighAccuracy: true} + {enableHighAccuracy: true, maximumAge: 10000, timeout: 60000} ); } else { @@ -198,6 +221,53 @@ var gModGrav = { }, } + +var gModDev = { + activate: function() { + gSounds.scan.play(); + this.batteryTimer = + setInterval(function () { gModDev.updateBattery(); }, 100); + }, + deactivate: function() { + clearTimeout(this.batteryTimer); + gSounds.scan.pause(); + }, + updateBattery: function() { + document.getElementById("devBattLevel").textContent = + (navigator.battery.level * 100).toFixed(1) + "%"; + if (navigator.battery.charging) { + if (navigator.battery.chargingTime == 0 || + navigator.battery.chargingTime == Infinity) { + document.getElementById("devBattStatus").textContent = "charging"; + } + else { + document.getElementById("devBattStatus").textContent = + "charging, " + navigator.battery.chargingTime + "s remaining"; + } + } + else { + if (navigator.battery.dischargingTime == 0 || + navigator.battery.dischargingTime == Infinity) { + document.getElementById("devBattStatus").textContent = "discharging"; + } + else { + document.getElementById("devBattStatus").textContent = + navigator.battery.dischargingTime + "s usage remaining"; + } + } + }, + batteryTimer: null, +} + +var gModNull = { + activate: function() { + //gSounds.scan.play(); + }, + deactivate: function() { + gSounds.scan.pause(); + }, +} + var gModOther = { activate: function() { //gSounds.scan.play();