-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
273 lines (230 loc) · 8.27 KB
/
Copy pathscript.js
File metadata and controls
273 lines (230 loc) · 8.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
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
document.addEventListener("DOMContentLoaded", () => {
const menuToggle = document.querySelector(".menu-toggle");
const navLinks = document.querySelector(".nav-links");
menuToggle.addEventListener("click", () => {
navLinks.classList.toggle("active");
const icon = menuToggle.querySelector("i");
if (navLinks.classList.contains("active")) {
icon.classList.remove("fa-bars");
icon.classList.add("fa-times");
} else {
icon.classList.remove("fa-times");
icon.classList.add("fa-bars");
}
});
(function () {
const el = document.getElementById("brand");
const text = el.dataset.text || "DevSpire";
let i = 0;
let isDeleting = false;
const typeSpeed = 100; // typing speed (ms)
const deleteSpeed = 50; // deleting speed (ms)
const pauseTime = 2000; // pause at end before deleting (ms)
const restartPause = 500; // pause before restarting (ms)
function typeLoop() {
const currentText = text.slice(0, i);
el.textContent = currentText;
if (!isDeleting && i < text.length) {
// Typing forward
i++;
setTimeout(typeLoop, typeSpeed);
} else if (!isDeleting && i === text.length) {
// Finished typing, pause then start deleting
isDeleting = true;
setTimeout(typeLoop, pauseTime);
} else if (isDeleting && i > 0) {
// Deleting
i--;
setTimeout(typeLoop, deleteSpeed);
} else if (isDeleting && i === 0) {
// Finished deleting, restart
isDeleting = false;
setTimeout(typeLoop, restartPause);
}
}
typeLoop();
})();
// Project filtering logic
// Project filtering logic
const tabButtons = document.querySelectorAll('.tab-button');
const projectCards = document.querySelectorAll('.project-card');
const languageMap = {
'HTML CSS': ['html', 'css'],
'JavaScript': ['html', 'css', 'javascript'],
'Python': ['python', 'pygame'],
'C': ['c'],
'C++': ['cpp'],
'all': []
};
function filterProjects(selectedLanguage) {
const languagesToShow = languageMap[selectedLanguage];
let visibleCount = 0;
projectCards.forEach(card => {
let shouldShow = false;
if (selectedLanguage === 'all') {
shouldShow = true;
} else {
// Check if card has any of the required language classes
shouldShow = languagesToShow.some(lang => card.classList.contains(lang));
}
if (shouldShow) {
// Remove hidden-project class if present
card.classList.remove('hidden-project');
card.style.display = 'flex';
visibleCount++;
} else {
card.style.display = 'none';
}
});
console.log(`Visible cards for ${selectedLanguage}: ${visibleCount}`);
}
if (tabButtons.length > 0 && projectCards.length > 0) {
tabButtons.forEach(button => {
button.addEventListener('click', (e) => {
e.preventDefault();
// Remove active class from all buttons
tabButtons.forEach(btn => btn.classList.remove('active'));
// Add active class to clicked button
button.classList.add('active');
// Get selected language
const selectedLanguage = button.getAttribute('data-lang');
// Filter projects
filterProjects(selectedLanguage);
console.log(`Filtered projects by: ${selectedLanguage}`);
});
});
// Set initial filter on page load
const activeTab = document.querySelector('tab-button.active');
if (activeTab) {
const initialLanguage = activeTab.getAttribute('data-lang');
filterProjects(initialLanguage);
}
}
function setupViewAllToggle(buttonId, hiddenClassName, showClass, initialButtonText, toggleButtonText) {
const viewAllBtn = document.getElementById(buttonId);
if (!viewAllBtn) return;
const hiddenCards = document.querySelectorAll(`.${hiddenClassName}`);
let allCardsVisible = false; // Toggle the state
viewAllBtn.textContent = initialButtonText;
viewAllBtn.addEventListener("click", () => {
if (!allCardsVisible) {
hiddenCards.forEach(card => {
card.classList.remove(hiddenClassName);
card.classList.add(showClass);
})
viewAllBtn.textContent = toggleButtonText;
} else {
hiddenCards.forEach(card => {
card.classList.remove(showClass);
card.classList.add(hiddenClassName);
})
viewAllBtn.textContent = initialButtonText;
}
allCardsVisible = !allCardsVisible; // Toggle the state
});
}
setupViewAllToggle(
'view-all-btn-projects',
'hidden-project', // Pass only the class name 'hidden-project'
'show-project',
'View All',
'Show Less'
);
setupViewAllToggle(
'view-all-btn-programming',
'hidden-programming', // Pass only the class name 'hidden-programming'
'show-programming',
'View All',
'Show Less'
);
setupViewAllToggle(
'view-all-btn-hacking-series',
'hidden-hacking', // Pass only the class name 'hidden-project'
'show-hacking',
'View All',
'Show Less'
);
setupViewAllToggle(
'view-all-btn-hacking-tutorial',
'hidden-hacking-tutorial', // Pass only the class name 'hidden-project'
'show-hacking-tutorial',
'View All',
'Show Less'
);
setupViewAllToggle(
'view-all-btn-networking',
'hidden-networking', // Pass only the class name 'hidden-project'
'show-networking',
'View All',
'Show Less'
);
setupViewAllToggle(
'view-all-btn-automation-tutorial',
'hidden-automation-tutorial', // Pass only the class name 'hidden-project'
'show-automation-tutorial',
'View All',
'Show Less'
);
setupViewAllToggle(
'view-all-btn-automation-project',
'hidden-automation-project', // Pass only the class name 'hidden-project'
'show-automation-project',
'View All',
'Show Less'
);
setupViewAllToggle(
'view-all-btn-guide-link',
'hidden-card-cheat', // Pass only the class name 'hidden-project'
'show-card-cheat',
'View All',
'Show Less'
);
// --- Scroll to top with progress indicator ---
const scrollBtn = document.getElementById("scrollUpBtn");
if (scrollBtn) {
const circle = scrollBtn.querySelector(".progress-circle .progress");
// The radius of the circle in the SVG is 15.9155.
const circumference = 2 * Math.PI * 15.9155;
if (circle) {
// Set initial dash array and offset
circle.style.strokeDasharray = `${circumference}`;
circle.style.strokeDashoffset = `${circumference}`;
}
window.addEventListener("scroll", () => {
const scrollTop = window.scrollY;
const docHeight = document.documentElement.scrollHeight - window.innerHeight;
const scrollPercent = docHeight > 0 ? scrollTop / docHeight : 0;
// Animate progress circle
if (circle) {
const offset = circumference * (1 - scrollPercent);
circle.style.strokeDashoffset = offset;
}
// Show/hide button
scrollBtn.style.display = scrollTop > 100 ? "block" : "none";
});
scrollBtn.addEventListener("click", () => {
window.scrollTo({
top: 0,
behavior: "smooth"
});
});
}
});
document.addEventListener("click", (e) => {
const btn = e.target.closest(".download-btn");
if (!btn) return;
const filePath = btn.dataset.file;
if (!filePath) {
console.error("Download failed: no file path defined.");
return;
}
downloadFile(filePath);
});
function downloadFile(filePath) {
const link = document.createElement("a");
link.href = filePath;
link.download = filePath.split("/").pop();
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}