-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstyle.js
514 lines (429 loc) · 14 KB
/
style.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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
var totalPrice = 0;
// THESE 3 FUNCTIONS HANDLE UPDATING THE TOTAL PRICE, WHENEVER A USER CLICKS ON A PLAN CARD AND REUPDATING THE HTML AFTER EVERY CLICK
// FIX IT SO IT WORKS FOR YEARS TOO
// TIP ADD AN EVENTLISTENER TO THE YEAR TOGGLE SUCH THAT IF IT IS ACTIVE, IT GETS TOGGLES DIFFERENTLY
function CalCurrentPrice(SumOfPrice) {
totalPrice += SumOfPrice;
updateTotalPriceInHTML();
}
function calcPlanPrice(price) {
totalPrice = price;
updateTotalPriceInHTML();
}
function updateTotalPriceInHTML() {
const planPerMonth = document.querySelector(".totalPerMonth");
let disStr = `$${totalPrice}/mo`;
planPerMonth.innerHTML = disStr;
}
(function () {
const planSection = [
{
title: "Arcade",
img: "/assets/images/icon-arcade.svg",
monthPrice: 9,
yearPrice: 90,
yearText: "2 months free",
class: "card-one",
},
{
title: "Advance",
img: "/assets/images/icon-advanced.svg",
monthPrice: 12,
yearPrice: 120,
yearText: "2 months free",
class: "card-two",
},
{
title: "Pro",
img: "/assets/images/icon-pro.svg",
monthPrice: 15,
yearPrice: 150,
yearText: "2 months free",
class: "card-three",
},
];
const groupCard = document.querySelector(".group-card");
function displayCard(cards) {
let displaycard = planSection.map((items) => {
return `<div class="card ${items.class}">
<div class="card-body">
<img src=${items.img} alt="" class="image">
<div class="Arcade card-word">
<h6 class="mb-0">${items.title}</h6>
<p class="card-text opacity-50 monthly-plan">$${items.monthPrice}/mo</p>
</div>
<div class="yearly-plan">
<p class="opacity-50 mb-0">$${items.yearPrice}/yr</p>
<p class="fw-bold text">2 months free</p>
</div>
</div>
</div> `;
});
displaycard = displaycard.join("");
groupCard.innerHTML = displaycard;
// looping thru the 3 plan cards
const Cards = document.querySelectorAll(".card");
const arc = document.querySelector(".arcade");
const sumOne = document.querySelector(".sum-one");
const sumTwo = document.querySelector(".sum-two");
const sumThree = document.querySelector(".sum-three");
const arcOne = document.querySelector(".arc-one");
const arcTwo = document.querySelector(".arc-two");
const arcThree = document.querySelector(".arc-three");
Cards.forEach((cards, index) => {
cards.addEventListener("click", (e) => {
const btn = e.currentTarget.classList;
calcPlanPrice(planSection[index].monthPrice);
Cards.forEach((item) => {
if (item !== btn) {
item.classList.remove("hover");
}
});
// console.log(index);
if (btn.contains("card-one")) {
btn.toggle("hover");
if (sumOne) {
arcOne.classList.add("active");
}
if (sumTwo) {
arcTwo.classList.remove("active");
}
if (sumThree) {
arcThree.classList.remove("active");
}
// addMonth.push(ArcMonprice)
// console.log(addMonth);
// addYear.push(ArcYrprice)
// console.log(addYear);
}
if (btn.contains("card-two")) {
btn.toggle("hover");
if (sumTwo) {
arcTwo.classList.add("active");
}
if (sumOne) {
arcOne.classList.remove("active");
}
if (sumThree) {
arcThree.classList.remove("active");
}
}
if (btn.contains("card-three")) {
btn.toggle("hover");
if (sumThree) {
arcThree.classList.add("active");
}
if (sumOne) {
arcOne.classList.remove("active");
}
if (sumTwo) {
arcTwo.classList.remove("active");
}
}
// let price = document.querySelectorAll('.price')
// const lastPrice = price
// lastPrice.forEach((Price)=>{
// addMonth.push(Price.textContent)
// })
// next to addon
const Nexttoaddon = document.querySelector(".Nexttoaddon");
Nexttoaddon.addEventListener("click", () => {
AddOn.classList.add("next");
plan.classList.remove("next");
});
});
});
}
displayCard();
// adddon section
const AddonSection = [
{
title: "Online service",
text: "Access to multiplayer games",
monthPrice: 1,
yearPrice: 10,
},
{
title: "Larger storage",
text: "Extra 1TB of cloud save",
monthPrice: 2,
yearPrice: 20,
},
{
title: "Customizable profile",
text: "customize theme on your profile",
monthPrice: 2,
yearPrice: 20,
},
];
const addonCard = document.querySelectorAll(".addOn-card");
function displayAddon() {
let displayaddon = AddonSection.map((item) => {
return `<div class="addOn-card my-3">
<div class="body-card">
<div class="card-words d-flex align-items-center justify-content-between my-2">
<div class="checkbox-container d-flex align-items-center" >
<input type="checkbox" class="checkbox checkBox-one ms-3">
<div class="checkbox-text ps-3">
<h6 class="mb-0">${item.title}</h6>
<p class="card-text opacity-50 monthly-plan">${item.text}</p>
</div>
</div>
<p class="my-2 month-text pe-3" >+$${item.monthPrice}/mo</p>
<div class="year-plan">
<p class="year-text my-2 pe-3">+$${item.yearPrice}/yr</p>
</div>
</div>
</div>
</div>`;
}).join("");
addonCard.innerHTML = displayaddon;
const AddonSections = document.querySelectorAll(".addOn-card");
AddonSections.forEach((addon, index) => {
const checkbox = addon.querySelector(".checkbox");
checkbox.addEventListener("click", () => {
CalCurrentPrice(AddonSection[index].monthPrice);
});
});
}
displayAddon();
// sum of both plansection and addsection
// const planSectiontotal = planSection.reduce((acc, item)=> acc + item.monthPrice, 0)
// const addonSectiontotal = AddonSection.reduce((acc, item)=> acc + item.monthPrice, 0)
// const totalMonthPrice = planSectiontotal + addonSectiontotal
// console.log(totalMonthPrice);
})();
const form = document.querySelector(".form");
const inputOne = document.querySelector(".input-one");
const inputtwo = document.querySelector(".input-two");
const inputthree = document.querySelector(".input-three");
const regOne = document.querySelector(".reg-one");
const regtwo = document.querySelector(".reg-two");
const regthree = document.querySelector(".reg-three");
const plan = document.querySelector(".plan");
const container = document.querySelector(".container");
// form section
form.addEventListener("submit", display);
function display(e) {
e.preventDefault();
submitted();
}
// submission function
function submitted() {
if (inputOne.value === "") {
regOne.classList.add("show");
} else {
regOne.classList.remove("show");
}
if (inputtwo.value === "") {
regtwo.classList.add("show");
} else {
regtwo.classList.remove("show");
}
if (inputthree.value === "") {
regthree.classList.add("show");
} else {
regthree.classList.remove("show");
}
// check for empty values
if (!inputOne.value || !inputtwo.value || !inputthree.value) {
plan.classList.remove("next");
container.classList.remove("next");
} else {
plan.classList.add("next");
container.classList.add("next");
}
console.log(inputOne.value, inputtwo.value, inputthree.value);
container.classList.remove("back");
plan.classList.remove("back");
clearTimeout(delayone);
}
// // plan section
const cardWord = document.querySelectorAll(".card-word");
const yearplan = document.querySelectorAll(".yearly-plan");
const slider = document.querySelector(".slider");
const index = document.querySelector(".index");
// // AddOn section and Summary section in the Toggle
const Yearplan = document.querySelectorAll(".year-plan");
const Month = document.querySelectorAll(".month-text");
const yearSum = document.querySelectorAll(".yearly");
const monthSum = document.querySelectorAll(".month");
// toggling btwn monthly and yearly price
slider.addEventListener("click", () => {
cardWord.forEach((btn) => {
if (btn) {
btn.classList.toggle("show-yearly");
}
});
yearplan.forEach((btns) => {
if (btns) {
btns.classList.toggle("show-yearly");
}
});
// Addon prices
Yearplan.forEach((year) => {
if (year) {
year.classList.toggle("show-text");
}
});
Month.forEach((month) => {
if (month) {
month.classList.toggle("show-text");
}
});
// Sum price
yearSum.forEach((Yearsum) => {
Yearsum.classList.toggle("show-text");
});
monthSum.forEach((Monthsum) => {
Monthsum.classList.toggle("show-text");
});
});
// Back to the Personal info
index.addEventListener("click", (e) => {
e.preventDefault();
container.classList.add("back");
plan.classList.add("back");
inputOne.value = "";
inputtwo.value = "";
inputthree.value = "";
});
//Addon section
const AddOn = document.querySelector(".addOn");
const blank = document.querySelector(".Blank");
const checkboxes = document.querySelectorAll(".checkbox");
const Online = document.querySelector(".Online");
const Larger = document.querySelector(".Larger");
const Customizable = document.querySelector(".Customizable");
const online = document.querySelector(".online");
const larger = document.querySelector(".larger");
const customizable = document.querySelector(".customizable");
const nextToSum = document.querySelector(".nexttosum");
// changing the background and border color of the AddOn card when clicked
const addOnCard = document.querySelectorAll(".addOn-card");
addOnCard.forEach((check) => {
const checkbox = check.querySelector(".checkbox");
checkbox.addEventListener("click", () => {
check.classList.toggle("hover");
});
});
checkboxes.forEach((checkbox) => {
checkbox.addEventListener("click", (e) => {
const btn = e.currentTarget.classList;
// let Tot = e.currentTarget.getAttribute('data-Set')
// console.log(parseInt(Tot));
// let Id = e.currentTarget.getAttribute('data-Id')
// console.log(parseInt(Id));
if (btn.contains("checkBox-one")) {
btn.toggle("hover");
if (Online) {
online.classList.toggle("active");
}
}
if (btn.contains("checkBox-two")) {
btn.toggle("hover");
if (Larger) {
larger.classList.toggle("active");
}
}
if (btn.contains("checkBox-three")) {
btn.toggle("hover");
if (Customizable) {
customizable.classList.toggle("active");
}
}
nextToSum.addEventListener("click", () => {
Sum.classList.add("next");
AddOn.classList.remove("next");
});
});
});
blank.addEventListener("click", () => {
AddOn.classList.remove("next");
plan.classList.add("next");
});
const Sum = document.querySelector(".Sum");
const backtoaddon = document.querySelector(".backtoaddon");
const confirmBtn = document.querySelector(".showThankYou");
const sum = document.querySelector(".sum");
const thankyou = document.querySelector(".thankyou");
const BackToAddon = document.querySelector(".BackToAddon");
backtoaddon.addEventListener("click", () => {
Sum.classList.remove("next");
AddOn.classList.add("next");
});
BackToAddon.addEventListener("click", () => {
plan.classList.add("next");
Sum.classList.remove("next");
});
confirmBtn.addEventListener("click", () => {
sum.classList.add("show");
thankyou.classList.add("show");
});
// setTimeOUT
// Mobile mode setTimeout
const btnone = document.querySelector(".btn-one");
const btntwo = document.querySelector(".btn-two");
const btnthree = document.querySelector(".btn-three");
const btnfour = document.querySelector(".btn-four");
function delayone() {
btnone.style.color = "black";
btnone.style.background = "var(--Light-blue)";
btnone.style.border = "var(--Light-blue)";
}
function delaytwo() {
btntwo.style.color = "black";
btntwo.style.background = "var(--Light-blue)";
btntwo.style.border = "var(--Light-blue)";
}
function delaythree() {
btnthree.style.color = "black";
btnthree.style.background = "var(--Light-blue)";
btnthree.style.border = "var(--Light-blue)";
}
function delayfour() {
btnfour.style.color = "black";
btnfour.style.background = "var(--Light-blue)";
btnfour.style.border = "var(--Light-blue)";
}
setTimeout(delayone, 1000);
setTimeout(delaytwo, 1000);
setTimeout(delaythree, 1000);
setTimeout(delayfour, 1000);
// Desktop mode setTimeout
const BtnOne = document.querySelectorAll(".Btn-one");
const BtnTwo = document.querySelectorAll(".Btn-two");
const BtnThree = document.querySelectorAll(".Btn-three");
const BtnFour = document.querySelectorAll(".Btn-four");
function delay() {
BtnOne.forEach((btn) => {
btn.style.color = "black";
btn.style.background = "var(--Light-blue)";
btn.style.border = "var(--Light-blue)";
});
}
function delayTwo() {
BtnTwo.forEach((btn) => {
btn.style.color = "black";
btn.style.background = "var(--Light-blue)";
btn.style.border = "var(--Light-blue)";
});
}
function delayThree() {
BtnThree.forEach((btn) => {
btn.style.color = "black";
btn.style.background = "var(--Light-blue)";
btn.style.border = "var(--Light-blue)";
});
}
function delayFour() {
BtnFour.forEach((btn) => {
btn.style.color = "black";
btn.style.background = "var(--Light-blue)";
btn.style.border = "2px solid var(--Light-blue)";
});
}
const timeout = setTimeout(delay, 1000);
const timeoutTwo = setTimeout(delayTwo, 1000);
const timeoutThree = setTimeout(delayThree, 1000);
const timeoutFour = setTimeout(delayFour, 1000);