diff --git a/modules/controller.js b/modules/controller.js index 945ee7600..e586cbb49 100644 --- a/modules/controller.js +++ b/modules/controller.js @@ -312,6 +312,15 @@ function init( $container, state ) { return; } + // If this is a new topic link, and a reply widget is open, attempt to close it first. + if ( activeController && c instanceof NewTopicController ) { + activeController.replyWidget.tryTeardown().then( function () { + activeController = c; + c.setup(); + } ); + return; + } + // If another reply widget is open (or opening), do nothing. if ( activeController ) { return; diff --git a/modules/dt.ui.ReplyWidget.js b/modules/dt.ui.ReplyWidget.js index 801fd3edd..6935eaeb3 100644 --- a/modules/dt.ui.ReplyWidget.js +++ b/modules/dt.ui.ReplyWidget.js @@ -472,7 +472,7 @@ ReplyWidget.prototype.afterSetup = function () { * Try to teardown the widget, prompting the user if unsaved changes will be lost. * * @chainable - * @return {ReplyWidget} + * @return {jQuery.Promise} Resolves if widget was torn down, rejects if it wasn't */ ReplyWidget.prototype.tryTeardown = function () { var promise, @@ -498,10 +498,10 @@ ReplyWidget.prototype.tryTeardown = function () { type: 'nochange' } ); } - promise.then( function () { + promise = promise.then( function () { widget.teardown( true ); } ); - return this; + return promise; }; /**