-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
86 lines (66 loc) · 2.9 KB
/
main.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
76
77
78
79
80
81
82
83
84
85
86
const colorPickerUI = document.querySelector("#colorpicker-ui");
const scene = document.querySelector("a-scene");
// Check if the user has a VR headset, because this application won't work without one.
window.addEventListener('enter-vr', e => colorPickerUI.setAttribute("scale", "0.5 0.5"));
window.addEventListener('exit-vr', e => colorPickerUI.setAttribute("scale", "0 0"));
const cpSwatchBtns = document.querySelectorAll(
"#colorpicker-container > #swatches-panel > div:not(.tool)"
);
const cpCloseBtn = document.querySelector(
"#colorpicker-container > #swatches-panel > div.tool#close"
);
const cpDeleteBtn = document.querySelector(
"#colorpicker-container > #swatches-panel > div.tool#delete"
);
const cpResetBtn = document.querySelector(
"#colorpicker-container > #delete-confirmation-panel > #reset-button"
);
const cpCancelBtn = document.querySelector(
"#colorpicker-container > #delete-confirmation-panel > #cancel-button"
);
cpSwatchBtns.forEach(swatchBtn => {
swatchBtn.addEventListener("click", event => {
cpSwatchBtns.forEach(el => {
el.innerHTML = "";
el.removeAttribute("id");
});
event.target.innerHTML = '<svg fill="white" style="margin: 5px" viewBox="0 0 20 20"><path fill-rule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clip-rule="evenodd"></path></svg>';
event.target.setAttribute("id", "active-swatch");
});
});
cpCloseBtn.addEventListener("click", event => {
colorPickerUI.setAttribute(
"animation",
"property: scale; to: 0 0 0; dur: 750;"
);
});
cpDeleteBtn.addEventListener("click", event => {
document
.querySelector("#colorpicker-container > #swatches-panel")
.classList.add("hide-panel");
document
.querySelector("#colorpicker-container > #delete-confirmation-panel")
.classList.remove("hide-panel");
});
cpCancelBtn.addEventListener("click", event => {
document
.querySelector("#colorpicker-container > #delete-confirmation-panel")
.classList.add("hide-panel");
document
.querySelector("#colorpicker-container > #swatches-panel")
.classList.remove("hide-panel");
});
cpResetBtn.addEventListener("click", event => {
document.querySelectorAll(".brush-point").forEach(element => element.remove());
document
.querySelector("#colorpicker-container > #delete-confirmation-panel")
.classList.add("hide-panel");
document
.querySelector("#colorpicker-container > #swatches-panel")
.classList.remove("hide-panel");
});
document.addEventListener("keydown", event => {
if (event.key !== "l") return;
const scaleToValue = colorPickerUI.getAttribute("scale").x < 0.5 ? "0.5 0.5" : "0 0";
colorPickerUI.setAttribute("animation", `property: scale; to: ${scaleToValue} 0; dur: 650;`);
});