2019-06-07 11:00:34 -04:00
|
|
|
import {slideUp, slideDown} from "../services/animations";
|
2017-08-06 16:08:03 -04: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 11:36:35 -04:00
|
|
|
const list = this.elem.parentNode.querySelector('.inset-list');
|
2017-08-06 16:08:03 -04:00
|
|
|
this.elem.classList.add('open');
|
2019-08-24 13:26:28 -04:00
|
|
|
this.elem.setAttribute('aria-expanded', 'true');
|
2019-06-07 11:00:34 -04:00
|
|
|
slideDown(list, 240);
|
2017-08-06 16:08:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
close() {
|
2018-09-22 11:36:35 -04:00
|
|
|
const list = this.elem.parentNode.querySelector('.inset-list');
|
|
|
|
this.elem.classList.remove('open');
|
2019-08-24 13:26:28 -04:00
|
|
|
this.elem.setAttribute('aria-expanded', 'false');
|
2019-06-07 11:00:34 -04:00
|
|
|
slideUp(list, 240);
|
2017-08-06 16:08:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
click(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
this.isOpen ? this.close() : this.open();
|
|
|
|
this.isOpen = !this.isOpen;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-11-09 16:17:35 -05:00
|
|
|
export default ChapterToggle;
|