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) {
|
2015-05-04 09:14:03 +08:00
|
|
|
clearTimeout(this.hideTimeout);
|
2015-04-25 20:58:39 +08:00
|
|
|
this.component = component;
|
|
|
|
m.redraw(true);
|
|
|
|
this.$().modal('show');
|
2015-05-26 09:44:06 +08:00
|
|
|
this.ready();
|
2015-04-25 20:58:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
close() {
|
2015-05-04 09:14:03 +08:00
|
|
|
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.$());
|
|
|
|
}
|
|
|
|
}
|