final polish

This commit is contained in:
John Gatward
2026-03-20 18:40:30 +00:00
parent 2646321ad9
commit ed713a931d
3 changed files with 141 additions and 47 deletions

View File

@@ -26,26 +26,61 @@ window.addEventListener('scroll', () => {
// ─── Project filters ──────────────────────────────────────────────
const filterChips = document.querySelectorAll('.filter-chip');
const projectCards = document.querySelectorAll('#project-grid .project-card');
const seeMoreButton = document.querySelector('#projects-see-more');
const DEFAULT_VISIBLE_PROJECTS = 8;
if (filterChips.length > 0 && projectCards.length > 0) {
const applyFilter = (filter) => {
let selectedFilter = 'all';
let isExpanded = false;
const applyFilter = () => {
const visibleCards = [];
projectCards.forEach(card => {
const tech = (card.dataset.tech || '').split(/\s+/).filter(Boolean);
const shouldShow = filter === 'all' || tech.includes(filter);
const shouldShow = selectedFilter === 'all' || tech.includes(selectedFilter);
card.classList.toggle('is-hidden', !shouldShow);
if (shouldShow) {
card.classList.remove('is-collapsed');
visibleCards.push(card);
}
});
if (!isExpanded) {
visibleCards.slice(DEFAULT_VISIBLE_PROJECTS).forEach(card => {
card.classList.add('is-collapsed');
});
}
if (seeMoreButton) {
const canExpand = visibleCards.length > DEFAULT_VISIBLE_PROJECTS;
seeMoreButton.hidden = !canExpand;
seeMoreButton.setAttribute('aria-expanded', canExpand && isExpanded ? 'true' : 'false');
seeMoreButton.textContent = isExpanded ? 'See less' : 'See more';
}
};
filterChips.forEach(chip => {
chip.addEventListener('click', () => {
const selected = chip.dataset.filter || 'all';
selectedFilter = chip.dataset.filter || 'all';
isExpanded = false;
filterChips.forEach(other => {
other.classList.toggle('active', other === chip);
});
applyFilter(selected);
applyFilter();
});
});
if (seeMoreButton) {
seeMoreButton.addEventListener('click', () => {
isExpanded = !isExpanded;
applyFilter();
});
}
applyFilter();
}