CommentController: Even better handle clicking links while already commenting

If the user is clicking on a new topic link, and a reply widget is
open, attempt to close it instead of doing nothing.

Bug: T272545
Change-Id: I1903f5ae4c9e98c4b3a4703ad0e44d772894592a
This commit is contained in:
Bartosz Dziewoński 2021-01-25 23:41:35 +01:00
parent 718457130e
commit d354b34fa6
2 changed files with 12 additions and 3 deletions

View file

@ -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;

View file

@ -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;
};
/**