mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-27 10:26:35 +03:00
26 lines
809 B
JavaScript
26 lines
809 B
JavaScript
'use strict';
|
|
|
|
import { $$ } from './util.js';
|
|
|
|
export default class Accordion {
|
|
/**
|
|
* Simple, collapsible accordion sections.
|
|
* Inspired by: https://inclusive-components.design/collapsible-sections/
|
|
* @param {string} selector - Query selector of button element.
|
|
*/
|
|
constructor(selector) {
|
|
[...$$(selector)].forEach(btn =>
|
|
btn.addEventListener('click', this.onClick.bind(this)))
|
|
}
|
|
|
|
/**
|
|
* Toggle aria-expanded attribute on button and visibility of section.
|
|
* @param {node} Event.target - The accordion button.
|
|
*/
|
|
onClick({ target }) {
|
|
const exp = target.getAttribute('aria-expanded') === 'true' || false;
|
|
target.setAttribute('aria-expanded', !exp);
|
|
target.parentElement.nextElementSibling.hidden = exp;
|
|
}
|
|
}
|