X-Git-Url: https://git-public.kairo.at/?p=tricorder.git;a=blobdiff_plain;f=js%2Ftricorder.js;h=ff53ccb176bc28d9f5f58a907ee5a7edd360cb55;hp=2debeec9964f1d1d2c0acd9cab1a0f9895f8b33b;hb=06b2173885cf29366194dde4848ed9cf1377ff1d;hpb=33a80b5e4b34ab6ab27677a1841014321dd076da diff --git a/js/tricorder.js b/js/tricorder.js index 2debeec..ff53ccb 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(); @@ -60,7 +71,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 +85,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 +130,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 +214,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();