]> BookStack Code Mirror - bookstack/blob - resources/js/components/collapsible.js
Merge branch 'development' of github.com:BookStackApp/BookStack into development
[bookstack] / resources / js / components / collapsible.js
1 import {slideDown, slideUp} from '../services/animations.ts';
2 import {Component} from './component';
3
4 /**
5  * Collapsible
6  * Provides some simple logic to allow collapsible sections.
7  */
8 export class Collapsible extends Component {
9
10     setup() {
11         this.container = this.$el;
12         this.trigger = this.$refs.trigger;
13         this.content = this.$refs.content;
14
15         if (this.trigger) {
16             this.trigger.addEventListener('click', this.toggle.bind(this));
17             this.openIfContainsError();
18         }
19     }
20
21     open() {
22         this.container.classList.add('open');
23         this.trigger.setAttribute('aria-expanded', 'true');
24         slideDown(this.content, 300);
25     }
26
27     close() {
28         this.container.classList.remove('open');
29         this.trigger.setAttribute('aria-expanded', 'false');
30         slideUp(this.content, 300);
31     }
32
33     toggle() {
34         if (this.container.classList.contains('open')) {
35             this.close();
36         } else {
37             this.open();
38         }
39     }
40
41     openIfContainsError() {
42         const error = this.content.querySelector('.text-neg.text-small');
43         if (error) {
44             this.open();
45         }
46     }
47
48 }
Morty Proxy This is a proxified and sanitized view of the page, visit original site.