blob: 03cd4dede7e36d4c835d62489a01b7c4918a3214 (
plain)
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
|
const sfx = new Audio("audio/button-press.mp3");
export function DeckButton(name) {
const elem = document.getElementById(`${name}-button`);
const images = { up: `images/${name}-button-up.jpg`, down: `images/${name}-button-down.jpg` };
let state = "off";
const turnOn = function () {
state = "on";
elem.src = images.down;
};
const turnOff = function () {
state = "off";
elem.src = images.up;
};
return {
state: () => state,
toggle: (opts = {sound: true}) => {
state === "off" ? turnOn(opts) : turnOff(opts);
if (opts.sound) sfx.play();
}
};
}
|