-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
98 lines (83 loc) · 2.7 KB
/
Copy pathscript.js
File metadata and controls
98 lines (83 loc) · 2.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
window.addEventListener("DOMContentLoaded", () => {
const form = document.querySelector(".form-main");
const formInputs = document.querySelectorAll(".form-inputs");
const formInputsArr = Array.from(formInputs);
const sendFormBtn = document.getElementById("send-form-button");
let hideModalTimeout;
// Form
sendFormBtn.addEventListener("click", (element) => {
element.preventDefault();
const requiredInputs = formInputsArr.some((element) => element.value === "");
if (requiredInputs) {
formInputsArr.forEach((element) => {
if (element.value === "") {
element.classList.add("error");
element.classList.remove("no-border");
}
setTimeout(() => {
element.classList.add("no-border");
element.classList.remove("error");
}, 3000);
});
} else {
showModal();
hideModalTimeout = setTimeout(() => {
closeModal();
}, 5000);
}
});
// Modal
const modalWindow = document.querySelector(".modal-window"),
modalWindowBtn = document.querySelector(".modal-window-main-btn");
modalWindowBtn.addEventListener("click", (element) => {
element.preventDefault();
closeModal();
});
document.addEventListener("keydown", (event) => {
if (event.code === "Escape" && modalWindow.classList.contains("show")) {
closeModal();
}
});
function showModal() {
modalWindow.classList.add("show");
modalWindow.classList.remove("hide");
document.body.style.overflow = "hidden";
form.reset();
}
function closeModal() {
modalWindow.classList.add("hide");
modalWindow.classList.remove("show");
clearTimeout(hideModalTimeout);
document.body.style.overflow = "";
}
// Language switcher
const languageBlock = document.querySelector(".language-switcher-block"),
languages = languageBlock.querySelectorAll(".language-switcher-block-element");
window.addEventListener("click", (e) => {
if (!e.target.classList.contains("fas")) {
languageBlock.classList.remove("show");
} else {
languageBlock.classList.toggle("show");
}
});
window.addEventListener("scroll", () => {
languageBlock.classList.remove("show");
});
languages.forEach((item) => {
item.addEventListener("click", (e) => {
if (e.target.textContent === "Английский" || e.target.textContent === "English") {
if (location.href !== "https://qkston.github.io/english.html") {
location.href = "https://qkston.github.io/english.html";
} else {
languageBlock.classList.remove("show");
}
} else if (e.target.textContent === "Українська" || e.target.textContent === "Ukrainian") {
if (location.href !== "https://qkston.github.io/") {
location.href = "https://qkston.github.io/";
} else {
languageBlock.classList.remove("show");
}
}
});
});
});