-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
59 lines (56 loc) · 2.26 KB
/
Copy pathscript.js
File metadata and controls
59 lines (56 loc) · 2.26 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
function toggleTheme(){
const isLight = document.documentElement.classList.toggle('light');
document.getElementById('themeToggle').textContent = isLight ? '☀️' : '🌙';
try { localStorage.setItem('theme', isLight ? 'light' : 'dark'); } catch(e) {}
}
document.addEventListener('DOMContentLoaded', () => {
if (document.documentElement.classList.contains('light')) {
const btn = document.getElementById('themeToggle');
if (btn) btn.textContent = '☀️';
}
});
/* Project filters.
These buttons used to only move the .active class around, so they looked
clickable and did nothing. Each .project-card carries a data-category and
each button a data-filter; "all" shows everything. Counts are derived from
the cards actually present rather than hard-coded, so they can't drift out
of sync with the grid when the sync workflow appends a new card. */
(function(){
const buttons = document.querySelectorAll('.filter-btn[data-filter]');
const cards = document.querySelectorAll('.project-card[data-category]');
if (!buttons.length || !cards.length) return;
buttons.forEach(btn => {
const filter = btn.dataset.filter;
const countEl = btn.querySelector('.filter-count');
if (countEl) {
countEl.textContent = filter === 'all'
? cards.length
: Array.from(cards).filter(c => c.dataset.category === filter).length;
}
btn.addEventListener('click', () => {
buttons.forEach(b => {
b.classList.remove('active');
b.setAttribute('aria-pressed', 'false');
});
btn.classList.add('active');
btn.setAttribute('aria-pressed', 'true');
cards.forEach(card => {
const show = filter === 'all' || card.dataset.category === filter;
card.hidden = !show;
});
});
});
// Hide any filter with nothing behind it, so you can't land on an empty grid.
buttons.forEach(btn => {
const filter = btn.dataset.filter;
if (filter === 'all') return;
const n = Array.from(cards).filter(c => c.dataset.category === filter).length;
if (n === 0) btn.hidden = true;
});
})();
function tick(){
const now = new Date();
const el = document.getElementById('clock');
if (el) el.textContent = now.toLocaleTimeString('en-NZ',{hour12:false}) + ' NZST';
}
tick(); setInterval(tick,1000);