20 lines
749 B
JavaScript
20 lines
749 B
JavaScript
/* News hub type filter: chips toggle which cards are shown. No dependencies. */
|
|
(function () {
|
|
var list = document.querySelector('.newshub-list');
|
|
if (!list) return;
|
|
var chips = list.querySelectorAll('.newshub-chip');
|
|
var cards = list.querySelectorAll('.newshub-card');
|
|
function apply(type) {
|
|
cards.forEach(function (card) {
|
|
card.hidden = !(type === 'all' || card.getAttribute('data-type') === type);
|
|
});
|
|
}
|
|
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-type'));
|
|
});
|
|
});
|
|
})();
|