forked from johannesloor/WebAudio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheventHandler.js
52 lines (43 loc) · 1.49 KB
/
eventHandler.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
let touchArea = document.getElementById("touchArea");
let compareButton = document.getElementById("compareButton");
let playButton = document.getElementById("playButton");
touchArea.onpointerup = touchAreaUp;
touchArea.onpointerdown = touchAreaDown;
playButton.onclick = playButtonClick;
compareButton.onclick = compareButtonClick;
let touchAreaStatus = false;
touchArea.style.pointerEvents = "none";
touchArea.style.opacity = "0.5";
function touchAreaToggle() {
if (touchAreaStatus == false) {
touchArea.style.pointerEvents = "auto";
touchArea.style.opacity = "1";
touchAreaStatus = true;
}
}
function touchAreaUp(event) {
compareButton.disabled = false;
touchArea.innerHTML = "Sound saved";
event.preventDefault();
}
function touchAreaDown(event) {
touchArea.innerHTML = "";
touchArea.style.cssText = "border-color:transparent;";
event.preventDefault();
}
function playButtonClick(event) {
webAudioXML.playSequence("_storedGesture");
touchAreaToggle();
event.preventDefault();
}
function compareButtonClick(event) {
webAudioXML.lastGesture.play();
webAudioXML.copyLastGestureToClipboard();
compare(webAudioXML.lastGesture, webAudioXML.getSequence("_storedGesture"))
? ((touchArea.style.cssText = "border-color:green;"),
(touchArea.innerHTML =
"YOU DID IT! <br/> The sounds and gestures match!"))
: ((touchArea.style.cssText = "border-color:red;"),
(touchArea.innerHTML = "The sounds do not match.. <br/> Try again!"));
event.preventDefault();
}