-
-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathcustom.js
More file actions
255 lines (241 loc) · 8.7 KB
/
Copy pathcustom.js
File metadata and controls
255 lines (241 loc) · 8.7 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
254
255
const _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"]);
const ready = (callback) => {
if (document.readyState !== "loading") {
callback();
} else {
document.addEventListener("DOMContentLoaded", callback);
}
};
/* Actual table switching logic */
function switchTabs(removal, enable) {
for (const child of document.querySelectorAll(removal)) {
child.classList.remove("current");
}
document.getElementById(enable).classList.add("current");
}
/* Generic tab toggling code */
function tabToggle(targets, removal) {
for (const element of document.querySelectorAll(targets)) {
element.addEventListener("click", (e) => {
const 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) => {
const thisParent = e.target.parentElement;
const thisNext = e.target.nextElementSibling;
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 */
for (const element of document.querySelectorAll("#dedicated-checkbox")) {
element.addEventListener("change", (e) => {
const 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");
});
}
for (const element of document.querySelectorAll(".dedicated-toggle")) {
element.addEventListener("click", (e) => {
const target = document.getElementById("dedicated-checkbox");
target.checked = element.classList.contains("dedicated-enable");
target.dispatchEvent(new Event("change"));
});
}
/* Donate rewards selection */
const donate_input = document.getElementById("donate-amount");
if (donate_input) {
for (const element of document.querySelectorAll(".rewards .choose")) {
element.addEventListener("click", (e) => {
const container = e.target.parentElement;
container.parentElement
.querySelector(".reward.checked")
.classList.remove("checked");
container.classList.add("checked");
container.querySelector("input").checked = true;
e.preventDefault();
});
}
for (const element of document.querySelectorAll(".rewards .close")) {
element.addEventListener("click", (e) => {
document
.querySelector(".rewards .fourth .choose")
.dispatchEvent(new Event("click"));
e.preventDefault();
});
}
donate_input.addEventListener("change", (e) => {
const amount = Number.parseInt(e.target.value);
let found = 0;
let highest = document.querySelector(".rewards .fourth");
let highest_amount = Number.parseInt(highest.getAttribute("data-amount"));
for (const element of document.querySelectorAll(".reward")) {
const current_amount = Number.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");
}
});
donate_input.dispatchEvent(new Event("change"));
}
/* VAT form */
const vat_input = document.getElementById("id_vat_0");
if (vat_input) {
vat_input.addEventListener("change", (e) => {
const value = e.target.value;
if (value !== "") {
document.querySelector(
`#id_country·option[value="${value}"]`,
).selected = true;
}
});
for (const element of document.querySelectorAll("#id_vat_0,#id_vat_1")) {
element.addEventListener("focusout", (e) => {
const country = document.getElementById("id_vat_0").value;
const 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 && data.name !== "---") {
document.querySelector('input[name="name"]').value = data.name;
const parts = data.address.trim().split("\n");
document.querySelector('input[name="address"]').value =
parts[0];
if (parts.length > 2) {
document.querySelector('input[name="address_2"]').value =
parts[1];
}
const city_parts = parts[parts.length - 1].split(" ");
console.log(city_parts);
console.log(parts[parts.length - 1]);
if (city_parts.length > 1) {
document.querySelector('input[name="postcode"]').value =
city_parts[0];
document.querySelector('input[name="city"]').value =
city_parts.slice(1).join(" ");
} else {
document.querySelector('input[name="city"]').value =
city_parts[0];
}
}
})
.catch((error) => {
console.error("Error:", error);
});
}
});
}
}
const sso = document.getElementById("SSO_Login");
if (sso) {
sso.submit();
}
for (const element of document.querySelectorAll("[data-clipboard-text]")) {
element.addEventListener("click", (e) => {
navigator.clipboard
.writeText(e.target.getAttribute("data-clipboard-text"))
.then(() => {
e.preventDefault();
});
});
}
console.log(
"%cStop!",
"color: red; font-weight: bold; font-size: 50px; font-family: sans-serif; -webkit-text-stroke: 1px black;",
);
console.log(
"%cThis is a browser feature intended for developers. If someone told you to copy-paste something here, they are likely trying to compromise your Weblate account.",
"font-size: 20px; font-family: sans-serif",
);
console.log(
"%cSee https://en.wikipedia.org/wiki/Self-XSS for more information.",
"font-size: 20px; font-family: sans-serif",
);
});
if (typeof SimpleSlider === "function") {
new SimpleSlider(".page-slider", {
slidesPerView: {
850: 2,
1165: 3,
},
});
}