X-Git-Url: https://git-public.kairo.at/?p=tricorder.git;a=blobdiff_plain;f=js%2Ftricorder.js;h=2dc920767f39b9bb17974ff22fb99ed40ad6a91a;hp=f82d9921d8a6559bd2622fe20ae0f0aa2b286167;hb=b6339904b13e7680010ea14b081bd60c06ab9336;hpb=1753d94ae19a06d64123c99d7d5c3184db00e155 diff --git a/js/tricorder.js b/js/tricorder.js index f82d992..2dc9207 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( @@ -79,6 +118,7 @@ var gModPos = { } }, deactivate: function() { + gSounds.scan.pause(); if (this.watchID) { navigator.geolocation.clearWatch(this.watchID); } @@ -98,37 +138,47 @@ 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); }, 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"; }, orientEvent: function(orientData) { - document.getElementById("gravAbs").textContent = orientData.absolute; - document.getElementById("gravAlpha").textContent = orientData.alpha; - document.getElementById("gravBeta").textContent = orientData.beta; - document.getElementById("gravGamma").textContent = orientData.gamma; + //document.getElementById("gravAbs").textContent = orientData.absolute; + document.getElementById("gravAlpha").textContent = orientData.alpha.toFixed(1) + "°"; + document.getElementById("gravBeta").textContent = orientData.beta.toFixed(1) + "°"; + document.getElementById("gravGamma").textContent = orientData.gamma.toFixed(1) + "°"; }, motionEvent: function(event) { - document.getElementById("gravX").textContent = event.accelerationIncludingGravity.x; - document.getElementById("gravY").textContent = event.accelerationIncludingGravity.y; - document.getElementById("gravZ").textContent = event.accelerationIncludingGravity.z; - document.getElementById("gravRot").textContent = event.rotationRate; + document.getElementById("gravX").textContent = event.accelerationIncludingGravity.x.toFixed(2) + " m/s²"; + document.getElementById("gravY").textContent = event.accelerationIncludingGravity.y.toFixed(2) + " m/s²"; + document.getElementById("gravZ").textContent = event.accelerationIncludingGravity.z.toFixed(2) + " m/s²"; + //document.getElementById("gravRot").textContent = event.rotationRate; }, } 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(); + }, }