]> BookStack Code Mirror - bookstack/blob - resources/assets/js/components/collapsible.js
Merge pull request #1096 from christophert/add-ldaptlsinsecure
[bookstack] / resources / assets / js / components / collapsible.js
1 /**
2  * Collapsible
3  * Provides some simple logic to allow collapsible sections.
4  */
5 class Collapsible {
6
7     constructor(elem) {
8         this.elem = elem;
9         this.trigger = elem.querySelector('[collapsible-trigger]');
10         this.content = elem.querySelector('[collapsible-content]');
11
12         if (!this.trigger) return;
13
14         this.trigger.addEventListener('click', this.toggle.bind(this));
15     }
16
17     open() {
18         this.elem.classList.add('open');
19         $(this.content).slideDown(400);
20     }
21
22     close() {
23         this.elem.classList.remove('open');
24         $(this.content).slideUp(400);
25     }
26
27     toggle() {
28         if (this.elem.classList.contains('open')) {
29             this.close();
30         } else {
31             this.open();
32         }
33     }
34
35 }
36
37 export default Collapsible;