framework/js/lib/components/modal.js

39 lines
834 B
JavaScript
Raw Normal View History

2015-04-25 20:58:39 +08:00
import Component from 'flarum/component';
export default class Modal extends Component {
view() {
return m('div.modal.fade', {config: this.onload.bind(this)}, this.component && this.component.view())
}
onload(element, isInitialized) {
if (isInitialized) { return; }
this.element(element);
this.$()
.on('hidden.bs.modal', this.destroy.bind(this))
.on('shown.bs.modal', this.ready.bind(this));
}
show(component) {
clearTimeout(this.hideTimeout);
2015-04-25 20:58:39 +08:00
this.component = component;
m.redraw(true);
this.$().modal('show');
this.ready();
2015-04-25 20:58:39 +08:00
}
close() {
this.hideTimeout = setTimeout(() => this.$().modal('hide'));
2015-04-25 20:58:39 +08:00
}
destroy() {
this.component = null;
2015-05-02 07:15:24 +08:00
m.redraw();
2015-04-25 20:58:39 +08:00
}
ready() {
this.component && this.component.ready && this.component.ready(this.$());
}
}