Merge branch 'master' of linz:/srv/git/tricorder
authorRobert Kaiser <kairo@kairo.at>
Thu, 13 Nov 2014 03:18:16 +0000 (04:18 +0100)
committerRobert Kaiser <kairo@kairo.at>
Thu, 13 Nov 2014 03:18:16 +0000 (04:18 +0100)
1  2 
js/tricorder.js

diff --combined js/tricorder.js
index 3ab7ee948fe0f41b15b6723efffcf05cff3403f8,dbd188d93bb5ae05ff326113bb7ab5e70f4a9c3d..3887a533936ad8b028c5d329f47490dd5b4fb66c
@@@ -40,6 -40,10 +40,10 @@@ window.onresize = 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");
  
@@@ -305,72 -309,6 +309,72 @@@ var gModSound = 
    },
  }
  
 +var gModEnv = {
 +  activate: function() {
 +    gSounds.scan.play();
 +    document.getElementById("envunavail").style.display = "none";
 +    document.getElementById("envavail").style.display = "block";
 +    window.addEventListener("devicelight", this.lightEvent, true);
 +    window.addEventListener("deviceproximity", this.proxEvent, true);
 +    setTimeout(function() {
 +      if ((document.getElementById("envLight").textContent == "...") &&
 +          (document.getElementById("envDistance").textContent == "...")) {
 +        gModEnv.deactivate();
 +      }
 +    }, 5000);
 +    try {
 +      for (var cameraId of window.navigator.mozCameras.getListOfCameras()) {
 +        window.navigator.mozCameras.getCamera({camera: cameraId}, function(aCamera) {
 +            if (aCamera.capabilities.flashModes.indexOf('torch') !== -1) {
 +              this.flashCamera = aCamera;
 +            }
 +        });
 +      }
 +      if (this.flashCamera) {
 +        document.getElementById("envFlashOn").onclick = gModEnv.switchFlashlight(true);
 +        document.getElementById("envFlashOff").onclick = gModEnv.switchFlashlight(false);
 +        document.getElementById("envFlashUnavail").style.display = "none";
 +        document.getElementById("envFlashAvail").style.display = "block";
 +      }
 +    } catch (e) {
 +      // camera api not supported
 +      document.getElementById("envFlashUnavail").style.display = "block";
 +      document.getElementById("envFlashAvail").style.display = "none";
 +    }
 +  },
 +  deactivate: function() {
 +    gSounds.scan.pause();
 +    window.removeEventListener("devicelight", this.lightEvent, true);
 +    window.removeEventListener("deviceproximity", this.proxEvent, true);
 +    document.getElementById("envunavail").style.display = "block";
 +    document.getElementById("envavail").style.display = "none";
 +    document.getElementById("envLight").textContent = "...";
 +    document.getElementById("envDistance").textContent = "...";
 +  },
 +  lightEvent: function(lightData) {
 +    // See http://www.w3.org/TR/ambient-light/
 +    document.getElementById("envLight").textContent = lightData.value + " lux";
 +  },
 +  proxEvent: function(proxData) {
 +    // See http://www.w3.org/TR/2012/WD-proximity-20120712/
 +    if (proxData.value >= proxData.max) {
 +      document.getElementById("envDistance").textContent = "(maximum, >= " + proxData.value + " cm)";
 +    }
 +    else if (proxData.value <= proxData.min) {
 +      document.getElementById("envDistance").textContent = "(minimum, <= " + proxData.value + " cm)";
 +    }
 +    else {
 +      document.getElementById("envDistance").textContent = proxData.value + " cm";
 +    }
 +  },
 +  flashCamera: null,
 +  switchFlashlight: function(aEnabled) {
 +    if (this.flashCamera) {
 +      this.flashCamera.flashMode = aEnabled ? 'torch' : 'off';
 +    }
 +  }
 +}
 +
  var gModDev = {
    activate: function() {
      gSounds.scan.play();