-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
78 lines (69 loc) · 2.77 KB
/
script.js
File metadata and controls
78 lines (69 loc) · 2.77 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
// ── THEME ──
(function () {
const saved = localStorage.getItem('theme') || 'light';
document.documentElement.setAttribute('data-theme', saved);
})();
function toggleTheme() {
const current = document.documentElement.getAttribute('data-theme');
const next = current === 'dark' ? 'light' : 'dark';
document.documentElement.setAttribute('data-theme', next);
localStorage.setItem('theme', next);
updateToggleIcon();
}
function updateToggleIcon() {
const btn = document.getElementById('theme-toggle');
if (!btn) return;
const isDark = document.documentElement.getAttribute('data-theme') === 'dark';
btn.textContent = isDark ? '☀️' : '🌙';
btn.title = isDark ? 'Switch to light mode' : 'Switch to dark mode';
}
// ── NAV ACTIVE ──
document.addEventListener('DOMContentLoaded', () => {
updateToggleIcon();
const path = window.location.pathname;
const links = document.querySelectorAll('.nav-btn');
links.forEach(link => {
const href = link.getAttribute('href');
if (!href) return;
const isHome = (path.endsWith('index.html') || path === '/' || path.endsWith('/')) && href.includes('index.html');
const isProjects = path.includes('projects.html') && href.includes('projects.html');
const isContact = path.includes('contact.html') && href.includes('contact.html');
const isAbout = path.includes('about.html') && href.includes('about.html');
if (isHome || isProjects || isContact || isAbout) link.classList.add('active');
});
});
// ── CONTACT FORM ──
function submitForm() {
const msg = document.getElementById('ok-msg');
if (msg) {
msg.style.display = 'block';
setTimeout(() => { msg.style.display = 'none'; }, 5000);
}
}
// ── PROJECT FILTER ──
function filter(cat, btn) {
document.querySelectorAll('.filter-btn').forEach(b => b.classList.remove('active'));
btn.classList.add('active');
document.querySelectorAll('.proj-grid .proj-card').forEach(card => {
const categories = card.dataset.c.split(' ');
card.style.display = (cat === 'all' || categories.includes(cat)) ? '' : 'none';
});
}
// Show success message if redirected back after form submit
if (window.location.search.includes('sent=true')) {
const msg = document.getElementById('ok-msg');
if (msg) msg.style.display = 'block';
}
function toggleMenu() {
const links = document.getElementById('nav-links');
const hamburger = document.getElementById('hamburger');
links.classList.toggle('open');
hamburger.classList.toggle('open');
}
// Close menu when a nav link is clicked
document.querySelectorAll('.nav-links .nav-btn').forEach(link => {
link.addEventListener('click', () => {
document.getElementById('nav-links').classList.remove('open');
document.getElementById('hamburger').classList.remove('open');
});
});