]> BookStack Code Mirror - bookstack/blob - resources/js/components/chapter-contents.js
c824d0f78b0b7fad13fcb16f84453746be6f1c7c
[bookstack] / resources / js / components / chapter-contents.js
1 import {slideUp, slideDown} from "../services/animations";
2
3 /**
4  * @extends {Component}
5  */
6 class ChapterContents {
7
8     setup() {
9         this.list = this.$refs.list;
10         this.toggle = this.$refs.toggle;
11
12         this.isOpen = this.toggle.classList.contains('open');
13         this.toggle.addEventListener('click', this.click.bind(this));
14     }
15
16     open() {
17         this.toggle.classList.add('open');
18         this.toggle.setAttribute('aria-expanded', 'true');
19         slideDown(this.list, 180);
20         this.isOpen = true;
21     }
22
23     close() {
24         this.toggle.classList.remove('open');
25         this.toggle.setAttribute('aria-expanded', 'false');
26         slideUp(this.list, 180);
27         this.isOpen = false;
28     }
29
30     click(event) {
31         event.preventDefault();
32         this.isOpen ?  this.close() : this.open();
33     }
34
35 }
36
37 export default ChapterContents;