-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
95 lines (79 loc) · 2.84 KB
/
script.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
import { planToggle } from "./module/planPrice.js";
import {
BackToPlanSelection,
forwardNavigation,
backwardNavigation,
conclusionPage,
} from "./module/stepNav.js";
import { inputValidation } from "./module/formValidation.js";
import { planSelection } from "./module/plan-selection.js";
import { page3Selection } from "./module/add-ons.js";
const planSelectorBtn = document.querySelector(".toggle");
const nextBtn = document.querySelector("button.btn-next");
const backBtn = document.querySelector("button.btn-back");
const confirmBtn = document.querySelector("button.btn-confirm");
const changePlanBtn = document.querySelector("a.change-plan-btn");
const selectedPlan = document.querySelector("span.selected-plan");
const selectedPlanPrice = document.querySelector("p.selected-plan-price");
// const totalAmount = document.querySelector('span.total-amount');
// Select between monthly and yearly plan
planSelectorBtn.addEventListener("click", planToggle);
// navigate between pages
let index = 0;
nextBtn.addEventListener("click", () => {
if (!inputValidation()) return;
let isSelected = planSelection();
if (index === 1 && !isSelected) return;
forwardNavigation();
index++;
});
backBtn.addEventListener("click", backwardNavigation);
// display the conclusion page
confirmBtn.addEventListener("click", conclusionPage);
// Select an item from add-ons section
page3Selection();
changePlanBtn.addEventListener("click", () => {
BackToPlanSelection();
});
// Display selectedPlan in the summary page
const planSelector = document.querySelectorAll("li.plan");
planSelector.forEach((plan) => {
setInterval(() => {
if (plan.classList.contains("checked")) {
selectedPlan.innerHTML = plan.children[1].children[0].innerHTML;
selectedPlanPrice.innerHTML = plan.children[1].children[1].innerHTML;
}
}, 4000);
});
// step-2 plan selector
const plans = document.querySelectorAll("li.plan");
// step-3 plan selector
const addOns = document.querySelectorAll("li.item");
const totalAmount = document.querySelector("span.total-amount");
// Get the price of all the selected plans and add-ons and return the sum
let arr = [];
let sum;
const summaryTotalPrice = () => {
arr = [];
addOns.forEach((selectedAddOns) => {
if (selectedAddOns.classList.contains("checked")) {
let strAmount = selectedAddOns.children[1].children[0].innerHTML;
const matches = strAmount.match(/\d+/g);
arr.push(parseInt(matches[0]));
}
});
plans.forEach((selectedPlan) => {
if (selectedPlan.classList.contains("checked")) {
let strAmount = selectedPlan.children[1].children[1].innerHTML;
const matches = strAmount.match(/\d+/g);
arr.push(parseInt(matches[0]));
}
});
sum = arr.reduce((a, b) => a + b);
return sum;
};
setTimeout(() => {
setInterval(() => {
totalAmount.innerHTML = summaryTotalPrice();
}, 3000);
}, 9000);