-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
93 lines (80 loc) · 2.67 KB
/
Copy pathmain.js
File metadata and controls
93 lines (80 loc) · 2.67 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
function mobileMenu() {
const navbar = document.getElementById("mobile-nav-link");
const navbarClasses = navbar.className.split(" ");
if (navbarClasses.includes("closed")) {
const newObj = navbarClasses.filter((el) => el !== "closed");
newObj.push("opened");
navbar.className = newObj.join(" ");
} else if (navbarClasses.includes("opened")) {
const newObj = navbarClasses.filter((el) => el !== "opened");
newObj.push("closed");
navbar.className = newObj.join(" ");
}
}
document
.querySelector(".mobile-humburger-menu")
.addEventListener("click", mobileMenu);
document.querySelectorAll(".close").forEach((closer) => {
closer.addEventListener("click", mobileMenu);
});
const form = document.getElementById("contact-me-form");
emailjs.init({
publicKey: "8yDA8xqgWyprQp-74",
});
form.addEventListener("submit", async (e) => {
e.preventDefault();
const formData = new FormData(form);
const formObject = {};
formData.forEach((value, key) => {
if (formObject[key]) {
if (!Array.isArray(formObject[key])) {
formObject[key] = [formObject[key]];
}
formObject[key].push(value);
} else {
formObject[key] = value;
}
});
document.querySelector(".form-submit-btn").style.display = "none";
document.querySelector(".form-loading-btn").style.display = "inline-block";
await emailjs
.send("service_glpg8gl", "template_c66aeqk", formObject)
.then((response) => {
if (response?.status === 200) {
if (
window.location.pathname === "/" ||
window.location.pathname === ""
) {
window.location.search = "";
window.location.hash = "";
window.location.pathname = "/thanks";
} else if (window.location.pathname.includes("index.html")) {
window.location.search = "";
window.location.hash = "";
window.location.pathname = window.location.pathname.replace(
"index.html",
"thanks"
);
} else if (window.location.pathname.startsWith("/")) {
const pathArr = window.location.pathname.split("/").filter((el) => {
if (el === "") {
return false;
} else if (el === "/") {
return false;
} else if (el.startsWith("#")) {
return false;
} else if (el.startsWith("?")) {
return false;
} else {
return true;
}
});
pathArr.unshift("");
pathArr.push("thanks");
window.location.search = "";
window.location.hash = "";
window.location.pathname = pathArr.join("/");
}
}
});
});