-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
99 lines (88 loc) · 3.4 KB
/
script.js
File metadata and controls
99 lines (88 loc) · 3.4 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
document.addEventListener("DOMContentLoaded", () => {
// Highlight Navigation Links
const currentPath = window.location.pathname.replace(/\/$/, ""); // Normalize path
const navLinks = document.querySelectorAll(".nav-link");
if (navLinks.length === 0) {
console.error("No nav links found. Ensure navbar.html is loaded first.");
}
navLinks.forEach((link) => {
const linkPath = link.getAttribute("href").replace(/\/$/, "");
if (link.id !== "sayHello" && linkPath === currentPath) {
link.classList.add("text-blue-950");
link.classList.remove("text-slate-400");
} else {
link.classList.add("text-slate-400");
link.classList.remove("text-blue-950");
}
});
// Animate on Scroll
const elements = document.querySelectorAll(".animate-on-scroll");
const observer = new IntersectionObserver(
(entries, observer) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add("opacity-100", "scale-100");
entry.target.classList.remove("opacity-0", "scale-90");
observer.unobserve(entry.target); // Stop observing once animated
}
});
},
{ threshold: 0.1 }
);
elements.forEach((el) => observer.observe(el));
// Copy Email
const sayHelloLink = document.getElementById("sayHello");
if (sayHelloLink) {
sayHelloLink.addEventListener("click", () => {
const email = "braden@bradenpate.com";
navigator.clipboard.writeText(email)
.then(() => {
sayHelloLink.textContent = "Email copied";
setTimeout(() => {
sayHelloLink.textContent = "Say hello";
}, 2000);
})
.catch((err) => {
console.error("Failed to copy email: ", err);
});
});
}
// Next Project Link
const projects = [
"agile.html",
"ef.html",
"makeshift.html",
"mendix-ai.html",
"mendix-cko25.html",
"mendix-refresh.html",
"wedding.html",
];
const currentProject = window.location.pathname.split("/").pop();
const currentIndex = projects.indexOf(currentProject);
// Proceed only if a placeholder is present and the current project is valid
const placeholder = document.getElementById("next-project-placeholder");
if (placeholder && currentIndex !== -1) {
const nextIndex = (currentIndex + 1) % projects.length; // Loop back to the first project
const nextProject = projects[nextIndex];
const projectTitle = nextProject.replace(".html", "");
// Fetch the HTML template
fetch("../next-project.html")
.then((response) => response.text())
.then((template) => {
// Create a temporary element to parse the template
const tempDiv = document.createElement("div");
tempDiv.innerHTML = template;
// Update the placeholders
const container = tempDiv.querySelector("#next-project-container");
const thumbnail = container.querySelector("#next-project-thumbnail");
const link = container.querySelector("#next-project-link");
thumbnail.src = `../images/work/${projectTitle}/thumbnail.png`;
thumbnail.alt = `${projectTitle} Thumbnail`;
link.href = `../work/${nextProject}`;
link.textContent = `Next Project →`;
// Append the updated template to the placeholder
placeholder.appendChild(container);
})
.catch((error) => console.error("Failed to load next-project.html:", error));
}
});