From 49e9ab362a8d3474b25838ffe1279afe944fa015 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Wed, 22 Jul 2015 09:54:00 +0930 Subject: [PATCH] Persist modal across routes Don't hide it unless it's already been shown, otherwise bootstrap JS won't be initialized correctly --- js/lib/components/ModalManager.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/js/lib/components/ModalManager.js b/js/lib/components/ModalManager.js index cc6bc08d7..81e3b78f5 100644 --- a/js/lib/components/ModalManager.js +++ b/js/lib/components/ModalManager.js @@ -7,6 +7,13 @@ import Modal from 'flarum/components/Modal'; * overwrite the previous one. */ export default class ModalManager extends Component { + constructor(...args) { + super(...args); + + this.showing = false; + this.component = null; + } + view() { return (
@@ -15,9 +22,11 @@ export default class ModalManager extends Component { ); } - config(isInitialized) { + config(isInitialized, context) { if (isInitialized) return; + context.retain = true; + this.$() .on('hidden.bs.modal', this.clear.bind(this)) .on('shown.bs.modal', this.onready.bind(this)); @@ -36,6 +45,7 @@ export default class ModalManager extends Component { clearTimeout(this.hideTimeout); + this.showing = true; this.component = component; m.redraw(true); @@ -50,12 +60,17 @@ export default class ModalManager extends Component { * @public */ close() { + if (!this.showing) return; + // Don't hide the modal immediately, because if the consumer happens to call // the `show` method straight after to show another modal dialog, it will // cause Bootstrap's modal JS to misbehave. Instead we will wait for a tiny // bit to give the `show` method the opportunity to prevent this from going // ahead. - this.hideTimeout = setTimeout(() => this.$().modal('hide')); + this.hideTimeout = setTimeout(() => { + this.$().modal('hide'); + this.showing = false; + }); } /**