2019-06-07 16:51:01 +02:00
|
|
|
import {slideDown, slideUp} from "../services/animations";
|
|
|
|
|
2017-12-10 14:46:50 +01:00
|
|
|
/**
|
|
|
|
* Collapsible
|
|
|
|
* Provides some simple logic to allow collapsible sections.
|
|
|
|
*/
|
|
|
|
class Collapsible {
|
|
|
|
|
|
|
|
constructor(elem) {
|
|
|
|
this.elem = elem;
|
|
|
|
this.trigger = elem.querySelector('[collapsible-trigger]');
|
|
|
|
this.content = elem.querySelector('[collapsible-content]');
|
|
|
|
|
|
|
|
if (!this.trigger) return;
|
|
|
|
|
|
|
|
this.trigger.addEventListener('click', this.toggle.bind(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
open() {
|
|
|
|
this.elem.classList.add('open');
|
2019-06-07 16:51:01 +02:00
|
|
|
slideDown(this.content, 300);
|
2017-12-10 14:46:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
close() {
|
|
|
|
this.elem.classList.remove('open');
|
2019-06-07 16:51:01 +02:00
|
|
|
slideUp(this.content, 300);
|
2017-12-10 14:46:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
toggle() {
|
|
|
|
if (this.elem.classList.contains('open')) {
|
|
|
|
this.close();
|
|
|
|
} else {
|
|
|
|
this.open();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-11-09 22:17:35 +01:00
|
|
|
export default Collapsible;
|