]> BookStack Code Mirror - bookstack/blob - resources/js/components/chapter-toggle.js
Merge branch 'master' of git://github.com/albergoniSivaf/BookStack into albergoniSiva...
[bookstack] / resources / js / components / chapter-toggle.js
1 import {slideUp, slideDown} from "../services/animations";
2
3 class ChapterToggle {
4
5     constructor(elem) {
6         this.elem = elem;
7         this.isOpen = elem.classList.contains('open');
8         elem.addEventListener('click', this.click.bind(this));
9     }
10
11     open() {
12         const list = this.elem.parentNode.querySelector('.inset-list');
13         this.elem.classList.add('open');
14         this.elem.setAttribute('aria-expanded', 'true');
15         slideDown(list, 240);
16     }
17
18     close() {
19         const list = this.elem.parentNode.querySelector('.inset-list');
20         this.elem.classList.remove('open');
21         this.elem.setAttribute('aria-expanded', 'false');
22         slideUp(list, 240);
23     }
24
25     click(event) {
26         event.preventDefault();
27         this.isOpen ?  this.close() : this.open();
28         this.isOpen = !this.isOpen;
29     }
30
31 }
32
33 export default ChapterToggle;