-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
133 lines (104 loc) · 3.53 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
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
let priceRange = document.getElementById("range");
let thumb = document.getElementById("selector");
let sliderTrack = document.getElementsByClassName("slider-track")[0];
let check = document.getElementById("check");
let trailBtn = document.getElementById("trail");
let modal = document.getElementsByClassName("modal-form")[0];
let sliderImage = document.getElementsByClassName("thumb")[0];
let closeBtn = document.getElementsByClassName("close")[0];
let submitBtn = document.getElementsByClassName("btnForm")[0];
let yearly = false;
let lastSliderValue = 0;
priceRange.addEventListener("change", changeValue);
function changeValue() {
console.log(this.value);
this.value = this.value || lastSliderValue;
lastSliderValue = this.value;
thumb.style.left = this.value + "%";
sliderTrack.style.width = this.value + "%";
let [traffic, rate] = getMonthlyPrice(this.value);
if (yearly) {
rate = getYearlyPrice(rate);
}
document.getElementById("views").innerHTML = traffic;
document.getElementById("price").innerHTML = rate;
}
check.addEventListener("change", calculateYearlyPrice);
function calculateYearlyPrice() {
// console.log(check.checked);
let discountText = document.getElementById("discount");
if (!check.checked) {
discountText.style.display = "none";
document.getElementById("subtext").innerHTML = "/month";
}
yearly = check.checked;
changeValue();
}
const getMonthlyPrice = (value) => {
if (value == 0 || value <= 24) {
return ["10k", 8];
} else if (value == 25 || value <= 49) {
return ["50k", 12];
} else if (value == 50 || value <= 74) {
return ["100k", 16];
} else if (value == 75 || value <= 99) {
return ["500k", 24];
} else if (value == 100) {
return ["1M", 36];
}
};
const getYearlyPrice = (price) => {
let discountText = document.getElementById("discount");
let yearlyPrice = price * 12;
let discount = (yearlyPrice / 100) * 25;
let discountedPrice = yearlyPrice - discount;
document.getElementById("price").innerHTML = discountedPrice;
document.getElementById("subtext").innerHTML = "/year";
discountText.style.display = "flex";
return discountedPrice;
};
trailBtn.addEventListener("click", startTrail);
function startTrail() {
modal.style.display = "block";
sliderImage.style.display = "none";
}
closeBtn.addEventListener("click", closeModal);
function closeModal() {
modal.style.display = "none";
sliderImage.style.display = "block";
}
window.addEventListener("click", outsideClick);
function outsideClick(e) {
if (e.target == modal) {
modal.style.display = "none";
sliderImage.style.display = "block";
}
}
submitBtn.addEventListener("click", submitForm);
let full_name = document.getElementById("fname");
let company_name = document.getElementById("company");
let email = document.getElementById("emailAddress");
let phone_number = document.getElementById("phone");
function submitForm(e) {
e.preventDefault();
let full_nameValue = document.getElementById("fname").value;
let company_nameValue = document.getElementById("company").value;
let emailValue = document.getElementById("emailAddress").value;
let phone_numberValue = document.getElementById("phone").value;
if (
full_nameValue == "" ||
company_nameValue == "" ||
emailValue == "" ||
phone_numberValue == ""
) {
alertify.alert("Please, fill all fields to continue");
return;
} else {
alertify.alert("A link has been sent to your mail");
}
full_name.value = "";
company_name.value = "";
email.value = "";
phone_number.value = "";
closeModal();
}