45 lines
1.2 KiB
JavaScript
Executable File
45 lines
1.2 KiB
JavaScript
Executable File
document.addEventListener('click', function (event) {
|
|
const button = event.target.closest('[data-kgv-faq-toggle]');
|
|
if (!button) {
|
|
return;
|
|
}
|
|
|
|
const panelId = button.getAttribute('aria-controls');
|
|
const panel = document.getElementById(panelId);
|
|
if (!panel) {
|
|
return;
|
|
}
|
|
|
|
const isOpen = button.getAttribute('aria-expanded') === 'true';
|
|
|
|
button.setAttribute('aria-expanded', isOpen ? 'false' : 'true');
|
|
button.classList.toggle('is-open', !isOpen);
|
|
panel.classList.toggle('is-open', !isOpen);
|
|
|
|
if (isOpen) {
|
|
panel.setAttribute('hidden', '');
|
|
} else {
|
|
panel.removeAttribute('hidden');
|
|
}
|
|
});
|
|
|
|
document.addEventListener('input', function (event) {
|
|
const input = event.target.closest('[data-kgv-faq-search]');
|
|
if (!input) {
|
|
return;
|
|
}
|
|
|
|
const wrapper = input.closest('[data-kgv-faq]');
|
|
if (!wrapper) {
|
|
return;
|
|
}
|
|
|
|
const value = input.value.trim().toLowerCase();
|
|
const items = wrapper.querySelectorAll('[data-kgv-faq-item]');
|
|
|
|
items.forEach(function (item) {
|
|
const text = item.textContent.toLowerCase();
|
|
item.classList.toggle('is-hidden', value && !text.includes(value));
|
|
});
|
|
});
|