-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathapp.js
More file actions
387 lines (329 loc) · 13.5 KB
/
app.js
File metadata and controls
387 lines (329 loc) · 13.5 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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
document.addEventListener('DOMContentLoaded', () => {
// Theme management
const themeToggle = document.getElementById('theme-toggle');
const body = document.body;
// Load saved theme or default to dark
const savedTheme = localStorage.getItem('theme') || 'dark';
body.setAttribute('data-theme', savedTheme);
themeToggle?.addEventListener('click', () => {
const currentTheme = body.getAttribute('data-theme') || 'light';
const newTheme = currentTheme === 'light' ? 'dark' : 'light';
body.setAttribute('data-theme', newTheme);
localStorage.setItem('theme', newTheme);
});
// Mobile menu toggle
const mobileMenuToggle = document.getElementById('mobile-menu-toggle');
const mainNav = document.querySelector('.main-nav');
mobileMenuToggle?.addEventListener('click', () => {
mainNav.classList.toggle('active');
mobileMenuToggle.classList.toggle('active');
});
// Navigation active state
const navLinks = document.querySelectorAll('.nav-link');
const sections = document.querySelectorAll('.section, .hero');
function updateActiveNav() {
const scrollPosition = window.scrollY + 100;
sections.forEach(section => {
const sectionTop = section.offsetTop;
const sectionBottom = sectionTop + section.offsetHeight;
const sectionId = section.getAttribute('id');
if (scrollPosition >= sectionTop && scrollPosition < sectionBottom) {
navLinks.forEach(link => {
link.classList.remove('active');
if (link.getAttribute('href') === `#${sectionId}`) {
link.classList.add('active');
}
});
}
});
}
window.addEventListener('scroll', updateActiveNav);
updateActiveNav();
// Smooth scroll for navigation links
navLinks.forEach(link => {
link.addEventListener('click', (e) => {
e.preventDefault();
const targetId = link.getAttribute('href').substring(1);
const targetSection = document.getElementById(targetId);
if (targetSection) {
targetSection.scrollIntoView({ behavior: 'smooth' });
// Close mobile menu if open
mainNav.classList.remove('active');
mobileMenuToggle?.classList.remove('active');
}
});
});
// Scroll animations with Intersection Observer
const observerOptions = {
root: null,
rootMargin: '0px 0px -50px 0px',
threshold: 0.1
};
const scrollObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
scrollObserver.unobserve(entry.target);
}
});
}, observerOptions);
// Observe animate-on-scroll elements
document.querySelectorAll('.animate-on-scroll').forEach(el => {
scrollObserver.observe(el);
});
// Staggered animation for grid items
function animateGridItems(items, baseDelay = 50) {
items.forEach((item, index) => {
setTimeout(() => {
item.classList.add('animate-in');
}, index * baseDelay);
});
}
// Initial animation for visible items
const gridObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const grid = entry.target;
const items = grid.querySelectorAll('.work-item, .team-member');
animateGridItems(items);
gridObserver.unobserve(grid);
}
});
}, { threshold: 0.1 });
const teamWork = document.getElementById('team-work');
const teamGrid = document.getElementById('team-members-grid');
if (teamWork) gridObserver.observe(teamWork);
if (teamGrid) gridObserver.observe(teamGrid);
// Search functionality
const searchInput = document.getElementById('project-search');
const searchClear = document.getElementById('search-clear');
const noResults = document.getElementById('no-results');
const authorSelect = document.getElementById('author-select');
let searchTimeout;
function applyAllFilters() {
const workItems = document.querySelectorAll('.work-item');
const searchQuery = (searchInput?.value || '').toLowerCase().trim();
const currentCategoryFilter = document.querySelector('.filter-btn.active')?.getAttribute('data-filter') || 'all';
const currentAuthorFilter = authorSelect?.value || 'all';
let visibleCount = 0;
workItems.forEach(item => {
const title = item.querySelector('.work-title')?.textContent.toLowerCase() || '';
const description = item.querySelector('.work-description')?.textContent.toLowerCase() || '';
const authorText = item.querySelector('.work-author')?.textContent.toLowerCase() || '';
const label = item.getAttribute('data-label')?.toLowerCase() || '';
const authorId = item.getAttribute('data-author') || '';
// Check search match
const matchesSearch = !searchQuery ||
title.includes(searchQuery) ||
description.includes(searchQuery) ||
authorText.includes(searchQuery) ||
label.includes(searchQuery);
// Check category filter match
const matchesCategoryFilter = currentCategoryFilter === 'all' || item.getAttribute('data-label')?.split(',').includes(currentCategoryFilter);
// Check author filter match
const matchesAuthorFilter = currentAuthorFilter === 'all' || authorId === currentAuthorFilter;
if (matchesSearch && matchesCategoryFilter && matchesAuthorFilter) {
item.classList.remove('hidden');
item.classList.add('filtering-in');
setTimeout(() => {
item.classList.remove('filtering-in');
}, 300);
visibleCount++;
} else {
item.classList.add('hidden');
}
});
// Reset show more state and update UI
showingAll = false;
updateShowMoreButton();
updateNoResults(visibleCount);
}
function performSearch(query) {
applyAllFilters();
}
function updateNoResults(visibleCount) {
if (noResults) {
if (visibleCount === 0) {
noResults.classList.add('visible');
} else {
noResults.classList.remove('visible');
}
}
}
if (searchInput) {
searchInput.addEventListener('input', (e) => {
const query = e.target.value;
// Show/hide clear button
if (searchClear) {
searchClear.classList.toggle('visible', query.length > 0);
}
// Debounce search
clearTimeout(searchTimeout);
searchTimeout = setTimeout(() => {
performSearch(query);
}, 150);
});
}
if (searchClear) {
searchClear.addEventListener('click', () => {
if (searchInput) {
searchInput.value = '';
searchClear.classList.remove('visible');
performSearch('');
searchInput.focus();
}
});
}
// Author filter functionality
if (authorSelect) {
authorSelect.addEventListener('change', () => {
applyAllFilters();
});
}
// Sort functionality
const sortSelect = document.getElementById('sort-select');
function sortItems(sortBy) {
const container = document.getElementById('team-work');
if (!container) return;
const items = Array.from(container.querySelectorAll('.work-item'));
const showMoreContainer = container.querySelector('.show-more-container');
items.sort((a, b) => {
const dateA = a.getAttribute('data-date') || '';
const dateB = b.getAttribute('data-date') || '';
const titleA = a.querySelector('.work-title')?.textContent.toLowerCase() || '';
const titleB = b.querySelector('.work-title')?.textContent.toLowerCase() || '';
switch (sortBy) {
case 'date-desc':
return dateB.localeCompare(dateA);
case 'date-asc':
return dateA.localeCompare(dateB);
case 'alpha-asc':
return titleA.localeCompare(titleB);
case 'alpha-desc':
return titleB.localeCompare(titleA);
default:
return 0;
}
});
// Reorder items with animation
items.forEach((item, index) => {
item.classList.add('filtering-out');
});
setTimeout(() => {
items.forEach((item) => {
container.appendChild(item);
item.classList.remove('filtering-out');
item.classList.add('filtering-in');
});
// Keep show more container at the end
if (showMoreContainer) {
container.appendChild(showMoreContainer);
}
// Remove animation class after animation completes
setTimeout(() => {
items.forEach(item => {
item.classList.remove('filtering-in');
});
}, 300);
// Update visibility
updateShowMoreButton();
}, 200);
}
if (sortSelect) {
sortSelect.addEventListener('change', (e) => {
sortItems(e.target.value);
});
}
// Filter functionality
const filterButtons = document.querySelectorAll('.filter-btn');
const showMoreBtn = document.getElementById('show-more-btn');
let showingAll = false;
function updateShowMoreButton() {
if (!showMoreBtn) return;
const visibleItems = document.querySelectorAll('.work-item:not(.hidden)');
let hiddenCount = 0;
visibleItems.forEach((item, index) => {
if (index >= 6) {
if (!showingAll) {
item.classList.add('work-item-hidden');
}
hiddenCount++;
} else {
item.classList.remove('work-item-hidden');
}
});
if (hiddenCount > 0) {
showMoreBtn.style.display = 'inline-block';
showMoreBtn.textContent = showingAll ? 'Show less' : `Show ${hiddenCount} more`;
} else {
showMoreBtn.style.display = 'none';
}
}
// Show more/less functionality
if (showMoreBtn) {
showMoreBtn.addEventListener('click', () => {
const hiddenItems = document.querySelectorAll('.work-item:not(.hidden).work-item-hidden');
if (!showingAll) {
// Show all items with staggered animation
hiddenItems.forEach((item, index) => {
setTimeout(() => {
item.classList.remove('work-item-hidden');
item.classList.add('filtering-in');
setTimeout(() => {
item.classList.remove('filtering-in');
}, 300);
}, index * 50);
});
showMoreBtn.textContent = 'Show less';
showingAll = true;
} else {
// Hide extra items
const visibleItems = document.querySelectorAll('.work-item:not(.hidden)');
visibleItems.forEach((item, index) => {
if (index >= 6) {
item.classList.add('work-item-hidden');
}
});
showMoreBtn.textContent = `Show ${Math.max(0, visibleItems.length - 6)} more`;
showingAll = false;
// Scroll to projects section if we're below it
const projectsSection = document.getElementById('projects');
if (projectsSection && window.scrollY > projectsSection.offsetTop + 200) {
projectsSection.scrollIntoView({ behavior: 'smooth' });
}
}
});
}
filterButtons.forEach(button => {
button.addEventListener('click', () => {
// Update active button
filterButtons.forEach(btn => btn.classList.remove('active'));
button.classList.add('active');
// Apply all filters (search, category, author)
applyAllFilters();
});
});
// Set last updated date
const lastUpdated = document.getElementById('last-updated');
if (lastUpdated) {
lastUpdated.textContent = new Date().toLocaleDateString('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric'
});
}
// Keyboard navigation for filters
filterButtons.forEach((button, index) => {
button.addEventListener('keydown', (e) => {
if (e.key === 'ArrowRight' || e.key === 'ArrowDown') {
e.preventDefault();
const next = filterButtons[index + 1] || filterButtons[0];
next.focus();
} else if (e.key === 'ArrowLeft' || e.key === 'ArrowUp') {
e.preventDefault();
const prev = filterButtons[index - 1] || filterButtons[filterButtons.length - 1];
prev.focus();
}
});
});
});