-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
50 lines (48 loc) · 1.75 KB
/
script.js
File metadata and controls
50 lines (48 loc) · 1.75 KB
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
var view = {
list: document.querySelector('ul'),
content: document.querySelector('#content'),
contentClose: document.querySelector('#content > button'),
modal: document.body.querySelector('aside'),
playPause: document.body.querySelector('#playPause'),
audioSource: document.body.querySelector('#source'),
}
var audioConvolver = new AudioConvolver();
audioConvolver.buffersPromises.then(_ => {
view.playPause.textContent = 'Enter';
view.playPause.removeAttribute('disabled');
})
function showOverlay(e) {
if (e.target.tagName !== "INPUT") return;
view.content.classList.add("overlay");
const label = e.target.nextElementSibling;
// view.content.querySelector('img').src = label.parentElement.querySelector('img').src;
view.content.querySelector("h4").textContent = label.dataset.title;
view.content.querySelector("p").textContent = label.dataset.text;
}
function handleImpulseSelection(e) {
if (e.target.tagName !== "INPUT") return;
const impulseIdx = Number(e.target.value) - 1;
if(impulseIdx !== audioConvolver.impulseIdx) {
showOverlay(e);
audioConvolver.updateImpulse(impulseIdx);
} else {
e.target.checked = false;
audioConvolver.removeImpulse();
}
}
function init() {
view.modal.style.display = 'none';
audioConvolver.setup(view.audioSource, view.content);
}
// view.list.addEventListener('change', handleImpulseSelection);
view.list.addEventListener('click', handleImpulseSelection);
view.contentClose.addEventListener('click', function() {
view.content.classList.remove('overlay');
});
window.onkeydown = function(e) {
var keyCode = e.key || e.keyIdentifier || e.keyCode;
if (keyCode == 27 || keyCode == 'Escape') {
view.content.classList.remove('overlay');
}
}
view.playPause.addEventListener('click', init);