blob: 64d9c57f7589ba44055973e61611a39e683d653d (
plain)
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
|
// filters.js
(function() {
const filterBtns = document.querySelectorAll('.filter-btn');
const feedList = document.getElementById('articles-feed');
const cards = feedList ? feedList.querySelectorAll('.post-card') : [];
if (!filterBtns.length || !cards.length) return;
filterBtns.forEach(btn => {
btn.addEventListener('click', function() {
const filter = this.dataset.filter;
// Update active button
filterBtns.forEach(b => b.classList.remove('active'));
this.classList.add('active');
// Filter cards
cards.forEach(card => {
const cardType = card.querySelector('.post-type-badge')?.classList[1];
const matches = filter === 'all' || cardType === filter;
card.style.display = matches ? '' : 'none';
});
// Scroll to top
window.scrollTo({ top: 0, behavior: 'smooth' });
});
});
})();
|