This repository was archived by the owner on May 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhighlight.js
51 lines (47 loc) · 1.6 KB
/
highlight.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
/* global AFRAME */
AFRAME.registerComponent("highlight", {
init: function () {
var buttonEls = (this.buttonEls = this.el.querySelectorAll(".menu-button"));
var backgroundEl = document.querySelector("#background");
this.onClick = this.onClick.bind(this);
this.onMouseEnter = this.onMouseEnter.bind(this);
this.onMouseLeave = this.onMouseLeave.bind(this);
this.reset = this.reset.bind(this);
backgroundEl.addEventListener("click", this.reset);
for (var i = 0; i < buttonEls.length; ++i) {
buttonEls[i].addEventListener("mouseenter", this.onMouseEnter);
buttonEls[i].addEventListener("mouseleave", this.onMouseLeave);
buttonEls[i].addEventListener("click", this.onClick);
}
},
onClick: function (evt) {
evt.target.pause();
evt.target.setAttribute("material", "color", "#046de7");
this.el.addState("clicked");
evt.target.object3D.scale.set(1.2, 1.2, 1.2);
},
onMouseEnter: function (evt) {
var buttonEls = this.buttonEls;
evt.target.setAttribute("material", "color", "#046de7");
for (var i = 0; i < buttonEls.length; ++i) {
if (evt.target === buttonEls[i]) {
continue;
}
buttonEls[i].setAttribute("material", "color", "white");
}
},
onMouseLeave: function (evt) {
if (this.el.is("clicked")) {
return;
}
evt.target.setAttribute("material", "color", "white");
},
reset: function () {
var buttonEls = this.buttonEls;
for (var i = 0; i < buttonEls.length; ++i) {
this.el.removeState("clicked");
buttonEls[i].play();
buttonEls[i].emit("mouseleave");
}
},
});