-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
426 lines (355 loc) · 11.9 KB
/
app.js
File metadata and controls
426 lines (355 loc) · 11.9 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
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
class PortfolioApp {
constructor() {
this.currentPage = 'home';
this.currentTheme = 'theme-forest';
this.isDarkMode = true; // Default to dark mode
this.isMobileMenuOpen = false;
this.init();
}
init() {
this.setupEventListeners();
this.initializeTheme();
this.handleInitialRoute();
this.loadProjects();
this.updateStats();
this.initLogoAnimation();
}
setupEventListeners() {
// Brand link (Om Singh as home button)
const brandLink = document.querySelector('.brand-link');
if (brandLink) {
brandLink.addEventListener('click', (e) => {
e.preventDefault();
this.navigateTo('home');
});
}
// Navigation links
document.querySelectorAll('.nav-link, .mobile-nav-link').forEach(link => {
link.addEventListener('click', (e) => {
e.preventDefault();
const page = link.getAttribute('href').substring(1);
this.navigateTo(page);
this.closeMobileMenu();
});
});
// CTA buttons
document.querySelectorAll('.btn[href^="#"]').forEach(btn => {
btn.addEventListener('click', (e) => {
e.preventDefault();
const page = btn.getAttribute('href').substring(1);
this.navigateTo(page);
});
});
// Theme switcher
document.querySelectorAll('.theme-btn').forEach(btn => {
btn.addEventListener('click', () => {
const theme = btn.getAttribute('data-theme');
this.switchTheme(theme);
});
});
// Dark mode toggle
const darkModeToggle = document.querySelector('.dark-mode-toggle');
if (darkModeToggle) {
darkModeToggle.addEventListener('click', () => {
this.toggleDarkMode();
});
}
// Mobile menu toggle
const mobileToggle = document.querySelector('.mobile-menu-toggle');
if (mobileToggle) {
mobileToggle.addEventListener('click', () => {
this.toggleMobileMenu();
});
}
// Close mobile menu when clicking outside
document.addEventListener('click', (e) => {
const mobileMenu = document.querySelector('.mobile-menu');
const mobileToggle = document.querySelector('.mobile-menu-toggle');
if (this.isMobileMenuOpen &&
!mobileMenu.contains(e.target) &&
!mobileToggle.contains(e.target)) {
this.closeMobileMenu();
}
});
// Handle browser back/forward buttons
window.addEventListener('popstate', () => {
this.handleInitialRoute();
});
// Handle hash changes
window.addEventListener('hashchange', () => {
this.handleInitialRoute();
});
}
navigateTo(page) {
// Update URL hash
window.location.hash = page;
// Hide all pages
document.querySelectorAll('.page').forEach(p => {
p.classList.remove('active');
});
// Show target page
const targetPage = document.getElementById(page);
if (targetPage) {
targetPage.classList.add('active');
}
// Update navigation state
document.querySelectorAll('.nav-link').forEach(link => {
link.classList.remove('active');
if (link.getAttribute('href') === `#${page}`) {
link.classList.add('active');
}
});
// Show/hide navbar based on page
const navbar = document.querySelector('.navbar');
if (navbar) {
if (page === 'home') {
navbar.classList.add('hidden');
} else {
navbar.classList.remove('hidden');
}
}
this.currentPage = page;
// Scroll to top
window.scrollTo({ top: 0, behavior: 'smooth' });
}
handleInitialRoute() {
const hash = window.location.hash.substring(1);
const page = hash || 'home';
// Always navigate on initial route to ensure proper page visibility
this.navigateTo(page);
}
switchTheme(themeName) {
// Remove current theme
document.body.classList.remove(this.currentTheme);
// Add new theme
const themeClass = `theme-${themeName}`;
document.body.classList.add(themeClass);
this.currentTheme = themeClass;
// Update theme button states
document.querySelectorAll('.theme-btn').forEach(btn => {
btn.classList.remove('active');
if (btn.getAttribute('data-theme') === themeName) {
btn.classList.add('active');
}
});
}
toggleDarkMode() {
this.isDarkMode = !this.isDarkMode;
if (this.isDarkMode) {
document.body.setAttribute('data-color-scheme', 'dark');
} else {
document.body.setAttribute('data-color-scheme', 'light');
}
// Update dark mode toggle icon
const toggle = document.querySelector('.dark-mode-toggle i');
if (toggle) {
toggle.className = this.isDarkMode ? 'fas fa-sun' : 'fas fa-moon';
}
}
initializeTheme() {
// Set default dark mode
document.body.setAttribute('data-color-scheme', 'dark');
// Set default theme
document.body.classList.add(this.currentTheme);
// Update theme button state
const defaultThemeBtn = document.querySelector('[data-theme="forest"]');
if (defaultThemeBtn) {
defaultThemeBtn.classList.add('active');
}
}
toggleMobileMenu() {
const mobileMenu = document.querySelector('.mobile-menu');
const mobileToggle = document.querySelector('.mobile-menu-toggle');
this.isMobileMenuOpen = !this.isMobileMenuOpen;
if (this.isMobileMenuOpen) {
mobileMenu.classList.add('active');
mobileMenu.style.display = 'flex';
mobileToggle.classList.add('active');
} else {
mobileMenu.classList.remove('active');
mobileMenu.style.display = 'none';
mobileToggle.classList.remove('active');
}
}
closeMobileMenu() {
if (this.isMobileMenuOpen) {
const mobileMenu = document.querySelector('.mobile-menu');
const mobileToggle = document.querySelector('.mobile-menu-toggle');
this.isMobileMenuOpen = false;
mobileMenu.classList.remove('active');
mobileMenu.style.display = 'none';
mobileToggle.classList.remove('active');
}
}
loadProjects() {
const projectsGrid = document.getElementById('projects-grid');
const emptyState = document.querySelector('.empty-projects');
if (portfolioData.projects.length === 0) {
// Show empty state
if (emptyState) {
emptyState.style.display = 'flex';
}
if (projectsGrid) {
projectsGrid.style.display = 'none';
}
} else {
// Hide empty state and show projects
if (emptyState) {
emptyState.style.display = 'none';
}
if (projectsGrid) {
projectsGrid.style.display = 'grid';
this.renderProjects();
}
}
}
renderProjects() {
const projectsGrid = document.getElementById('projects-grid');
if (!projectsGrid) return;
projectsGrid.innerHTML = '';
portfolioData.projects.forEach(project => {
const projectCard = this.createProjectCard(project);
projectsGrid.appendChild(projectCard);
});
}
createProjectCard(project) {
const card = document.createElement('div');
card.className = 'project-card';
const techBadges = project.technologies.map(tech =>
`<span class="tech-badge">${tech}</span>`
).join('');
card.innerHTML = `
<div class="project-image">
<img src="${project.image}" alt="${project.title}" onerror="this.parentElement.innerHTML='<i class=\"fas fa-image\" style=\"font-size: 3rem; color: var(--color-text-secondary);\"></i>'">
</div>
<div class="project-content">
<h3 class="project-title">${project.title}</h3>
<p class="project-description">${project.description}</p>
<div class="project-tech">
${techBadges}
</div>
<div class="project-actions">
${project.github ? `<a href="${project.github}" target="_blank" class="btn btn--secondary"><i class="fab fa-github"></i> Code</a>` : ''}
${project.live ? `<a href="${project.live}" target="_blank" class="btn btn--primary"><i class="fas fa-external-link-alt"></i> Live Demo</a>` : ''}
</div>
</div>
`;
return card;
}
updateStats() {
// Update stats based on current data
const stats = portfolioData.stats;
// Update age
const ageElements = document.querySelectorAll('.stat-card .stat-number');
if (ageElements[0]) {
ageElements[0].textContent = stats.age;
}
// Update project count
if (ageElements[1]) {
ageElements[1].textContent = stats.projects;
}
// Update technology count
if (ageElements[2]) {
ageElements[2].textContent = stats.technologies;
}
}
// Utility method to add new project (for future use)
addProject(project) {
portfolioData.projects.push(project);
portfolioData.stats.projects = portfolioData.projects.length;
this.loadProjects();
this.updateStats();
}
// Utility method to update personal info (for future use)
updatePersonalInfo(info) {
Object.assign(portfolioData.personal, info);
// Update UI elements that display personal info
this.updatePersonalInfoUI();
}
updatePersonalInfoUI() {
// Update name in navigation
const navBrand = document.querySelector('.nav-brand h2');
if (navBrand) {
navBrand.textContent = portfolioData.personal.name;
}
// Update hero title
const heroName = document.querySelector('.hero-title .highlight');
if (heroName) {
heroName.textContent = portfolioData.personal.name;
}
// Update profile images
const profileImages = document.querySelectorAll('img[alt*="Om Singh"]');
profileImages.forEach(img => {
img.src = portfolioData.personal.profileImage;
img.alt = portfolioData.personal.name;
});
}
// Method to get current theme info
getCurrentTheme() {
return {
name: this.currentTheme,
isDark: this.isDarkMode
};
}
// Animated logo letters
initLogoAnimation() {
const letters = document.querySelectorAll('.nav-brand .letter');
if (letters.length === 0) return;
const animateLetter = (index) => {
if (index >= letters.length) return;
const letter = letters[index];
// Skip spaces
if (letter.classList.contains('space')) {
setTimeout(() => animateLetter(index + 1), 100);
return;
}
// Apply 3D rotation on Y-axis - rotate once (360 degrees)
letter.style.transform = 'rotateY(360deg)';
// Reset to original position after rotation completes
setTimeout(() => {
letter.style.transition = 'none'; // Disable transition temporarily
letter.style.transform = 'rotateY(0deg)';
// Re-enable transition for next animation
setTimeout(() => {
letter.style.transition = 'transform 0.8s ease-in-out';
}, 50);
}, 800);
// Animate next letter after delay
setTimeout(() => animateLetter(index + 1), 250);
};
// Start the animation sequence
const startAnimation = () => {
animateLetter(0);
};
// Initial animation after page load
setTimeout(startAnimation, 1500);
// Repeat animation every 6 seconds
setInterval(startAnimation, 6000);
}
}
// Initialize the portfolio app when DOM is loaded
document.addEventListener('DOMContentLoaded', () => {
window.portfolioApp = new PortfolioApp();
});
// Handle smooth scrolling for anchor links
document.addEventListener('click', (e) => {
if (e.target.tagName === 'A' && e.target.getAttribute('href').startsWith('#')) {
e.preventDefault();
const targetId = e.target.getAttribute('href').substring(1);
const targetElement = document.getElementById(targetId);
if (targetElement) {
targetElement.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
}
});
// Add loading animation
window.addEventListener('load', () => {
document.body.classList.add('loaded');
});
// Export for potential module use
if (typeof module !== 'undefined' && module.exports) {
module.exports = PortfolioApp;
}