-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
61 lines (53 loc) · 2.46 KB
/
script.js
File metadata and controls
61 lines (53 loc) · 2.46 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
// ── Dark mode toggle ──────────────────────────────────────────────────────────
function applyTheme(dark) {
document.body.classList.toggle('dark-mode', dark);
localStorage.setItem('theme', dark ? 'dark' : 'light');
}
// Restore saved preference on load
const savedTheme = localStorage.getItem('theme');
if (savedTheme === 'dark') {
document.body.classList.add('dark-mode');
}
// Desktop toggle
const themeToggle = document.getElementById('theme-toggle');
if (themeToggle) {
themeToggle.addEventListener('click', () => {
applyTheme(!document.body.classList.contains('dark-mode'));
});
}
// Mobile drawer toggle
const drawerTheme = document.getElementById('drawer-theme');
if (drawerTheme) {
drawerTheme.addEventListener('click', () => {
applyTheme(!document.body.classList.contains('dark-mode'));
});
}
// ── Mobile nav drawer ─────────────────────────────────────────────────────────
const hamburger = document.getElementById('nav-hamburger');
const drawer = document.getElementById('nav-drawer');
if (hamburger && drawer) {
hamburger.addEventListener('click', () => {
drawer.classList.toggle('open');
});
// Close drawer when a link is tapped
drawer.querySelectorAll('a').forEach(link => {
link.addEventListener('click', () => drawer.classList.remove('open'));
});
}
// ── Dynamic copyright year ────────────────────────────────────────────────────
const yearEl = document.getElementById('year');
if (yearEl) yearEl.textContent = new Date().getFullYear();
// ── Smooth scroll offset for fixed header ─────────────────────────────────────
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', e => {
const target = document.querySelector(anchor.getAttribute('href'));
if (!target) return;
e.preventDefault();
const navHeight = parseInt(
getComputedStyle(document.documentElement).getPropertyValue('--nav-height'),
10
) || 60;
const top = target.getBoundingClientRect().top + window.scrollY - navHeight - 16;
window.scrollTo({ top, behavior: 'smooth' });
});
});