-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
108 lines (92 loc) · 3.27 KB
/
Copy pathscript.js
File metadata and controls
108 lines (92 loc) · 3.27 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
document.addEventListener("DOMContentLoaded", () => {
// Set current year in footer
const yearSpan = document.getElementById("current-year");
if (yearSpan) {
yearSpan.textContent = new Date().getFullYear();
}
// Smooth scrolling for anchor links
document.querySelectorAll('a[href^="#"]').forEach((anchor) => {
anchor.addEventListener("click", function (e) {
e.preventDefault();
const targetId = this.getAttribute("href");
if (targetId === "#") {
window.scrollTo({
top: 0,
behavior: "smooth",
});
return;
}
const targetElement = document.querySelector(targetId);
if (targetElement) {
targetElement.scrollIntoView({
behavior: "smooth",
block: "start",
});
}
});
});
// Simple intersection observer for fade-in animation on scroll
const observerOptions = {
threshold: 0.1,
};
const observer = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.style.opacity = "1";
entry.target.style.transform = "translateY(0)";
observer.unobserve(entry.target);
}
});
}, observerOptions);
// Add animation classes to elements
const animatedElements = document.querySelectorAll(
".card, .project-card, .section-title, .hero-title, .hero-subtitle"
);
animatedElements.forEach((el) => {
el.style.opacity = "0";
el.style.transform = "translateY(20px)";
el.style.transition = "opacity 0.6s ease-out, transform 0.6s ease-out";
observer.observe(el);
});
// Contact form handling
const contactForm = document.getElementById("contactForm");
if (contactForm) {
contactForm.addEventListener("submit", async (e) => {
e.preventDefault();
// 1. Spam Protection (Honeypot)
const honeypot = document.getElementById("website");
if (honeypot && honeypot.value) {
console.log("Bot detected");
return; // Silently fail for bots
}
const btn = contactForm.querySelector("button");
const originalText = btn.textContent;
// 2. UI Feedback
btn.textContent = "Sending...";
btn.disabled = true;
// 3. Data Preparation
const formData = new FormData(contactForm);
const data = Object.fromEntries(formData.entries());
delete data.website; // Remove honeypot from data
try {
// TODO: Replace with your actual backend endpoint
const response = await fetch("https://formspree.io/f/xanrbaee", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(data),
});
if (!response.ok) throw new Error("Network response was not ok");
// Simulate success for now
await new Promise((resolve) => setTimeout(resolve, 1500));
alert("Thank you for your message! We will get back to you soon.");
contactForm.reset();
} catch (error) {
console.error("Error:", error);
alert("Something went wrong. Please try again later.");
} finally {
btn.textContent = originalText;
btn.disabled = false;
}
});
}
});