Initial plugin commit
This commit is contained in:
44
assets/front.js
Executable file
44
assets/front.js
Executable file
@@ -0,0 +1,44 @@
|
||||
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));
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user