reduce behavior not compliant with the CSP for privileged apps; start implementing...
authorRobert Kaiser <robert@widebook.box.kairo.at>
Sun, 28 Jul 2013 19:13:41 +0000 (21:13 +0200)
committerRobert Kaiser <robert@widebook.box.kairo.at>
Sun, 28 Jul 2013 19:13:41 +0000 (21:13 +0200)
index.html
js/tricorder.js

index e2bd3f1..b426b25 100644 (file)
 
 <div id="sideBottom">
 <ul id="navlist">
-<li id="navPos" onclick="switchModule('Pos');">Position</li>
-<li id="navGrav" onclick="switchModule('Grav');">Gravity</li>
-<li id="navOther" onclick="switchModule('Other');">Other</li>
+<li id="navPos">Position</li>
+<li id="navGrav">Gravity</li>
+<li id="navDev">Device</li>
+<li id="navOther">Other</li>
 </ul>
 </div>
 
 <ul id="sideRemark">
-<li onclick="toggleFullscreen();">Full Screen</li>
+<li id="fullScreenButton">Full Screen</li>
 </ul>
 </div>
 
@@ -98,6 +99,14 @@ a better device.
 </div>
 </section>
 
+<section id="sectDev">
+<table>
+<tr><td>Battery Level:</td><td id="devBattLevel" class="deviceVal">...</td></tr>
+<tr><td>Battery Status:</td><td id="devBattStatus" class="deviceVal">...</td></tr>
+<!-- to come : storage data -->
+</table>
+</section>
+
 <section id="sectOther">
 <p>This tricorder model doesn't have other sensors yet, please contact
 the <a href="http://www.kairo.at/apps" target="_blank">Starfleet science
index 3bf19c6..f88ebb1 100644 (file)
@@ -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();