From 84436ccb5cf636e01658943c44b6af5d063750c4 Mon Sep 17 00:00:00 2001 From: Robert Kaiser Date: Sun, 28 Jul 2013 21:13:41 +0200 Subject: [PATCH] reduce behavior not compliant with the CSP for privileged apps; start implementing a device module (battery, storage) --- index.html | 17 +++++++++++++---- js/tricorder.js | 50 ++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 58 insertions(+), 9 deletions(-) diff --git a/index.html b/index.html index e2bd3f1..b426b25 100644 --- a/index.html +++ b/index.html @@ -32,14 +32,15 @@
@@ -98,6 +99,14 @@ a better device. +
+ + + + +
Battery Level:...
Battery Status:...
+
+

This tricorder model doesn't have other sensors yet, please contact the Starfleet science diff --git a/js/tricorder.js b/js/tricorder.js index 3bf19c6..f88ebb1 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,13 +85,13 @@ function switchModule(modname) { navs[i].classList.remove("active"); } - var navItem = document.getElementById("nav" + modname); + var navItem = document.getElementById("nav" + aModname); navItem.classList.add("active"); - document.getElementById("sect" + modname).classList.add("active"); + document.getElementById("sect" + aModname).classList.add("active"); document.getElementById("mainHeader").textContent = - (modname == "Other") ? "Web Tricorder" : navItem.textContent; + (aModname == "Other") ? "Web Tricorder" : navItem.textContent; - window["gMod" + modname].activate(); + window["gMod" + aModname].activate(); } var gModPos = { @@ -203,6 +214,35 @@ 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) + "%"; + document.getElementById("devBattStatus").textContent = + navigator.battery.charging ? "charging, " + navigator.battery.chargingTime + "s remaining" + : 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(); -- 2.43.0