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
|
2020-08-07 17:18:21 +00:00
|
|
|
* @param {string} commentId
|
|
|
|
* @param {string} pageName
|
|
|
|
* @param {number} oldId
|
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
|
|
|
|
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 ) {
|
2020-07-13 16:45:06 +00:00
|
|
|
var textInput = new OO.ui.MultilineTextInputWidget( $.extend( {
|
2019-11-05 14:07:50 +00:00
|
|
|
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 ) );
|
2020-07-13 16:45:06 +00:00
|
|
|
// Fix jquery.ime position (T255191)
|
|
|
|
textInput.$input.addClass( 'ime-position-inside' );
|
|
|
|
return textInput;
|
2019-11-05 14:07:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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-29 16:43:11 +00:00
|
|
|
this.replyBodyWidget.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.onInputChange = function () {
|
|
|
|
var wikitext;
|
|
|
|
|
|
|
|
// Parent method
|
|
|
|
ReplyWidgetPlain.super.prototype.onInputChange.apply( this, arguments );
|
|
|
|
|
|
|
|
wikitext = this.getValue();
|
|
|
|
this.storage.set( this.storagePrefix + '/body', wikitext );
|
|
|
|
};
|
|
|
|
|
2020-04-29 16:43:11 +00:00
|
|
|
ReplyWidgetPlain.prototype.setup = function ( initialValue ) {
|
|
|
|
var autosaveValue = this.storage.get( this.storagePrefix + '/body' );
|
|
|
|
|
2020-02-19 01:25:38 +00:00
|
|
|
// Parent method
|
|
|
|
ReplyWidgetPlain.super.prototype.setup.call( this );
|
|
|
|
|
2020-05-17 20:12:23 +00:00
|
|
|
// Events
|
|
|
|
this.replyBodyWidget.connect( this, { change: this.onInputChangeThrottled } );
|
2020-04-27 16:23:27 +00:00
|
|
|
|
2020-04-29 16:43:11 +00:00
|
|
|
this.replyBodyWidget.setValue( initialValue || autosaveValue );
|
|
|
|
|
2020-06-04 17:19:46 +00:00
|
|
|
// needs to bind after the initial setValue:
|
|
|
|
this.replyBodyWidget.once( 'change', this.onFirstTransaction.bind( this ) );
|
|
|
|
|
2020-04-29 16:43:11 +00:00
|
|
|
this.afterSetup();
|
|
|
|
|
2020-04-27 16:23:27 +00:00
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
ReplyWidgetPlain.prototype.teardown = function () {
|
2020-05-17 20:12:23 +00:00
|
|
|
this.replyBodyWidget.disconnect( this );
|
2020-04-27 16:23:27 +00:00
|
|
|
this.replyBodyWidget.off( 'change' );
|
|
|
|
|
2020-05-08 22:01:17 +00:00
|
|
|
this.storage.remove( this.storagePrefix + '/body' );
|
|
|
|
|
2020-04-27 16:23:27 +00:00
|
|
|
// 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();
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = ReplyWidgetPlain;
|