X-Git-Url: https://git-public.kairo.at/?p=tricorder.git;a=blobdiff_plain;f=js%2Ftricorder.js;h=4d5e69bb66cda667f6429ff11d192adb065915a6;hp=89c6094e3f5dbe9779c3da3cb4e19c5bc67ea209;hb=6632e08ce5328bd77d12839c85eec0c685ed88cf;hpb=b5c483f2e99354c8da9770cd763f0e752bc46614 diff --git a/js/tricorder.js b/js/tricorder.js index 89c6094..4d5e69b 100644 --- a/js/tricorder.js +++ b/js/tricorder.js @@ -3,9 +3,21 @@ * You can obtain one at http://mozilla.org/MPL/2.0/. */ var gStardate, gSDBase; +var gSounds = {}; window.onload = function() { setTimeout(updateStardate, 0); + gSounds.scan = new Audio("sound/scan.opus"); + gSounds.scan.loop = true; + gSounds.launch = new Audio("sound/launch.opus"); + gSounds.shutdown = new Audio("sound/shutdown.opus"); + gSounds.keyaction = new Audio("sound/key-action.opus"); + gSounds.keypress = new Audio("sound/key-press.opus"); + + gSounds.launch.play(); + window.addEventListener("beforeunload", function( event ) { + gSounds.shutdown.play(); + }, false); } function updateStardate() { @@ -23,7 +35,33 @@ function updateStardate() { setTimeout(updateStardate, 5*60*1000); } +function toggleFullscreen() { + gSounds.keyaction.play(); + if ((document.fullScreenElement && document.fullScreenElement !== null) || + (document.mozFullScreenElement && document.mozFullScreenElement !== null) || + (document.webkitFullScreenElement && document.webkitFullScreenElement !== null)) { + if (document.cancelFullScreen) { + document.cancelFullScreen(); + } else if (document.mozCancelFullScreen) { + document.mozCancelFullScreen(); + } else if (document.webkitCancelFullScreen) { + document.webkitCancelFullScreen(); + } + } + else { + var elem = document.getElementById("body"); + if (elem.requestFullScreen) { + elem.requestFullScreen(); + } else if (elem.mozRequestFullScreen) { + elem.mozRequestFullScreen(); + } else if (elem.webkitRequestFullScreen) { + elem.webkitRequestFullScreen(); + } + } +} + function switchModule(modname) { + gSounds.keyaction.play(); var sections = document.getElementsByTagName('section'); for (var i = 0; i <= sections.length - 1; i++) { if (sections[i].classList.contains("active")) { @@ -45,6 +83,7 @@ function switchModule(modname) { var gModPos = { activate: function() { if (navigator.geolocation) { + gSounds.scan.play(); document.getElementById("posunavail").style.display = "none"; document.getElementById("posavail").style.display = "block"; this.watchID = navigator.geolocation.watchPosition( @@ -61,14 +100,20 @@ var gModPos = { }, function(error) { // See https://developer.mozilla.org/en/Using_geolocation#Handling_errors - document.getElementById("posLat").textContent = error.message; - document.getElementById("posLong").textContent = "..."; - document.getElementById("posAlt").textContent = "..."; - document.getElementById("posAcc").textContent = "..."; - document.getElementById("posAltAcc").textContent = "..."; - document.getElementById("posHead").textContent = "..."; - document.getElementById("posSpd").textContent = "..."; - document.getElementById("posTime").textContent = "..."; + if (error.message) { + document.getElementById("posLat").textContent = error.message; + document.getElementById("posLong").textContent = "..."; + document.getElementById("posAlt").textContent = "..."; + document.getElementById("posAcc").textContent = "..."; + document.getElementById("posAltAcc").textContent = "..."; + document.getElementById("posHead").textContent = "..."; + document.getElementById("posSpd").textContent = "..."; + document.getElementById("posTime").textContent = "..."; + } + else { + document.getElementById("posunavail").style.display = "block"; + document.getElementById("posavail").style.display = "none"; + } }, {enableHighAccuracy: true} ); @@ -79,6 +124,7 @@ var gModPos = { } }, deactivate: function() { + gSounds.scan.pause(); if (this.watchID) { navigator.geolocation.clearWatch(this.watchID); } @@ -98,16 +144,32 @@ var gModPos = { var gModGrav = { activate: function() { + gSounds.scan.play(); document.getElementById("gravunavail").style.display = "none"; document.getElementById("gravavail").style.display = "block"; window.addEventListener("deviceorientation", this.orientEvent, true); window.addEventListener("devicemotion", this.motionEvent, true); + setTimeout(function() { + if ((document.getElementById("gravAlpha").textContent == "...") && + (document.getElementById("gravX").textContent == "...")) { + gModGrav.deactivate(); + } + }, 3000); }, deactivate: function() { + gSounds.scan.pause(); window.removeEventListener("deviceorientation", this.orientEvent, true); window.removeEventListener("devicemotion", this.motionEvent, true); document.getElementById("gravunavail").style.display = "block"; document.getElementById("gravavail").style.display = "none"; + //document.getElementById("gravAbs").textContent = "..."; + document.getElementById("gravAlpha").textContent = "..."; + document.getElementById("gravBeta").textContent = "..."; + document.getElementById("gravGamma").textContent = "..."; + document.getElementById("gravX").textContent = "..."; + document.getElementById("gravY").textContent = "..."; + document.getElementById("gravZ").textContent = "..."; + //document.getElementById("gravRot").textContent = "..."; }, orientEvent: function(orientData) { //document.getElementById("gravAbs").textContent = orientData.absolute; @@ -124,11 +186,19 @@ var gModGrav = { } var gModAcou = { - activate: function() {}, - deactivate: function() {}, + activate: function() { + //gSounds.scan.play(); + }, + deactivate: function() { + gSounds.scan.pause(); + }, } var gModNull = { - activate: function() {}, - deactivate: function() {}, + activate: function() { + //gSounds.scan.play(); + }, + deactivate: function() { + gSounds.scan.pause(); + }, }