2019-11-05 14:07:50 +00:00
|
|
|
/**
|
|
|
|
* DiscussionTools ReplyWidgetPlain class
|
|
|
|
*
|
|
|
|
* @class mw.dt.ReplyWidgetPlain
|
|
|
|
* @extends mw.dt.ReplyWidget
|
|
|
|
* @constructor
|
2020-04-27 15:50:02 +00:00
|
|
|
* @param {Object} commentController
|
|
|
|
* @param {Object} parsoidData
|
2019-11-05 14:07:50 +00:00
|
|
|
* @param {Object} [config] Configuration options
|
|
|
|
*/
|
2020-04-27 15:50:02 +00:00
|
|
|
function ReplyWidgetPlain() {
|
2019-11-05 14:07:50 +00:00
|
|
|
// Parent constructor
|
2020-04-27 15:50:02 +00:00
|
|
|
ReplyWidgetPlain.super.apply( this, arguments );
|
2019-11-05 14:07:50 +00:00
|
|
|
|
|
|
|
// Events
|
|
|
|
this.replyBodyWidget.connect( this, { change: this.onInputChangeThrottled } );
|
2020-04-27 16:23:27 +00:00
|
|
|
|
|
|
|
this.$element.addClass( 'dt-ui-replyWidget-plain' );
|
2019-11-05 14:07:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
OO.inheritClass( ReplyWidgetPlain, require( 'ext.discussionTools.ReplyWidget' ) );
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
ReplyWidgetPlain.prototype.createReplyBodyWidget = function ( config ) {
|
|
|
|
return new OO.ui.MultilineTextInputWidget( $.extend( {
|
|
|
|
rows: 3,
|
2020-01-21 19:30:34 +00:00
|
|
|
// TODO: Fix upstream to support a value meaning no max limit (e.g. Infinity)
|
|
|
|
maxRows: 999,
|
2019-11-05 14:07:50 +00:00
|
|
|
autosize: true,
|
2020-04-10 12:57:51 +00:00
|
|
|
// The following classes are used here:
|
2019-11-05 14:07:50 +00:00
|
|
|
// * mw-editfont-monospace
|
|
|
|
// * mw-editfont-sans-serif
|
|
|
|
// * mw-editfont-serif
|
|
|
|
classes: [ 'mw-editfont-' + mw.user.options.get( 'editfont' ) ]
|
|
|
|
}, config ) );
|
|
|
|
};
|
|
|
|
|
|
|
|
ReplyWidgetPlain.prototype.focus = function () {
|
|
|
|
this.replyBodyWidget.focus();
|
2020-04-27 16:23:27 +00:00
|
|
|
|
|
|
|
return this;
|
2019-11-05 14:07:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ReplyWidgetPlain.prototype.clear = function () {
|
2019-12-11 04:40:17 +00:00
|
|
|
// Parent method
|
|
|
|
ReplyWidgetPlain.super.prototype.clear.apply( this, arguments );
|
|
|
|
|
2020-04-27 16:23:27 +00:00
|
|
|
this.setValue( '' );
|
2019-11-05 14:07:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ReplyWidgetPlain.prototype.isEmpty = function () {
|
|
|
|
return !this.replyBodyWidget.getValue().trim();
|
|
|
|
};
|
|
|
|
|
2020-04-02 15:43:49 +00:00
|
|
|
ReplyWidgetPlain.prototype.getMode = function () {
|
|
|
|
return 'source';
|
|
|
|
};
|
|
|
|
|
2020-04-10 12:57:51 +00:00
|
|
|
ReplyWidgetPlain.prototype.initAutoSave = function () {
|
|
|
|
var body;
|
|
|
|
this.storage = mw.storage.session;
|
|
|
|
this.storage.set( this.storagePrefix + '/class', 'ReplyWidgetPlain' );
|
|
|
|
if ( ( body = this.storage.get( this.storagePrefix + '/body' ) ) ) {
|
|
|
|
this.replyBodyWidget.setValue( body );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ReplyWidgetPlain.prototype.onInputChange = function () {
|
|
|
|
var wikitext;
|
|
|
|
|
|
|
|
// Parent method
|
|
|
|
ReplyWidgetPlain.super.prototype.onInputChange.apply( this, arguments );
|
|
|
|
|
|
|
|
wikitext = this.getValue();
|
|
|
|
this.storage.set( this.storagePrefix + '/body', wikitext );
|
|
|
|
};
|
|
|
|
|
2020-02-19 01:25:38 +00:00
|
|
|
ReplyWidgetPlain.prototype.setup = function () {
|
|
|
|
// Parent method
|
|
|
|
ReplyWidgetPlain.super.prototype.setup.call( this );
|
|
|
|
|
|
|
|
this.replyBodyWidget.once( 'change', this.onFirstTransaction.bind( this ) );
|
2020-04-27 16:23:27 +00:00
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
ReplyWidgetPlain.prototype.teardown = function () {
|
|
|
|
this.replyBodyWidget.off( 'change' );
|
|
|
|
|
|
|
|
// Parent method
|
|
|
|
return ReplyWidgetPlain.super.prototype.teardown.call( this );
|
2020-02-19 01:25:38 +00:00
|
|
|
};
|
|
|
|
|
2019-11-05 14:07:50 +00:00
|
|
|
ReplyWidgetPlain.prototype.onKeyDown = function ( e ) {
|
|
|
|
// Parent method
|
|
|
|
ReplyWidgetPlain.super.prototype.onKeyDown.call( this, e );
|
|
|
|
|
|
|
|
if ( e.which === OO.ui.Keys.ENTER && ( e.ctrlKey || e.metaKey ) ) {
|
|
|
|
this.onReplyClick();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ReplyWidgetPlain.prototype.setPending = function ( pending ) {
|
|
|
|
// Parent method
|
|
|
|
ReplyWidgetPlain.super.prototype.setPending.call( this, pending );
|
|
|
|
|
|
|
|
if ( pending ) {
|
|
|
|
this.replyBodyWidget.pushPending();
|
|
|
|
this.replyBodyWidget.setDisabled( true );
|
|
|
|
} else {
|
|
|
|
this.replyBodyWidget.popPending();
|
|
|
|
this.replyBodyWidget.setDisabled( false );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ReplyWidgetPlain.prototype.getValue = function () {
|
|
|
|
return this.replyBodyWidget.getValue();
|
|
|
|
};
|
|
|
|
|
2020-04-27 16:23:27 +00:00
|
|
|
ReplyWidgetPlain.prototype.setValue = function ( value ) {
|
|
|
|
this.replyBodyWidget.setValue( value );
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2019-11-05 14:07:50 +00:00
|
|
|
module.exports = ReplyWidgetPlain;
|