]> BookStack Code Mirror - bookstack/blob - resources/js/components/expand-toggle.js
Merge branch 'development' of github.com:BookStackApp/BookStack into development
[bookstack] / resources / js / components / expand-toggle.js
1 import {slideUp, slideDown} from '../services/animations.ts';
2 import {Component} from './component';
3
4 export class ExpandToggle extends Component {
5
6     setup() {
7         this.targetSelector = this.$opts.targetSelector;
8         this.isOpen = this.$opts.isOpen === 'true';
9         this.updateEndpoint = this.$opts.updateEndpoint;
10
11         // Listener setup
12         this.$el.addEventListener('click', this.click.bind(this));
13     }
14
15     open(elemToToggle) {
16         slideDown(elemToToggle, 200);
17     }
18
19     close(elemToToggle) {
20         slideUp(elemToToggle, 200);
21     }
22
23     click(event) {
24         event.preventDefault();
25
26         const matchingElems = document.querySelectorAll(this.targetSelector);
27         for (const match of matchingElems) {
28             const action = this.isOpen ? this.close : this.open;
29             action(match);
30         }
31
32         this.isOpen = !this.isOpen;
33         this.updateSystemAjax(this.isOpen);
34     }
35
36     updateSystemAjax(isOpen) {
37         window.$http.patch(this.updateEndpoint, {
38             expand: isOpen ? 'true' : 'false',
39         });
40     }
41
42 }
Morty Proxy This is a proxified and sanitized view of the page, visit original site.