forked from MatthieuGuinet/Project1_Pokestar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
247 lines (207 loc) · 8.38 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
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
//import of the displayText function to unwrap the legend section test
import displayText from "./displayText.js";
//import hoverButton to use the hovering on the buttons a the top of the pokemon
import { headerFunctions } from "./header_button.js";
import { options } from "./chart.js";
import { quizFunctions } from "./quiz.js";
// import modify content function
import { switchPokemon } from "./content_modification.js";
// loading eevee display when opening the website for the first time
window.addEventListener("load", () => {
switchPokemon.eeveeContent.replaceContent();
});
// ouverture et fermeture du menu burger + animation de l'icone
const burgerIcon = document.getElementById("burger_icon");
const burgerMenu = document.getElementById("nav_links");
const burger = document.getElementById("burger");
function closeNav() {
burgerMenu.classList.toggle("burger_open");
burger.classList.toggle("animationOpen");
}
burgerIcon.addEventListener("click", function () {
closeNav();
});
// fermeture du menu burger après click sur un lien
const navElement = document.getElementsByClassName("nav");
for (let i = 0; i < navElement.length; i++) {
const link = navElement[i];
link.addEventListener("click", () => {
closeNav();
});
}
//Hover and click on desktop header band
const textButtons = document.querySelectorAll(".text_button");
const svgButtons = document.querySelectorAll(".lr_buttons");
headerFunctions.actionButton(textButtons);
headerFunctions.actionButton(svgButtons);
// Section "legend", button "poursuivre l'aventure"
let legendButton = document.getElementById("legend-deployment");
legendButton.addEventListener("click", () => {
displayText();
});
// déclaration des variables contenant les coordonnées de départ. On utilise "let" car les coordonnées vont être amenées à changer
let startX = 0;
let startY = 0;
let scrollTop = 0;
let scrollLeft = 0;
// déclaration des variables contenant la carte et son conteneur
const scrollableMap = document.getElementById("scrollable_map");
const wrapper = document.getElementById("map_wrapper");
// fonction contenant l'ensemble des fonctions et instructions permettant le scroll
function scrollTheMap() {
// méthode 'onmousedown' crée une interaction lorsque le clic gauche est maintenu;
// le paramètre event est un objet "natif" de JS contenant diverses données : par exemple "event.clientX" donne la coordonnée sur l'axe X du pointeur de la souris
scrollableMap.onmousedown = function mouseDown(event) {
startX = event.clientX;
startY = event.clientY;
scrollTop = wrapper.scrollTop;
scrollLeft = wrapper.scrollLeft;
};
// méthode 'onmousemove' crée une interaction lorsque l'on bouge le curseur avec le clic gauche enfoncé
// on donne les instructions afin que le scroll suive le curseur
scrollableMap.onmousemove = function mouseMove(event) {
wrapper.scrollTo({
left: scrollLeft + (startX - event.clientX),
top: scrollTop + (startY - event.clientY),
});
};
// méthode 'onmouseup' crée une interaction lorsque l'on relâche le clic gauche
// on veut que le scroll s'arrête
scrollableMap.onmouseup = function mouseUp() {
scrollableMap.onmousemove = null;
};
}
// création d'un 'addeventlistener' appelant la fonction principale lorsque le clic gauche est enfoncé
scrollableMap.addEventListener("mousedown", scrollTheMap);
//Chart
let chart = new ApexCharts(document.querySelector("#chart"), options);
chart.render();
// Section "quiz" button "suivant"
let nextButton = document.getElementById("quiz-button-next");
nextButton.addEventListener("click", () => {
quizFunctions.nextQuestion();
});
// Section "quiz". adding an isChosen class to the chosen item, removing all others
const allAnswers = document.getElementsByClassName("quiz-answer");
for (let i = 0; i < allAnswers.length; i++) {
allAnswers[i].addEventListener("click", function () {
// deleting all "isChosen" classes among the answers
for (let j = 0; j < allAnswers.length; j++) {
allAnswers[j].classList.remove("isChosen");
}
// adding "isChosen" to the allAnswers[i] clicked
allAnswers[i].classList.add("isChosen");
document.getElementById("quiz-error").style.display = "none";
document.getElementById("quiz-button-next").style.marginBottom = "30px";
});
}
// Section "quiz" adding addeventListener function to replay button
const replayButton = document.getElementById("quiz-replay-button");
replayButton.addEventListener("click", () => {
quizFunctions.replay();
});
//sticky-nav hover
const icon = document.getElementsByClassName("sticky-nav-icon-desktop");
const circle = document.getElementsByClassName("sticky-nav-circle-desktop");
const eeveeIcon = document.getElementById("eevee-icon-desktop");
const vaporeonIcon = document.getElementById("vaporeon-icon-desktop");
const jolteonIcon = document.getElementById("jolteon-icon-desktop");
const flareonIcon = document.getElementById("flareon-icon-desktop");
function hoverIcon(stickyIcon) {
for (let i = 0; i < stickyIcon.length; i++) {
const nav = stickyIcon[i];
nav.addEventListener("mouseover", function () {
icon[i].style.fill = "white";
eeveeIcon.style.fill = "#C38F5C";
vaporeonIcon.style.fill = "#54ADFF";
jolteonIcon.style.fill = "#FFCA42";
flareonIcon.style.fill = "#FF7D05";
circle[i].style.opacity = "1";
icon[i].style.cursor = "pointer";
circle[i].style.cursor = "pointer";
});
nav.addEventListener("mouseout", function () {
icon[i].style.fill = "black";
circle[i].style.opacity = "0.6";
});
}
}
const stickyNavMobile = document.getElementById("sticky-nav-mobile");
const stickyNavDesktop = document.getElementById("sticky-nav-desktop");
function scrollStickyNavMobile() {
let firstScrollPosition = window.pageYOffset;
window.addEventListener("scroll", function () {
let secondScrollPosition = window.pageYOffset;
if (firstScrollPosition < secondScrollPosition) {
stickyNavMobile.classList.add("down");
// stickyNavMobile.style.bottom = "-50px"
} else {
stickyNavMobile.classList.remove("down");
// stickyNavMobile.style.bottom = "0"
}
firstScrollPosition = secondScrollPosition;
});
}
let mobile = window.matchMedia("(max-width: 768px)");
let desktop = window.matchMedia("(min-width: 769px)");
if (desktop.matches) {
hoverIcon(icon);
hoverIcon(circle);
} else {
scrollStickyNavMobile();
}
//sticky-nav addEventListener desktop
let eeveeNavButton = document.getElementById("eevee-nav-button");
eeveeNavButton.addEventListener("click", () => {
switchPokemon.eeveeContent.replaceContent();
});
let flareonNavButton = document.getElementById("flareon-nav-button");
flareonNavButton.addEventListener("click", () => {
switchPokemon.flareonContent.replaceContent();
});
let jolteonNavButton = document.getElementById("jolteon-nav-button");
jolteonNavButton.addEventListener("click", () => {
switchPokemon.jolteonContent.replaceContent();
});
let vaporeonNavButton = document.getElementById("vaporeon-nav-button");
vaporeonNavButton.addEventListener("click", () => {
switchPokemon.vaporeonContent.replaceContent();
});
//sticky-nav addEventListener smartphone
let eeveeNavButtonSmartphone = document.getElementById(
"eevee-nav-button-smartphone"
);
eeveeNavButtonSmartphone.addEventListener("click", () => {
switchPokemon.eeveeContent.replaceContent();
});
let flareonNavButtonSmartphone = document.getElementById(
"flareon-nav-button-smartphone"
);
flareonNavButtonSmartphone.addEventListener("click", () => {
switchPokemon.flareonContent.replaceContent();
});
let jolteonNavButtonSmartphone = document.getElementById(
"jolteon-nav-button-smartphone"
);
jolteonNavButtonSmartphone.addEventListener("click", () => {
switchPokemon.jolteonContent.replaceContent();
});
let vaporeonNavButtonSmartphone = document.getElementById(
"vaporeon-nav-button-smartphone"
);
vaporeonNavButtonSmartphone.addEventListener("click", () => {
switchPokemon.vaporeonContent.replaceContent();
});
//some styling features to get backlines in document's specific places
document
.getElementById("caracteristics-text")
.setAttribute("style", "white-space: pre-line;");
document
.getElementById("legend-text")
.setAttribute("style", "white-space: pre-line;");
document
.getElementById("localisation-text")
.setAttribute("style", "white-space: pre-line;");
document
.getElementById("little-description-text")
.setAttribute("style", "white-space: pre-line;");