| |
| |
| |
| |
| |
| |
| |
| |
| (function () { |
| 'use strict'; |
|
|
| var list = document.getElementById('faq-list'); |
| var search = document.getElementById('faq-search'); |
| var cats = Array.from(document.querySelectorAll('.faq-cat')); |
| var empty = document.getElementById('faq-empty'); |
| var count = document.getElementById('faq-count'); |
| if (!list) return; |
|
|
| var items = Array.from(list.querySelectorAll('.faq-item')); |
| var currentCat = 'all'; |
|
|
| |
| function toggle(item) { |
| var isOpen = item.getAttribute('data-open') === 'true'; |
| |
| items.forEach(function (it) { |
| it.setAttribute('data-open', 'false'); |
| var btn = it.querySelector('.faq-q'); |
| if (btn) btn.setAttribute('aria-expanded', 'false'); |
| }); |
| |
| if (!isOpen) { |
| item.setAttribute('data-open', 'true'); |
| var b = item.querySelector('.faq-q'); |
| if (b) b.setAttribute('aria-expanded', 'true'); |
| } |
| } |
|
|
| |
| items.forEach(function (item) { |
| var btn = item.querySelector('.faq-q'); |
| if (btn) btn.addEventListener('click', function () { toggle(item); }); |
| }); |
|
|
| |
| function applyFilter() { |
| var q = (search.value || '').trim().toLowerCase(); |
| var shown = 0; |
| items.forEach(function (item) { |
| var cat = item.getAttribute('data-category'); |
| var text = (item.textContent || '').toLowerCase(); |
| var matchCat = currentCat === 'all' || cat === currentCat; |
| var matchSearch = !q || text.indexOf(q) !== -1; |
| var visible = matchCat && matchSearch; |
| item.setAttribute('data-hidden', visible ? 'false' : 'true'); |
| if (visible) shown++; |
| }); |
| |
| if (empty) empty.style.display = shown === 0 ? 'block' : 'none'; |
| if (count) count.textContent = shown; |
| } |
|
|
| |
| var t; |
| search.addEventListener('input', function () { |
| clearTimeout(t); |
| t = setTimeout(applyFilter, 80); |
| }); |
|
|
| |
| cats.forEach(function (pill) { |
| pill.addEventListener('click', function () { |
| currentCat = pill.getAttribute('data-cat'); |
| cats.forEach(function (p) { |
| p.setAttribute('aria-pressed', p === pill ? 'true' : 'false'); |
| }); |
| applyFilter(); |
| }); |
| }); |
|
|
| |
| document.addEventListener('keydown', function (e) { |
| if (e.key === '/' && document.activeElement !== search) { |
| e.preventDefault(); |
| search.focus(); |
| } else if (e.key === 'Escape' && document.activeElement === search) { |
| search.value = ''; |
| applyFilter(); |
| search.blur(); |
| } |
| }); |
|
|
| |
| applyFilter(); |
| })(); |
|
|