-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
178 lines (152 loc) · 5.55 KB
/
Copy pathscript.js
File metadata and controls
178 lines (152 loc) · 5.55 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
// Smooth scroll for in-page links
document.querySelectorAll('a[href^="#"]').forEach((a) => {
a.addEventListener("click", (e) => {
const target = document.querySelector(a.getAttribute("href"));
if (!target) return;
e.preventDefault();
target.scrollIntoView({ behavior: "smooth", block: "start" });
});
});
// Open modal
function openModal(modalId) {
const modal = document.getElementById(modalId);
if (!modal) return;
modal.setAttribute("aria-hidden", "false");
document.body.style.overflow = "hidden";
}
// Close modal + stop media (YouTube/video)
function closeModal(modal) {
if (!modal) return;
modal.setAttribute("aria-hidden", "true");
document.body.style.overflow = "";
modal.querySelectorAll("video").forEach((v) => {
v.pause();
v.currentTime = 0;
});
modal.querySelectorAll("iframe").forEach((frame) => {
const src = frame.getAttribute("src");
frame.setAttribute("src", src);
});
}
// Click handlers for project cards
document.querySelectorAll("[data-modal]").forEach((btn) => {
btn.addEventListener("click", () => openModal(btn.dataset.modal));
});
// Close handlers
document.querySelectorAll(".modal [data-close]").forEach((btn) => {
btn.addEventListener("click", () => closeModal(btn.closest(".modal")));
});
// Click outside modal box closes it
document.querySelectorAll(".modal").forEach((modal) => {
modal.addEventListener("click", (e) => {
if (e.target === modal) closeModal(modal);
});
});
// ESC closes any open modal
window.addEventListener("keydown", (e) => {
if (e.key !== "Escape") return;
document.querySelectorAll(".modal[aria-hidden='false']").forEach((m) => closeModal(m));
});
// Scroll reveal animation
const revealObserver = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add("is-visible");
revealObserver.unobserve(entry.target);
}
});
},
{ threshold: 0.16 }
);
document.querySelectorAll(".section-reveal").forEach((el) => revealObserver.observe(el));
// Active nav link based on current section
const sections = Array.from(document.querySelectorAll("section[id]"));
const navLinks = Array.from(document.querySelectorAll(".links a"));
const sectionObserver = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (!entry.isIntersecting) return;
const id = entry.target.getAttribute("id");
navLinks.forEach((link) => {
link.classList.toggle("active", link.getAttribute("href") === `#${id}`);
});
});
},
{
rootMargin: "-35% 0px -50% 0px",
threshold: 0.1,
}
);
sections.forEach((section) => sectionObserver.observe(section));
// Hero particles and subtle parallax motion
const heroParticles = document.getElementById("bg-dots");
const prefersReducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
if (heroParticles && !prefersReducedMotion) {
const dotCount = window.innerWidth < 640 ? 36 : 64;
const colors = ["rgba(216,161,59,0.9)", "rgba(134,176,160,0.85)", "rgba(196,74,59,0.8)", "rgba(239,233,223,0.7)"];
for (let i = 0; i < dotCount; i += 1) {
const dot = document.createElement("span");
dot.className = "particle";
const size = Math.random() * 4 + 1.5;
const duration = Math.random() * 12 + 11;
const delay = Math.random() * -duration;
dot.style.left = `${Math.random() * 100}%`;
dot.style.top = `${Math.random() * 100}%`;
dot.style.width = `${size}px`;
dot.style.height = `${size}px`;
dot.style.background = colors[Math.floor(Math.random() * colors.length)];
dot.style.animationDuration = `${duration}s`;
dot.style.animationDelay = `${delay}s`;
dot.style.setProperty("--drift", `${(Math.random() - 0.5) * 42}px`);
heroParticles.appendChild(dot);
}
}
// Contact form AJAX submit (no redirect page)
const contactForm = document.getElementById("contact-form");
const statusEl = document.getElementById("form-status");
const submitBtn = document.getElementById("contact-submit");
if (contactForm) {
const FORM_ENDPOINT = "/api/contact";
contactForm.addEventListener("submit", async (e) => {
e.preventDefault();
const email = document.getElementById("contact-email")?.value.trim() || "";
const message = document.getElementById("contact-message")?.value.trim() || "";
if (!email || !message) {
if (statusEl) statusEl.textContent = "Please fill in your email and message.";
return;
}
if (submitBtn) submitBtn.disabled = true;
if (statusEl) statusEl.textContent = "Sending...";
try {
const res = await fetch(FORM_ENDPOINT, {
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify({
email,
message,
_subject: "New Portfolio Contact Form Message",
_template: "table",
_captcha: "false",
}),
});
const data = await res.json();
if (res.ok && data?.success === true) {
if (statusEl) statusEl.textContent = "Message sent. Thanks for reaching out.";
contactForm.reset();
} else {
if (statusEl) statusEl.textContent = data?.message || "Could not send right now. Please email me directly at ignanaseelan04@gmail.com.";
throw new Error("Submit failed");
}
} catch (err) {
if (statusEl) {
statusEl.textContent = "Could not send right now. Please email me directly at ignanaseelan04@gmail.com.";
}
} finally {
if (submitBtn) submitBtn.disabled = false;
}
});
}