Commit | Line | Data |
---|---|---|
feec2d1c RK |
1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
2 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, | |
3 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ | |
4 | ||
5 | var gStardate, gSDBase; | |
14a57547 | 6 | var gSounds = {}; |
feec2d1c RK |
7 | |
8 | window.onload = function() { | |
9 | setTimeout(updateStardate, 0); | |
14a57547 RK |
10 | gSounds.scan = new Audio("sound/scan.opus"); |
11 | gSounds.scan.loop = true; | |
12 | gSounds.launch = new Audio("sound/launch.opus"); | |
13 | gSounds.shutdown = new Audio("sound/shutdown.opus"); | |
14 | gSounds.keyaction = new Audio("sound/key-action.opus"); | |
15 | gSounds.keypress = new Audio("sound/key-press.opus"); | |
16 | ||
17 | gSounds.launch.play(); | |
18 | window.addEventListener("beforeunload", function( event ) { | |
19 | gSounds.shutdown.play(); | |
20 | }, false); | |
feec2d1c RK |
21 | } |
22 | ||
23 | function updateStardate() { | |
24 | if (!gStardate) | |
25 | gStardate = document.getElementById("stardate"); | |
26 | ||
27 | var curDate = new Date(); | |
28 | ||
29 | if (!gSDBase) | |
30 | gSDBase = new Date("September 8, 1966 20:00:00 EST"); | |
31 | ||
32 | var sdateval = (curDate - gSDBase) / (86400 * 365.2425); | |
33 | gStardate.textContent = sdateval.toFixed(1); | |
34 | ||
35 | setTimeout(updateStardate, 5*60*1000); | |
eabed1a4 RK |
36 | } |
37 | ||
14a57547 RK |
38 | function toggleFullscreen() { |
39 | gSounds.keyaction.play(); | |
40 | if ((document.fullScreenElement && document.fullScreenElement !== null) || | |
41 | (document.mozFullScreenElement && document.mozFullScreenElement !== null) || | |
42 | (document.webkitFullScreenElement && document.webkitFullScreenElement !== null)) { | |
43 | if (document.cancelFullScreen) { | |
44 | document.cancelFullScreen(); | |
45 | } else if (document.mozCancelFullScreen) { | |
46 | document.mozCancelFullScreen(); | |
47 | } else if (document.webkitCancelFullScreen) { | |
48 | document.webkitCancelFullScreen(); | |
49 | } | |
50 | } | |
51 | else { | |
52 | var elem = document.getElementById("body"); | |
53 | if (elem.requestFullScreen) { | |
54 | elem.requestFullScreen(); | |
55 | } else if (elem.mozRequestFullScreen) { | |
56 | elem.mozRequestFullScreen(); | |
57 | } else if (elem.webkitRequestFullScreen) { | |
58 | elem.webkitRequestFullScreen(); | |
59 | } | |
60 | } | |
61 | } | |
62 | ||
eabed1a4 | 63 | function switchModule(modname) { |
14a57547 | 64 | gSounds.keyaction.play(); |
eabed1a4 RK |
65 | var sections = document.getElementsByTagName('section'); |
66 | for (var i = 0; i <= sections.length - 1; i++) { | |
1753d94a RK |
67 | if (sections[i].classList.contains("active")) { |
68 | window["gMod" + sections[i].id.replace("sect", "")].deactivate(); | |
69 | sections[i].classList.remove("active"); | |
70 | } | |
eabed1a4 RK |
71 | } |
72 | var navs = document.getElementById('navlist').children; | |
73 | for (var i = 0; i <= navs.length - 1; i++) { | |
74 | navs[i].classList.remove("active"); | |
75 | } | |
76 | ||
77 | document.getElementById("nav" + modname).classList.add("active"); | |
78 | document.getElementById("sect" + modname).classList.add("active"); | |
1753d94a RK |
79 | |
80 | window["gMod" + modname].activate(); | |
81 | } | |
82 | ||
83 | var gModPos = { | |
84 | activate: function() { | |
85 | if (navigator.geolocation) { | |
14a57547 | 86 | gSounds.scan.play(); |
1753d94a RK |
87 | document.getElementById("posunavail").style.display = "none"; |
88 | document.getElementById("posavail").style.display = "block"; | |
89 | this.watchID = navigator.geolocation.watchPosition( | |
90 | function(position) { | |
91 | document.getElementById("posLat").textContent = position.coords.latitude; | |
92 | document.getElementById("posLong").textContent = position.coords.longitude; | |
93 | document.getElementById("posAlt").textContent = position.coords.altitude; | |
94 | document.getElementById("posAcc").textContent = position.coords.accuracy; | |
95 | document.getElementById("posAltAcc").textContent = position.coords.altitudeAccuracy; | |
96 | document.getElementById("posHead").textContent = position.coords.heading || "---"; | |
97 | document.getElementById("posSpd").textContent = position.coords.speed || "---"; | |
98 | var locTime = new Date(position.timestamp); | |
99 | document.getElementById("posTime").textContent = locTime.toISOString(); | |
100 | }, | |
101 | function(error) { | |
102 | // See https://developer.mozilla.org/en/Using_geolocation#Handling_errors | |
103 | document.getElementById("posLat").textContent = error.message; | |
104 | document.getElementById("posLong").textContent = "..."; | |
105 | document.getElementById("posAlt").textContent = "..."; | |
106 | document.getElementById("posAcc").textContent = "..."; | |
107 | document.getElementById("posAltAcc").textContent = "..."; | |
108 | document.getElementById("posHead").textContent = "..."; | |
109 | document.getElementById("posSpd").textContent = "..."; | |
110 | document.getElementById("posTime").textContent = "..."; | |
111 | }, | |
112 | {enableHighAccuracy: true} | |
113 | ); | |
114 | } | |
115 | else { | |
116 | document.getElementById("posunavail").style.display = "block"; | |
117 | document.getElementById("posavail").style.display = "none"; | |
118 | } | |
119 | }, | |
120 | deactivate: function() { | |
14a57547 | 121 | gSounds.scan.pause(); |
1753d94a RK |
122 | if (this.watchID) { |
123 | navigator.geolocation.clearWatch(this.watchID); | |
124 | } | |
125 | document.getElementById("posunavail").style.display = "block"; | |
126 | document.getElementById("posavail").style.display = "none"; | |
127 | document.getElementById("posLat").textContent = "..."; | |
128 | document.getElementById("posLong").textContent = "..."; | |
129 | document.getElementById("posAlt").textContent = "..."; | |
130 | document.getElementById("posAcc").textContent = "..."; | |
131 | document.getElementById("posAltAcc").textContent = "..."; | |
132 | document.getElementById("posHead").textContent = "..."; | |
133 | document.getElementById("posSpd").textContent = "..."; | |
134 | document.getElementById("posTime").textContent = "..."; | |
135 | }, | |
136 | watchID: null, | |
137 | } | |
138 | ||
139 | var gModGrav = { | |
140 | activate: function() { | |
14a57547 | 141 | gSounds.scan.play(); |
1753d94a RK |
142 | document.getElementById("gravunavail").style.display = "none"; |
143 | document.getElementById("gravavail").style.display = "block"; | |
144 | window.addEventListener("deviceorientation", this.orientEvent, true); | |
145 | window.addEventListener("devicemotion", this.motionEvent, true); | |
146 | }, | |
147 | deactivate: function() { | |
14a57547 | 148 | gSounds.scan.pause(); |
1753d94a RK |
149 | window.removeEventListener("deviceorientation", this.orientEvent, true); |
150 | window.removeEventListener("devicemotion", this.motionEvent, true); | |
151 | document.getElementById("gravunavail").style.display = "block"; | |
152 | document.getElementById("gravavail").style.display = "none"; | |
153 | }, | |
154 | orientEvent: function(orientData) { | |
b5c483f2 RK |
155 | //document.getElementById("gravAbs").textContent = orientData.absolute; |
156 | document.getElementById("gravAlpha").textContent = orientData.alpha.toFixed(1) + "°"; | |
157 | document.getElementById("gravBeta").textContent = orientData.beta.toFixed(1) + "°"; | |
158 | document.getElementById("gravGamma").textContent = orientData.gamma.toFixed(1) + "°"; | |
1753d94a RK |
159 | }, |
160 | motionEvent: function(event) { | |
b5c483f2 RK |
161 | document.getElementById("gravX").textContent = event.accelerationIncludingGravity.x.toFixed(2) + " m/s²"; |
162 | document.getElementById("gravY").textContent = event.accelerationIncludingGravity.y.toFixed(2) + " m/s²"; | |
163 | document.getElementById("gravZ").textContent = event.accelerationIncludingGravity.z.toFixed(2) + " m/s²"; | |
164 | //document.getElementById("gravRot").textContent = event.rotationRate; | |
1753d94a RK |
165 | }, |
166 | } | |
167 | ||
168 | var gModAcou = { | |
14a57547 RK |
169 | activate: function() { |
170 | //gSounds.scan.play(); | |
171 | }, | |
172 | deactivate: function() { | |
173 | gSounds.scan.pause(); | |
174 | }, | |
1753d94a RK |
175 | } |
176 | ||
177 | var gModNull = { | |
14a57547 RK |
178 | activate: function() { |
179 | //gSounds.scan.play(); | |
180 | }, | |
181 | deactivate: function() { | |
182 | gSounds.scan.pause(); | |
183 | }, | |
eabed1a4 | 184 | } |