-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
130 lines (115 loc) · 3.79 KB
/
script.js
File metadata and controls
130 lines (115 loc) · 3.79 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
// YEAR FOOTER
document.addEventListener("DOMContentLoaded", () => {
const yearSpan = document.getElementById("year");
if (yearSpan) {
yearSpan.textContent = new Date().getFullYear();
}
// CONTACT FORM SUBMIT
const contactForm = document.getElementById("contact-form");
if (contactForm) {
const statusEl = document.getElementById("contact-status");
contactForm.addEventListener("submit", async (e) => {
e.preventDefault();
const name = document.getElementById("name").value.trim();
const email = document.getElementById("email").value.trim();
const message = document.getElementById("message").value.trim();
if (!name || !email || !message) {
if (statusEl) {
statusEl.textContent = "Fill in all fields before submitting.";
statusEl.className = "form-status error";
}
return;
}
if (statusEl) {
statusEl.textContent = "Sending...";
statusEl.className = "form-status pending";
}
try {
const res = await fetch(contactForm.action, {
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify({ name, email, message }),
});
if (res.ok) {
if (statusEl) {
statusEl.textContent =
"Message sent, I will reply as soon as possible.";
statusEl.className = "form-status success";
}
contactForm.reset();
} else {
let data = {};
try {
data = await res.json();
} catch (_) {}
if (statusEl) {
statusEl.textContent =
data.error || "Something went wrong. Please try again.";
statusEl.className = "form-status error";
}
}
} catch (err) {
console.error(err);
if (statusEl) {
statusEl.textContent =
"Network error. Check your connection and try again.";
statusEl.className = "form-status error";
}
}
});
}
// MOBILE NAV TOGGLE
const navToggle = document.querySelector(".nav-toggle");
const navLinks = document.querySelector(".nav-links");
if (navToggle && navLinks) {
navToggle.addEventListener("click", () => {
navLinks.classList.toggle("open");
});
navLinks.querySelectorAll("a").forEach((link) => {
link.addEventListener("click", () => {
navLinks.classList.remove("open");
});
});
}
// FADE UP ON SCROLL
const fadeEls = document.querySelectorAll(".fade-up");
if ("IntersectionObserver" in window && fadeEls.length) {
const observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add("visible");
observer.unobserve(entry.target);
}
});
},
{ threshold: 0.18 }
);
fadeEls.forEach((el) => observer.observe(el));
} else {
fadeEls.forEach((el) => el.classList.add("visible"));
}
// WORKS FILTERS
const filterChips = document.querySelectorAll(".filter-chip");
const workCards = document.querySelectorAll(".works-grid .work-card");
if (filterChips.length && workCards.length) {
filterChips.forEach((chip) => {
chip.addEventListener("click", () => {
const type = chip.getAttribute("data-filter");
filterChips.forEach((c) => c.classList.remove("active"));
chip.classList.add("active");
workCards.forEach((card) => {
const cardType = card.getAttribute("data-type");
if (type === "all" || type === cardType) {
card.style.display = "";
} else {
card.style.display = "none";
}
});
});
});
}
});