msos/blog-filter.js

23 lines
771 B
JavaScript

/* Blog topic filter: chips toggle which cards are shown. No dependencies. */
(function () {
var list = document.querySelector('.blog-list');
if (!list) return;
var chips = list.querySelectorAll('.blog-chip');
var cards = list.querySelectorAll('.blog-card');
function apply(topic) {
cards.forEach(function (card) {
var show = topic === 'all' || card.getAttribute('data-topic') === topic;
card.hidden = !show;
});
}
chips.forEach(function (chip) {
chip.addEventListener('click', function () {
chips.forEach(function (c) { c.classList.remove('is-active'); });
chip.classList.add('is-active');
apply(chip.getAttribute('data-topic'));
});
});
})();