From 09857e13f12584ff8cf27d698de83de0d534188e Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Thu, 11 Jun 2020 17:36:00 +0100 Subject: [PATCH] Only re-focus the reply link when reply is abandoned Bug: T252903 Change-Id: Iabac3eb2258ecd48f61e027950446f59dca68df3 --- modules/CommentController.js | 6 ++++-- modules/dt.ui.ReplyWidget.js | 7 ++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/modules/CommentController.js b/modules/CommentController.js index 62d6b590a..8f1e77e42 100644 --- a/modules/CommentController.js +++ b/modules/CommentController.js @@ -241,7 +241,7 @@ CommentController.prototype.setupReplyWidget = function ( replyWidget, initialVa this.replyWidget = replyWidget; }; -CommentController.prototype.teardown = function () { +CommentController.prototype.teardown = function ( abandoned ) { this.$replyLinkButtons.removeClass( 'dt-init-replylink-active' ); this.$pageContainer.removeClass( 'dt-init-replylink-open' ); // eslint-disable-next-line no-jquery/no-global-selector @@ -255,7 +255,9 @@ CommentController.prototype.teardown = function () { } modifier.removeAddedListItem( this.newListItem ); this.newListItem = null; - this.$replyLink.trigger( 'focus' ); + if ( abandoned ) { + this.$replyLink.trigger( 'focus' ); + } }; CommentController.prototype.postReply = function ( parsoidData ) { diff --git a/modules/dt.ui.ReplyWidget.js b/modules/dt.ui.ReplyWidget.js index 083746b67..b8e8ded94 100644 --- a/modules/dt.ui.ReplyWidget.js +++ b/modules/dt.ui.ReplyWidget.js @@ -316,7 +316,7 @@ ReplyWidget.prototype.tryTeardown = function () { } ); } promise.then( function () { - widget.teardown(); + widget.teardown( true ); } ); return this; }; @@ -324,16 +324,17 @@ ReplyWidget.prototype.tryTeardown = function () { /** * Teardown the widget * + * @param {boolean} [abandoned] Widget was torn down after a reply was abandoned * @chainable * @return {ReplyWidget} */ -ReplyWidget.prototype.teardown = function () { +ReplyWidget.prototype.teardown = function ( abandoned ) { this.unbindBeforeUnloadHandler(); this.clear(); this.storage.remove( this.storagePrefix + '/mode' ); this.storage.remove( this.storagePrefix + '/saveable' ); this.$preview.empty(); - this.emit( 'teardown' ); + this.emit( 'teardown', abandoned ); return this; };