2019-06-07 17:00:34 +02:00
|
|
|
import {slideUp, slideDown} from "../services/animations";
|
2017-08-06 22:08:03 +02:00
|
|
|
|
|
|
|
class ChapterToggle {
|
|
|
|
|
|
|
|
constructor(elem) {
|
|
|
|
this.elem = elem;
|
|
|
|
this.isOpen = elem.classList.contains('open');
|
|
|
|
elem.addEventListener('click', this.click.bind(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
open() {
|
2018-09-22 17:36:35 +02:00
|
|
|
const list = this.elem.parentNode.querySelector('.inset-list');
|
2017-08-06 22:08:03 +02:00
|
|
|
this.elem.classList.add('open');
|
2019-06-07 17:00:34 +02:00
|
|
|
slideDown(list, 240);
|
2017-08-06 22:08:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
close() {
|
2018-09-22 17:36:35 +02:00
|
|
|
const list = this.elem.parentNode.querySelector('.inset-list');
|
|
|
|
this.elem.classList.remove('open');
|
2019-06-07 17:00:34 +02:00
|
|
|
slideUp(list, 240);
|
2017-08-06 22:08:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
click(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
this.isOpen ? this.close() : this.open();
|
|
|
|
this.isOpen = !this.isOpen;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-11-09 22:17:35 +01:00
|
|
|
export default ChapterToggle;
|