From cc5976e8db290fb9246e65af83018ee19055242f Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Mon, 13 Jan 2020 19:29:07 +0000 Subject: [PATCH] Fix handler again Sepatate #teardown and #tryTeardown methods to make it obvious what they do. Have call #tryTeardown like the cancel button. Change-Id: Ica0f3295bfee378bcd15d0b6a3ccea3c7917ad9b --- modules/dt.ui.ReplyWidget.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/modules/dt.ui.ReplyWidget.js b/modules/dt.ui.ReplyWidget.js index 7c6f046ac..d0f0a2e08 100644 --- a/modules/dt.ui.ReplyWidget.js +++ b/modules/dt.ui.ReplyWidget.js @@ -37,7 +37,7 @@ function ReplyWidget( comment, config ) { // Events this.replyButton.connect( this, { click: 'onReplyClick' } ); - this.cancelButton.connect( this, { click: [ 'teardown', true ] } ); + this.cancelButton.connect( this, { click: 'tryTeardown' } ); this.$element.on( 'keydown', this.onKeyDown.bind( this ) ); this.beforeUnloadHandler = this.onBeforeUnload.bind( this ); @@ -112,10 +112,11 @@ ReplyWidget.prototype.setup = function () { this.bindBeforeUnloadHandler(); }; -ReplyWidget.prototype.teardown = function ( confirm ) { +ReplyWidget.prototype.tryTeardown = function () { var promise, widget = this; - if ( confirm && !this.isEmpty() ) { + + if ( !this.isEmpty() ) { // TODO: Override messages in dialog to be more ReplyWidget specific promise = OO.ui.getWindowManager().openWindow( 'abandonedit' ) .closed.then( function ( data ) { @@ -127,16 +128,20 @@ ReplyWidget.prototype.teardown = function ( confirm ) { promise = $.Deferred().resolve().promise(); } promise.then( function () { - widget.unbindBeforeUnloadHandler(); - widget.clear(); - widget.$preview.empty(); - widget.emit( 'teardown' ); + widget.teardown(); } ); }; +ReplyWidget.prototype.teardown = function () { + this.unbindBeforeUnloadHandler(); + this.clear(); + this.$preview.empty(); + this.emit( 'teardown' ); +}; + ReplyWidget.prototype.onKeyDown = function ( e ) { if ( e.which === OO.ui.Keys.ESCAPE ) { - this.emit( 'teardown' ); + this.tryTeardown(); return false; } };