ReplyWidget: Replace .mode with #getMode

.mode was only set the end of the constructor.

Change-Id: I1a14167d1b2e524742da31f78c6cbfaf96aec667
This commit is contained in:
Ed Sanders 2020-04-02 16:43:49 +01:00 committed by Bartosz Dziewoński
parent c5e9185ae7
commit 5597787eb4
3 changed files with 16 additions and 9 deletions

View file

@ -113,9 +113,7 @@ ReplyWidget.prototype.getValue = null;
ReplyWidget.prototype.isEmpty = null;
ReplyWidget.prototype.getMode = function () {
return this.mode;
};
ReplyWidget.prototype.getMode = null;
ReplyWidget.prototype.clear = function () {
if ( this.errorMessage ) {
@ -193,7 +191,7 @@ ReplyWidget.prototype.onInputChange = function () {
this.replyButton.setDisabled( this.isEmpty() );
if ( this.mode !== 'source' ) {
if ( this.getMode() !== 'source' ) {
return;
}

View file

@ -11,8 +11,6 @@ function ReplyWidgetPlain( comment, config ) {
// Parent constructor
ReplyWidgetPlain.super.call( this, comment, config );
this.mode = 'source';
// Events
this.replyBodyWidget.connect( this, { change: this.onInputChangeThrottled } );
}
@ -52,6 +50,10 @@ ReplyWidgetPlain.prototype.isEmpty = function () {
return !this.replyBodyWidget.getValue().trim();
};
ReplyWidgetPlain.prototype.getMode = function () {
return 'source';
};
ReplyWidgetPlain.prototype.setup = function () {
// Parent method
ReplyWidgetPlain.super.prototype.setup.call( this );

View file

@ -13,6 +13,9 @@ var
function ReplyWidgetVisual( comment, config ) {
// Parent constructor
ReplyWidgetVisual.super.call( this, comment, config );
// TODO: Use user preference
this.defaultMode = 'source';
}
/* Inheritance */
@ -23,7 +26,7 @@ OO.inheritClass( ReplyWidgetVisual, require( 'ext.discussionTools.ReplyWidget' )
ReplyWidgetVisual.prototype.createReplyBodyWidget = function ( config ) {
return new CommentTargetWidget( $.extend( {
defaultMode: 'source'
defaultMode: this.defaultMode
}, config ) );
};
@ -49,6 +52,12 @@ ReplyWidgetVisual.prototype.isEmpty = function () {
return !surface || !surface.getModel().hasBeenModified();
};
ReplyWidgetVisual.prototype.getMode = function () {
return this.replyBodyWidget.target.getSurface() ?
this.replyBodyWidget.target.getSurface().getMode() :
this.defaultMode;
};
ReplyWidgetVisual.prototype.setup = function () {
var surface;
@ -59,8 +68,6 @@ ReplyWidgetVisual.prototype.setup = function () {
surface = this.replyBodyWidget.target.getSurface();
this.mode = surface.getMode();
// Events
surface.getModel().getDocument()
.connect( this, { transact: this.onInputChangeThrottled } )