]> BookStack Code Mirror - bookstack/blob - resources/assets/js/components/collapsible.js
Adds autofocus on the email field of the standard login page.
[bookstack] / resources / assets / js / components / collapsible.js
1 import {slideDown, slideUp} from "../services/animations";
2
3 /**
4  * Collapsible
5  * Provides some simple logic to allow collapsible sections.
6  */
7 class Collapsible {
8
9     constructor(elem) {
10         this.elem = elem;
11         this.trigger = elem.querySelector('[collapsible-trigger]');
12         this.content = elem.querySelector('[collapsible-content]');
13
14         if (!this.trigger) return;
15
16         this.trigger.addEventListener('click', this.toggle.bind(this));
17     }
18
19     open() {
20         this.elem.classList.add('open');
21         slideDown(this.content, 300);
22     }
23
24     close() {
25         this.elem.classList.remove('open');
26         slideUp(this.content, 300);
27     }
28
29     toggle() {
30         if (this.elem.classList.contains('open')) {
31             this.close();
32         } else {
33             this.open();
34         }
35     }
36
37 }
38
39 export default Collapsible;