-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
253 lines (218 loc) Β· 7.07 KB
/
app.js
File metadata and controls
253 lines (218 loc) Β· 7.07 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
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
248
249
250
251
252
253
// Elements selection
const onButton = document.getElementById("on-button");
const screen = document.querySelector(".screen");
const vhsContainer = document.querySelectorAll(".vhs");
const vhsInTitle = document.querySelector(".vhs-in h2");
const vhsIn = document.querySelector(".vhs-in");
//const channelType = document.querySelector('.channel-type');
const welcomeMessage = document.querySelector(".welcome-message");
const tvVhsContent = document.querySelectorAll(".content");
const aboutMe = document.getElementById("AboutMe");
const cards = document.querySelectorAll(".card");
const cardsCon = document.querySelector(".cards"); //fpr changing
const newGameBtn = document.querySelector(".new-game-btn");
const winMessages = document.querySelector(".winMessage");
const carouselImgs = document.querySelectorAll(".carousel img");
const prevBtn = document.getElementById("prev");
const nextBtn = document.getElementById("next");
const winMessage = document.querySelector(".win-text");
let prevPage = "AboutMe"; //Initial page
let prevCard = "0-0"; //Initial card status
let win = 0;
let isEveryCardRight = true;
let imagesPosition = 0; //Carousel
// On and off button*******************************************************************************************************
const onOff = () => {
onButton.classList.toggle("off-button");
onButton.classList.toggle("on-button");
welcomeMessage.classList.toggle("welcome-message-off");
tvVhsContent.forEach((vhsContent) => {
//Changing the active page off
if (vhsContent.classList.length > 1) {
contectActive(vhsContent);
prevPage = vhsContent.id;
}
if (onButton.classList.value == "on-button" && vhsContent.id == prevPage) {
contectActive(vhsContent);
vhsInTitle.textContent = vhsContent.childNodes[1].innerText;
vhsIn.style.boxShadow = `var(--${prevPage}Glow)`;
}
});
};
onButton.addEventListener("click", onOff);
//VHS***********************************************************************************************************************
// Chose VHS
const changeVhs = (event) => {
let vhsTextClean = event.target.textContent;
let vhsText = vhsTextClean.replace(" ", "").replace("?", ""); // seleccting the inner text for the changing
// Check the same page
if (vhsInTitle.textContent == vhsText) {
return;
}
// Changing the VHS
vhsInTitle.textContent = vhsTextClean;
vhsIn.style.backgroundColor = `var(--${vhsText})`;
vhsIn.style.boxShadow = `var(--${vhsText}Glow)`;
// Changing the Channel Type
// Change the Content in the TV
tvVhsContent.forEach((vhsContent) => {
//Changing the active page off
if (vhsContent.classList.length > 1) {
contectActive(vhsContent);
}
//Changing the new page on
if (vhsText == vhsContent.id) {
contectActive(vhsContent);
}
});
};
const contectActive = (vhsContent) => {
/*if(vhsContent.id == 'Game'){
vhsContent.classList.toggle('content-active-flex');
} else {
vhsContent.classList.toggle('content-active-grid');
}*/
vhsContent.classList.toggle("content-active-grid");
};
vhsContainer.forEach((vhs) => {
vhs.addEventListener("click", (event) => {
//if the television is on
if (onButton.classList.value == "on-button") {
changeVhs(event);
}
});
});
//Game******************************************************************************************************/
const newGame = () => {
cardShuffle();
removeCardToggle();
changeImages();
prevCard = "0-0";
win = 0;
isEveryCardRight = true;
winMessages.style.display = "none";
cardsCon.style.gridRow = "2/ 4";
/*newGameBtn.style.marginTop ='10px';*/
};
const cardShuffle = () => {
cards.forEach((card) => {
card.style.order = Math.floor(Math.random() * cards.length);
});
};
const removeCardToggle = () => {
cards.forEach((card) => {
//console.log(card.classList);
card.classList.remove("cardCorrect");
card.classList.remove("cardWrong");
card.style.display = "grid";
//console.log(card.classList);
});
};
const changeImages = () => {
let firstCars = Math.floor(Math.random() * carouselImgs.length);
firstCars = firstCars > 1 ? firstCars : 2;
cards.forEach((card) => {
if (card.id.charAt(0) == "1") {
card.children[0].src = `./images/slide_images/image0${firstCars}.jpg`;
} else if (card.id.charAt(0) == "2") {
card.children[0].src = `./images/slide_images/image0${firstCars - 1}.jpg`;
} else if (card.id.charAt(0) == "3") {
card.children[0].src = `./images/slide_images/image0${firstCars + 1}.jpg`;
}
});
};
const gameOn = (event) => {
if (isEveryCardRight) {
let selectedCard = event.target;
if (prevCard == "0-0") {
selectedCard.classList.toggle("cardCorrect");
prevCard = selectedCard;
} else {
if (prevCard.id.charAt(0) == selectedCard.id.charAt(0)) {
selectedCard.classList.toggle("cardCorrect");
prevCard = "0-0";
win++;
} else {
prevCard.classList.toggle("cardCorrect");
prevCard.classList.toggle("cardWrong");
selectedCard.classList.toggle("cardWrong");
isEveryCardRight = false;
setTimeout(() => {
prevCard.classList.toggle("cardWrong");
prevCard = "0-0";
}, 500);
setTimeout(() => {
selectedCard.classList.toggle("cardWrong");
}, 500);
}
}
if (win == 3) {
winOnOff();
}
} else {
isEveryCardRight = true;
}
};
const displayWin = () => {
cards.forEach((card) => {
card.style.display = "none";
cardsCon.style.gridRow = "2/ 3";
winMessages.style.display = "flex";
});
};
cards.forEach((card) => {
card.addEventListener("click", (event) => {
gameOn(event);
});
});
const winOnOff = () => {
winMessage.classList.toggle("win-text-on");
};
winMessage.addEventListener("click", () => {
winOnOff();
displayWin();
//ZsetTimeout(displayWin, 1000);
});
newGameBtn.addEventListener("click", newGame);
//Carousel******************************************************
const nextImage = (move) => {
toggleActiveImage(carouselImgs);
if (move === "+") {
imagesPosition++;
} else {
imagesPosition--;
}
checkLimit();
toggleActiveImage(carouselImgs);
};
const checkLimit = () => {
if (imagesPosition > carouselImgs.length - 1) {
imagesPosition = 0;
} else if (imagesPosition < 0) {
imagesPosition = carouselImgs.length - 1;
}
};
const toggleActiveImage = (carouselImgs) => {
carouselImgs[imagesPosition].classList.toggle("active-image");
carouselImgs[imagesPosition].classList.toggle("unactive-image");
};
nextBtn.addEventListener("click", () => nextImage("+"));
prevBtn.addEventListener("click", () => nextImage("-"));
const whyFacSelect = document.querySelectorAll(".special-why");
whyFacSelect.forEach((reason) => {
reason.addEventListener("click", () => {
reason.childNodes[3].classList.toggle("why-full-On");
});
});
const logKey = (e) => {
if (aboutMe.classList.length < 2) return;
switch (e.keyCode) {
case 37:
nextImage("-");
break;
case 39:
nextImage("+");
break;
}
};
document.addEventListener("keydown", logKey);