mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-10-01 01:36:00 -04:00
e711290d8b
Had to do some manual fixing of the app.js file due to misplaced comments
42 lines
1.0 KiB
JavaScript
42 lines
1.0 KiB
JavaScript
import {slideUp, slideDown} from '../services/animations';
|
|
import {Component} from './component';
|
|
|
|
export class ExpandToggle extends Component {
|
|
|
|
setup(elem) {
|
|
this.targetSelector = this.$opts.targetSelector;
|
|
this.isOpen = this.$opts.isOpen === 'true';
|
|
this.updateEndpoint = this.$opts.updateEndpoint;
|
|
|
|
// Listener setup
|
|
this.$el.addEventListener('click', this.click.bind(this));
|
|
}
|
|
|
|
open(elemToToggle) {
|
|
slideDown(elemToToggle, 200);
|
|
}
|
|
|
|
close(elemToToggle) {
|
|
slideUp(elemToToggle, 200);
|
|
}
|
|
|
|
click(event) {
|
|
event.preventDefault();
|
|
|
|
const matchingElems = document.querySelectorAll(this.targetSelector);
|
|
for (const match of matchingElems) {
|
|
this.isOpen ? this.close(match) : this.open(match);
|
|
}
|
|
|
|
this.isOpen = !this.isOpen;
|
|
this.updateSystemAjax(this.isOpen);
|
|
}
|
|
|
|
updateSystemAjax(isOpen) {
|
|
window.$http.patch(this.updateEndpoint, {
|
|
expand: isOpen ? 'true' : 'false',
|
|
});
|
|
}
|
|
|
|
}
|