From 75b2aa2edd6febb180d2f2dc5340eebc3cdd9037 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Wed, 30 Aug 2017 17:52:49 -0400 Subject: [PATCH] Better support for inline modals --- .../discourse/components/d-modal-body.js.es6 | 18 ++++++++++++++++-- .../discourse/components/d-modal.js.es6 | 6 +++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/discourse/components/d-modal-body.js.es6 b/app/assets/javascripts/discourse/components/d-modal-body.js.es6 index a2b373400ab..660456db7f5 100644 --- a/app/assets/javascripts/discourse/components/d-modal-body.js.es6 +++ b/app/assets/javascripts/discourse/components/d-modal-body.js.es6 @@ -1,10 +1,17 @@ export default Ember.Component.extend({ classNames: ['modal-body'], + fixed: false, didInsertElement() { this._super(); $('#modal-alert').hide(); - $('.d-modal.fixed-modal').modal('show'); + + let fixedParent = this.$().closest('.d-modal.fixed-modal'); + if (fixedParent.length) { + this.set('fixed', true); + fixedParent.modal('show'); + } + Ember.run.scheduleOnce('afterRender', this, this._afterFirstRender); this.appEvents.on('modal-body:flash', msg => this._flash(msg)); }, @@ -28,7 +35,14 @@ export default Ember.Component.extend({ } } - this.appEvents.trigger('modal:body-shown', this.getProperties('title', 'rawTitle')); + this.appEvents.trigger( + 'modal:body-shown', + this.getProperties( + 'title', + 'rawTitle', + 'fixed' + ) + ); }, _flash(msg) { diff --git a/app/assets/javascripts/discourse/components/d-modal.js.es6 b/app/assets/javascripts/discourse/components/d-modal.js.es6 index e0cf5bafc13..c015ca6ba52 100644 --- a/app/assets/javascripts/discourse/components/d-modal.js.es6 +++ b/app/assets/javascripts/discourse/components/d-modal.js.es6 @@ -27,7 +27,11 @@ export default Ember.Component.extend({ }); this.appEvents.on('modal:body-shown', data => { - this.$().removeClass('hidden'); + if (this.isDestroying || this.isDestroyed) { return; } + if (data.fixed) { + this.$().removeClass('hidden'); + } + if (data.title) { this.set('title', I18n.t(data.title)); } else if (data.rawTitle) {