-
Notifications
You must be signed in to change notification settings - Fork 2
/
sbs-ui-wireup.js
75 lines (62 loc) · 2.31 KB
/
sbs-ui-wireup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Controls behavior functions for the Artemis SBS GUI imitation/supplement
// Separated because it should be called at the end of the page, when document is nearly ready
// and common functions already defined.
// authored by [email protected]
// released under MIT license; see LICENSE file.
//=\\ Standard Wire-up
function makeExclusiveActiveButton(btnelm) {
document.querySelectorAll('button.major_action').forEach(function(elm,idx,arr){
elm.className = elm.className.replace(/(?:^|\s)major_action_active(?!\S)/,'');
//elm.className = elm.className.replace(/\bmajor_action_active\b/,'');
} );
btnelm.className += " major_action_active";
audioAcknowledge && audioAcknowledge();
}
document.querySelectorAll('button.major_action').forEach(function(elm,idx,arr){
elm.addEventListener("click", function(){ makeExclusiveActiveButton(this); });
} );
if (sessionStorage["greeting"] == "acknowledged") {
var commElm = document.querySelector("#communique");
if (commElm) {
commElm.style.display = 'none';
}
}
var audioExtensions = {};
audioExtensions["ogg"] = "ogg";
audioExtensions["webm"] = "webm";
audioExtensions["mp4"] = "aac";
var audioPath = "./audio/";
var audioType;
var audAck;
var audAlert;
var audInput;
auDummy = document.getElementById("audUmmy").appendChild(document.createElement("audio"));
for (var key in audioExtensions) {
if (auDummy.canPlayType("audio/"+audioExtensions[key]) != '') {
auDummy.src = audioPath + "ui2." + key;
//TODO: test it further??
console.log(auDummy.src + " " +auDummy.src.lastIndexOf("."));
audioType = auDummy.src.slice(auDummy.src.lastIndexOf(".") + 1);
console.log("We have a winner: " + audioType);
break;
}
}
audAck = new Audio("audio/bleep." + audioType);
audAlert = new Audio("audio/ui13." + audioType);
audInput = new Audio("audio/ui2." + audioType);
function audioAlert() {
window.console && console.log(audAlert.readyState)
//audAlert.load();
audAlert.play();
//TODO:bonus: have a fallback for no supported file types (or MUTE active): floating div pops up and flashes, then disappears. der blinken lights
}
function audioAcknowledge() {
audAck.play();
}
function audioInput() {
audInput.play();
}
document.addEventListener("DOMContentLoaded", function(event) {
console.log("Attempting to play " + audAck);
audioAcknowledge();
});