-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
90 lines (70 loc) · 1.96 KB
/
index.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
87
88
89
90
const start = document.querySelector("#start");
const score = document.querySelector("#score");
const home = document.querySelector(".home");
const modal = document.querySelector(".modal");
// Animated Icon Hover Options
function startIconAdd() {
if (start.classList.contains("icon")) return;
start.classList.add("icon");
}
function startIconRmv() {
if (start.classList.contains("icon")) {
start.classList.remove("icon");
}
}
function scoreIconAdd() {
if (score.classList.contains("icon")) return;
start.classList.remove("icon");
score.classList.add("icon");
}
function scoreIconRmv() {
if (score.classList.contains("icon")) {
score.classList.remove("icon");
startIconAdd();
}
}
start.addEventListener("mouseenter", (ev) => {
ev.preventDefault();
startIconAdd();
});
score.addEventListener("mouseenter", (ev) => {
ev.preventDefault();
scoreIconAdd();
});
score.addEventListener("mouseleave", (ev) => {
ev.preventDefault();
scoreIconRmv();
});
// Modal User Name
function saveUser() {
const value = document.querySelector(".modal-input");
if (!validateInput(value)) return;
localStorage.setItem("user", JSON.stringify(value.value));
location.replace(`/pages/game/index.html`);
}
function validateInput(value) {
const notFound = document.querySelector("span.not-found");
const error = document.querySelector("span.error");
if (value.value.length === 0) {
value.classList.add("error");
notFound.classList.remove("desactive");
return false;
} else if (value.value.length < 3) {
value.classList.add("error");
error.classList.remove("desactive");
return false;
}
value.classList.remove("error");
notFound.classList.add("desactive");
error.classList.add("desactive");
return true;
}
function closeModal() {
modal.classList.add("desactive");
}
function onModalUserName() {
modal.classList.remove("desactive");
}
function redirectScoreScreen() {
location.replace(`/pages/score/index.html`);
}