-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
125 lines (88 loc) · 2.67 KB
/
Copy pathscript.js
File metadata and controls
125 lines (88 loc) · 2.67 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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
const introTrigger = document.querySelector("#intro-trigger");
const logo = document.querySelector(".logo");
const sticker = document.querySelector(".sticker");
const INTRO_READY_DELAY = 3250;
const EXIT_FALLBACK_DELAY = 1800;
const BOUNCE_DELAY = 800;
const BOUNCE_REPEAT_INTERVAL = 15000;
const ARROW_DELAY = 60000;
let isExiting = false;
let bounceInterval = null;
let arrowTimer = null;
/* Bounce automatically after sticker reveal */
sticker.addEventListener("animationend", (event) => {
if (event.animationName !== "sticker-reveal") {
return;
}
window.setTimeout(() => {
if (!isExiting) {
introTrigger.classList.add("intro-bounce");
}
}, BOUNCE_DELAY);
});
/* Remove the temporary class after the bounce */
introTrigger.addEventListener("animationend", (event) => {
if (event.animationName !== "hover-bounce") {
return;
}
introTrigger.classList.remove("intro-bounce");
});
/* Repeat the attention bounce until the visitor interacts */
bounceInterval = window.setInterval(() => {
const isReady =
document.body.classList.contains("intro-ready");
if (isReady && !isExiting) {
introTrigger.classList.add("intro-bounce");
}
}, BOUNCE_REPEAT_INTERVAL);
/* Show a hint arrow if the visitor still hasn't clicked after a while */
arrowTimer = window.setTimeout(() => {
if (!isExiting) {
document.body.classList.add("intro-nudge");
}
}, ARROW_DELAY);
/* Enable click after the sticker has entered */
window.setTimeout(() => {
document.body.classList.add("intro-ready");
introTrigger.setAttribute("aria-disabled", "false");
introTrigger.removeAttribute("tabindex");
}, INTRO_READY_DELAY);
/* Click, animate the bee, then navigate */
introTrigger.addEventListener("click", (event) => {
event.preventDefault();
const isReady =
document.body.classList.contains("intro-ready");
if (!isReady || isExiting) {
return;
}
isExiting = true;
window.clearInterval(bounceInterval);
window.clearTimeout(arrowTimer);
const destination = introTrigger.href;
document.body.classList.remove("intro-ready");
document.body.classList.add("is-exiting");
introTrigger.classList.remove("intro-bounce");
introTrigger.setAttribute("aria-disabled", "true");
let hasNavigated = false;
const navigate = () => {
if (hasNavigated) {
return;
}
hasNavigated = true;
window.location.assign(destination);
};
const handleAnimationEnd = (animationEvent) => {
if (animationEvent.animationName === "bee-horizontal") {
navigate();
}
};
logo.addEventListener(
"animationend",
handleAnimationEnd,
{ once: true }
);
window.setTimeout(
navigate,
EXIT_FALLBACK_DELAY
);
});