2020-08-13 09:28:39 +00:00
|
|
|
/**
|
|
|
|
* @external CommentController
|
|
|
|
* @external CommentItem
|
|
|
|
*/
|
|
|
|
|
2019-11-05 14:07:50 +00:00
|
|
|
/**
|
|
|
|
* DiscussionTools ReplyWidgetPlain class
|
|
|
|
*
|
|
|
|
* @class mw.dt.ReplyWidgetPlain
|
|
|
|
* @extends mw.dt.ReplyWidget
|
|
|
|
* @constructor
|
2020-08-13 09:28:39 +00:00
|
|
|
* @param {CommentController} commentController
|
|
|
|
* @param {CommentItem} comment
|
2020-08-19 20:03:41 +00:00
|
|
|
* @param {string} pageName
|
|
|
|
* @param {number} oldId
|
2020-08-13 09:28:39 +00:00
|
|
|
* @param {Object} [config]
|
2019-11-05 14:07:50 +00:00
|
|
|
*/
|
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
|
|
|
|
2021-03-13 14:39:39 +00:00
|
|
|
this.$element.addClass( 'ext-discussiontools-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 ) );
|
2021-03-17 17:54:55 +00:00
|
|
|
textInput.$input.attr( 'aria-label', config.placeholder );
|
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 () {
|
2020-08-19 20:03:41 +00:00
|
|
|
this.replyBodyWidget.setValue( '' );
|
|
|
|
|
|
|
|
this.storage.remove( this.storagePrefix + '/body' );
|
|
|
|
|
2019-12-11 04:40:17 +00:00
|
|
|
// Parent method
|
|
|
|
ReplyWidgetPlain.super.prototype.clear.apply( this, arguments );
|
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-09-25 17:08:08 +00:00
|
|
|
ReplyWidgetPlain.prototype.setup = function ( data ) {
|
2020-04-29 16:43:11 +00:00
|
|
|
var autosaveValue = this.storage.get( this.storagePrefix + '/body' );
|
|
|
|
|
2020-09-25 17:08:08 +00:00
|
|
|
data = data || {};
|
|
|
|
|
2020-02-19 01:25:38 +00:00
|
|
|
// Parent method
|
2020-09-25 17:08:08 +00:00
|
|
|
ReplyWidgetPlain.super.prototype.setup.apply( this, arguments );
|
2020-02-19 01:25:38 +00:00
|
|
|
|
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-09-25 17:08:08 +00:00
|
|
|
this.replyBodyWidget.setValue( data.value || autosaveValue );
|
2020-04-29 16:43:11 +00:00
|
|
|
|
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' );
|
|
|
|
|
|
|
|
// 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.getValue = function () {
|
|
|
|
return this.replyBodyWidget.getValue();
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = ReplyWidgetPlain;
|