-
-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathcustom.js
More file actions
213 lines (200 loc) · 7.18 KB
/
Copy pathcustom.js
File metadata and controls
213 lines (200 loc) · 7.18 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
var _paq = window._paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(["disableCookies"]);
_paq.push(["trackPageView"]);
_paq.push(["enableLinkTracking"]);
_paq.push(["setTrackerUrl", "https://stats.cihar.com/matomo.php"]);
_paq.push(["setSiteId", "12"]);
var ready = (callback) => {
if (document.readyState != "loading") {
callback();
} else {
document.addEventListener("DOMContentLoaded", callback);
}
};
/* Actual table switching logic */
function switchTabs(removal, enable) {
document.querySelectorAll(removal).forEach((child) => {
child.classList.remove("current");
});
document.getElementById(enable).classList.add("current");
}
/* Generic tab toggling code */
function tabToggle(targets, removal) {
document.querySelectorAll(targets).forEach((element) => {
element.addEventListener("click", (e) => {
let tab = e.target.getAttribute("data-tab");
switchTabs(removal, tab);
e.target.classList.add("current");
if (tab === "monthly") {
document.getElementById("dedicated-checkbox").checked = false;
}
});
});
}
ready(() => {
/* Mobile menu display */
document.querySelector(".menu-show").addEventListener("click", (e) => {
document.querySelector("body").classList.toggle("open-mobile");
document.querySelector(".mobile-menu").classList.toggle("is-visible");
e.preventDefault();
});
/* Languages menu */
document.querySelector(".open-langs").addEventListener("click", (e) => {
console.log(e);
var thisParent = e.target.parentElement;
var thisNext = e.target.nextElementSibling;
console.log(thisNext);
if (thisParent.classList.contains("opened")) {
thisParent.classList.remove("opened");
thisNext.style.opacity = "0";
setTimeout(() => {
thisNext.classList.toggle("is-visible");
thisNext.style.opacity = null;
}, 350);
} else {
thisNext.style.display = "block";
thisParent.classList.add("opened");
setTimeout(() => {
thisNext.classList.toggle("is-visible");
thisNext.style.display = null;
}, 20);
}
e.preventDefault();
});
/* Pricing tabs */
tabToggle("ul.pricing-tabs li", "ul.pricing-tabs li, .tab-content");
/* Yearly/monthly toggle */
tabToggle(
".pricing-table-tabs-menu ul li",
".pricing-table-tabs-menu ul li, .tab-content"
);
/* Dedicated hosting toggle */
document.querySelectorAll("#dedicated-checkbox").forEach((element) => {
element.addEventListener("change", (e) => {
let yearly_pricing = document.getElementById("yearly-pricing");
if (e.target.checked) {
yearly_pricing.dispatchEvent(new Event("click"));
switchTabs(".pricing-table-tabs-menu ul li, .tab-content", "dedicated");
} else {
switchTabs(".pricing-table-tabs-menu ul li, .tab-content", "yearly");
}
yearly_pricing.classList.add("current");
});
});
document.querySelectorAll(".dedicated-toggle").forEach((element) => {
console.log(element);
element.addEventListener("click", (e) => {
let target = document.getElementById("dedicated-checkbox");
target.checked = element.classList.contains("dedicated-enable");
target.dispatchEvent(new Event("change"));
});
});
/* Donate rewards selection */
let donate_input = document.getElementById("donate-amount");
if (donate_input) {
document.querySelectorAll(".rewards .choose").forEach((element) => {
element.addEventListener("click", (e) => {
var container = e.target.parentElement;
container.parentElement
.querySelector(".reward.checked")
.classList.remove("checked");
container.classList.add("checked");
container.querySelector("input").checked = true;
e.preventDefault();
});
});
document.querySelectorAll(".rewards .close").forEach((element) => {
element.addEventListener("click", (e) => {
document
.querySelector(".rewards .fourth .choose")
.dispatchEvent(new Event("click"));
e.preventDefault();
});
});
donate_input.addEventListener("change", (e) => {
var amount = parseInt(e.target.value);
var found = 0;
var highest = document.querySelector(".rewards .fourth");
var highest_amount = parseInt(highest.getAttribute("data-amount"));
document.querySelectorAll(".reward").forEach((element) => {
var current_amount = parseInt(element.getAttribute("data-amount"));
if (current_amount <= amount) {
element.classList.remove("small");
found++;
if (highest_amount < current_amount) {
highest = element;
highest_amount = current_amount;
}
} else {
element.classList.add("small");
if (element.classList.contains("checked")) {
element.querySelector(".close").dispatchEvent(new Event("click"));
}
}
});
highest.querySelector(".choose").click();
if (found > 1) {
document.querySelector(".whoa").classList.add("is-visible");
document.querySelector(".nowhoa").classList.remove("is-visible");
} else {
document.querySelector(".whoa").classList.remove("is-visible");
document.querySelector(".nowhoa").classList.add("is-visible");
}
console.log(amount);
});
donate_input.dispatchEvent(new Event("change"));
}
/* VAT form */
let vat_input = document.getElementById("id_vat_0");
if (vat_input) {
vat_input.addEventListener("change", (e) => {
var value = e.target.value;
if (value != "") {
document.querySelector(
'#id_country option[value="' + value + '"'
).selected = true;
}
});
document.querySelectorAll("#id_vat_0,#id_vat_1").forEach((element) => {
element.addEventListener("focusout", (e) => {
var country = document.getElementById("id_vat_0").value;
var code = document.getElementById("id_vat_1").value;
if (country && code) {
const payload = new FormData();
payload.append("vat", country + code);
payload.append(
"payment",
document.querySelector('input[name="payment"]').value
);
payload.append(
"csrfmiddlewaretoken",
document.querySelector('input[name="csrfmiddlewaretoken"]').value
);
fetch("/js/vat/", {
method: "POST",
body: payload,
})
.then((response) => response.json())
.then((data) => {
if (data.valid) {
document.querySelector('input[name="name"]').value = data.name;
var parts = data.address.trim().split("\n");
document.querySelector('input[name="address"]').value =
parts[0];
document.querySelector('input[name="city"]').value =
parts[parts.length - 1];
}
})
.catch((error) => {
console.error("Error:", error);
});
}
});
});
}
new ClipboardJS("[data-clipboard-text]");
});
function removeUser(userId) {
document.getElementById(`server_user_${userId}_form`).submit();
}