2019-06-07 23:00:34 +08:00
|
|
|
import {slideUp, slideDown} from "../services/animations";
|
2022-11-16 00:04:46 +08:00
|
|
|
import {Component} from "./component";
|
2017-08-07 04:08:03 +08:00
|
|
|
|
2022-11-16 00:04:46 +08:00
|
|
|
export class ExpandToggle extends Component {
|
2017-08-07 04:08:03 +08:00
|
|
|
|
2022-11-16 00:04:46 +08:00
|
|
|
setup(elem) {
|
|
|
|
this.targetSelector = this.$opts.targetSelector;
|
|
|
|
this.isOpen = this.$opts.isOpen === 'true';
|
|
|
|
this.updateEndpoint = this.$opts.updateEndpoint;
|
2019-04-14 20:01:51 +08:00
|
|
|
|
|
|
|
// Listener setup
|
2022-11-16 00:04:46 +08:00
|
|
|
this.$el.addEventListener('click', this.click.bind(this));
|
2017-08-07 04:08:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
open(elemToToggle) {
|
2019-06-07 23:00:34 +08:00
|
|
|
slideDown(elemToToggle, 200);
|
2017-08-07 04:08:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
close(elemToToggle) {
|
2019-06-07 23:00:34 +08:00
|
|
|
slideUp(elemToToggle, 200);
|
2017-08-07 04:08:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
click(event) {
|
|
|
|
event.preventDefault();
|
2019-04-14 20:01:51 +08:00
|
|
|
|
2022-11-16 00:04:46 +08:00
|
|
|
const matchingElems = document.querySelectorAll(this.targetSelector);
|
2019-04-14 20:01:51 +08:00
|
|
|
for (let match of matchingElems) {
|
|
|
|
this.isOpen ? this.close(match) : this.open(match);
|
2017-08-07 04:08:03 +08:00
|
|
|
}
|
2019-04-14 20:01:51 +08:00
|
|
|
|
2017-08-07 04:08:03 +08:00
|
|
|
this.isOpen = !this.isOpen;
|
2019-04-14 20:01:51 +08:00
|
|
|
this.updateSystemAjax(this.isOpen);
|
|
|
|
}
|
|
|
|
|
|
|
|
updateSystemAjax(isOpen) {
|
|
|
|
window.$http.patch(this.updateEndpoint, {
|
|
|
|
expand: isOpen ? 'true' : 'false'
|
|
|
|
});
|
2017-08-07 04:08:03 +08:00
|
|
|
}
|
|
|
|
|
2022-11-16 00:04:46 +08:00
|
|
|
}
|