-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
134 lines (101 loc) · 3.35 KB
/
Copy pathscript.js
File metadata and controls
134 lines (101 loc) · 3.35 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
const cards = document.querySelectorAll(".project-card");
const prevBtn = document.querySelector(".carousel-btn.prev");
const nextBtn = document.querySelector(".carousel-btn.next");
const dotsBox = document.querySelector(".carousel-dots");
let currentIndex = 0;
let autoSlide;
cards.forEach((card, index) => {
const dot = document.createElement("button");
dot.setAttribute("aria-label", `Show project ${index + 1}`);
dot.addEventListener("click", () => {
showSlide(index);
restartAutoSlide();
});
dotsBox.appendChild(dot);
});
const dots = document.querySelectorAll(".carousel-dots button");
function showSlide(index) {
currentIndex = (index + cards.length) % cards.length;
const prevIndex = (currentIndex - 1 + cards.length) % cards.length;
const nextIndex = (currentIndex + 1) % cards.length;
cards.forEach((card, i) => {
card.classList.remove("active", "prev", "next");
if (i === currentIndex) {
card.classList.add("active");
}
if (i === prevIndex) {
card.classList.add("prev");
}
if (i === nextIndex) {
card.classList.add("next");
}
});
dots.forEach((dot, i) => {
dot.classList.toggle("active", i === currentIndex);
});
}
function nextSlide() {
showSlide(currentIndex + 1);
}
function prevSlide() {
showSlide(currentIndex - 1);
}
function startAutoSlide() {
autoSlide = setInterval(nextSlide, 10000);
}
function restartAutoSlide() {
clearInterval(autoSlide);
startAutoSlide();
}
nextBtn.addEventListener("click", () => {
nextSlide();
restartAutoSlide();
});
prevBtn.addEventListener("click", () => {
prevSlide();
restartAutoSlide();
});
showSlide(currentIndex);
startAutoSlide();
const themeToggle = document.querySelector("#themeToggle");
const themeToggleLabel = themeToggle?.querySelector(".theme-toggle-label");
const savedTheme = localStorage.getItem("theme");
function setTheme(isDark) {
document.body.classList.toggle("dark-mode", isDark);
if (themeToggle) {
themeToggle.setAttribute("aria-pressed", String(isDark));
themeToggle.setAttribute("aria-label", isDark ? "Switch to light mode" : "Switch to dark mode");
}
if (themeToggleLabel) {
themeToggleLabel.textContent = isDark ? "Light Mode" : "Dark Mode";
}
}
setTheme(savedTheme === "dark");
if (themeToggle) {
themeToggle.addEventListener("click", () => {
const isDark = !document.body.classList.contains("dark-mode");
setTheme(isDark);
localStorage.setItem("theme", isDark ? "dark" : "light");
});
}
const contactForm = document.querySelector("#contactForm");
if (contactForm) {
contactForm.addEventListener("submit", (event) => {
event.preventDefault();
const data = new FormData(contactForm);
const fallbackEmail = "hello@example.com";
const to = String(data.get("to") || fallbackEmail).trim() || fallbackEmail;
const cc = String(data.get("cc") || "").trim();
const subject = String(data.get("subject") || "Portfolio contact").trim() || "Portfolio contact";
const from = String(data.get("from") || "").trim();
const message = String(data.get("message") || "").trim();
const body = [`From: ${from}`, "", message].join("\n");
const params = new URLSearchParams();
if (cc) {
params.set("cc", cc);
}
params.set("subject", subject);
params.set("body", body);
window.location.href = `mailto:${to}?${params.toString()}`;
});
}