From 937918f280e71f09c0f8ef1d1478482e307be052 Mon Sep 17 00:00:00 2001 From: Robert Kaiser Date: Fri, 14 Nov 2014 02:44:56 +0100 Subject: [PATCH] actually make flashlight work and make switch look decent --- index.html | 4 ++-- js/tricorder.js | 27 +++++++++++++++++---------- style/tricorder.css | 29 +++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 12 deletions(-) diff --git a/index.html b/index.html index 16ee42c..f8cb293 100644 --- a/index.html +++ b/index.html @@ -125,8 +125,8 @@ a better device.
diff --git a/js/tricorder.js b/js/tricorder.js index 3887a53..f8bc28f 100644 --- a/js/tricorder.js +++ b/js/tricorder.js @@ -323,18 +323,16 @@ var gModEnv = { } }, 5000); try { - for (var cameraId of window.navigator.mozCameras.getListOfCameras()) { - window.navigator.mozCameras.getCamera({camera: cameraId}, function(aCamera) { + var cameras = navigator.mozCameras.getListOfCameras(); + for (i = 0; i < cameras.length; i++) { + var promise = navigator.mozCameras.getCamera(cameras[i], {}, + function(aCamera) { if (aCamera.capabilities.flashModes.indexOf('torch') !== -1) { - this.flashCamera = aCamera; + gModEnv.foundFlashCamera(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"; + }, + function(aError) { console.log("camera error: " + aError); } + ); } } catch (e) { // camera api not supported @@ -342,6 +340,13 @@ var gModEnv = { document.getElementById("envFlashAvail").style.display = "none"; } }, + foundFlashCamera(aCamera) { + this.flashCamera = aCamera; + document.getElementById("envFlashOn").onclick = function() { console.log("on"); gModEnv.switchFlashlight(true); }; + document.getElementById("envFlashOff").onclick = function() { console.log("off"); gModEnv.switchFlashlight(false); }; + document.getElementById("envFlashUnavail").style.display = "none"; + document.getElementById("envFlashAvail").style.display = "block"; + }, deactivate: function() { gSounds.scan.pause(); window.removeEventListener("devicelight", this.lightEvent, true); @@ -371,6 +376,8 @@ var gModEnv = { switchFlashlight: function(aEnabled) { if (this.flashCamera) { this.flashCamera.flashMode = aEnabled ? 'torch' : 'off'; + document.getElementById("envFlashOn").disabled == aEnabled; + document.getElementById("envFlashOff").disabled == !aEnabled; } } } diff --git a/style/tricorder.css b/style/tricorder.css index 99696f6..cc79ade 100644 --- a/style/tricorder.css +++ b/style/tricorder.css @@ -242,6 +242,19 @@ section > p:first-child { padding-top: 1em; } +button { + font: inherit; + border: none; + color: #000000; + background-color: #C09070; + border-radius: 3000px; + margin: 0 .25em; +} + +button.disabled { + background-color: #402858; +} + .posVal, .gravVal { text-align: right; } @@ -262,6 +275,22 @@ section > p:first-child { height: 100%; } +#envFlashAvail { + padding: 1em 3px 0; +} + +#envFlashOn { + margin-right: 0; + border-top-right-radius: 0; + border-bottom-right-radius: 0; +} + +#envFlashOff { + margin-left: 0; + border-top-left-radius: 0; + border-bottom-left-radius: 0; +} + @media screen and (min-width: 500px) { body { font-size: 24px; -- 2.43.0