2024-05-24 12:31:30 +00:00
|
|
|
const utils = require( 'ext.discussionTools.init' ).utils;
|
2021-03-24 16:48:10 +00:00
|
|
|
|
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
|
2021-06-09 23:22:28 +00:00
|
|
|
* @param {CommentDetails} commentDetails
|
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
|
|
|
|
2020-12-15 19:45:05 +00:00
|
|
|
if ( OO.ui.isMobile() ) {
|
2024-05-24 12:20:50 +00:00
|
|
|
const toolFactory = new OO.ui.ToolFactory(),
|
2020-12-15 19:45:05 +00:00
|
|
|
toolGroupFactory = new OO.ui.ToolGroupFactory();
|
|
|
|
|
|
|
|
toolFactory.register( mw.libs.ve.MWEditModeVisualTool );
|
|
|
|
toolFactory.register( mw.libs.ve.MWEditModeSourceTool );
|
|
|
|
this.switchToolbar = new OO.ui.Toolbar( toolFactory, toolGroupFactory, {
|
|
|
|
classes: [ 'ext-discussiontools-ui-replyWidget-editSwitch' ]
|
|
|
|
} );
|
|
|
|
|
2024-04-18 18:37:58 +00:00
|
|
|
this.switchToolbar.on( 'switchEditor', ( mode ) => {
|
|
|
|
this.switch( mode );
|
2020-12-15 19:45:05 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
this.switchToolbar.setup( [ {
|
|
|
|
name: 'editMode',
|
|
|
|
type: 'list',
|
|
|
|
icon: 'edit',
|
|
|
|
title: mw.msg( 'visualeditor-mweditmode-tooltip' ),
|
|
|
|
label: mw.msg( 'visualeditor-mweditmode-tooltip' ),
|
|
|
|
invisibleLabel: true,
|
|
|
|
include: [ 'editModeVisual', 'editModeSource' ]
|
|
|
|
} ] );
|
|
|
|
|
|
|
|
this.switchToolbar.emit( 'updateState' );
|
|
|
|
|
|
|
|
this.$headerWrapper.append( this.switchToolbar.$element );
|
|
|
|
}
|
|
|
|
|
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 */
|
|
|
|
|
2023-10-13 10:58:12 +00:00
|
|
|
OO.inheritClass( ReplyWidgetPlain, require( './dt.ui.ReplyWidget.js' ) );
|
2019-11-05 14:07:50 +00:00
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
2021-12-20 15:58:01 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2019-11-05 14:07:50 +00:00
|
|
|
ReplyWidgetPlain.prototype.createReplyBodyWidget = function ( config ) {
|
2024-05-24 12:20:50 +00:00
|
|
|
const textInput = new OO.ui.MultilineTextInputWidget( Object.assign( {
|
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' );
|
2021-09-01 19:04:57 +00:00
|
|
|
|
2020-07-13 16:45:06 +00:00
|
|
|
return textInput;
|
2019-11-05 14:07:50 +00:00
|
|
|
};
|
|
|
|
|
2021-12-20 15:58:01 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
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
|
|
|
};
|
|
|
|
|
2021-12-20 15:58:01 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2022-02-02 16:15:50 +00:00
|
|
|
ReplyWidgetPlain.prototype.clear = function ( preserveStorage ) {
|
2020-08-19 20:03:41 +00:00
|
|
|
this.replyBodyWidget.setValue( '' );
|
|
|
|
|
2022-02-02 16:15:50 +00:00
|
|
|
if ( !preserveStorage ) {
|
2023-06-13 22:55:08 +00:00
|
|
|
this.storage.remove( 'body' );
|
2022-02-02 16:15:50 +00:00
|
|
|
}
|
2020-08-19 20:03:41 +00:00
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2021-12-20 15:58:01 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2019-11-05 14:07:50 +00:00
|
|
|
ReplyWidgetPlain.prototype.isEmpty = function () {
|
2021-03-24 16:48:10 +00:00
|
|
|
return utils.htmlTrim( this.replyBodyWidget.getValue() ) === '';
|
2019-11-05 14:07:50 +00:00
|
|
|
};
|
|
|
|
|
2021-12-20 15:58:01 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2020-04-02 15:43:49 +00:00
|
|
|
ReplyWidgetPlain.prototype.getMode = function () {
|
|
|
|
return 'source';
|
|
|
|
};
|
|
|
|
|
2021-12-20 15:58:01 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2020-04-10 12:57:51 +00:00
|
|
|
ReplyWidgetPlain.prototype.onInputChange = function () {
|
2022-09-03 04:55:42 +00:00
|
|
|
if ( this.isTornDown ) {
|
|
|
|
// Ignore calls after teardown, which would clear the auto-save or crash
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-10 12:57:51 +00:00
|
|
|
// Parent method
|
|
|
|
ReplyWidgetPlain.super.prototype.onInputChange.apply( this, arguments );
|
|
|
|
|
2024-05-24 12:20:50 +00:00
|
|
|
const wikitext = this.getValue();
|
2023-06-13 22:55:08 +00:00
|
|
|
this.storage.set( 'body', wikitext );
|
2020-04-10 12:57:51 +00:00
|
|
|
};
|
|
|
|
|
2021-12-20 15:58:01 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2020-09-25 17:08:08 +00:00
|
|
|
ReplyWidgetPlain.prototype.setup = function ( data ) {
|
2024-05-24 12:20:50 +00:00
|
|
|
const autosaveValue = this.storage.get( 'body' );
|
2020-04-29 16:43:11 +00:00
|
|
|
|
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 } );
|
2021-09-01 19:04:57 +00:00
|
|
|
this.replyBodyWidget.$input.on( 'focus', this.emit.bind( this, 'bodyFocus' ) );
|
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:
|
2021-12-20 15:58:01 +00:00
|
|
|
this.replyBodyWidget.once( 'change', this.onFirstChange.bind( this ) );
|
2020-06-04 17:19:46 +00:00
|
|
|
|
2020-04-29 16:43:11 +00:00
|
|
|
this.afterSetup();
|
|
|
|
|
2020-04-27 16:23:27 +00:00
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2021-12-20 15:58:01 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2020-04-27 16:23:27 +00:00
|
|
|
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
|
2022-02-02 16:15:50 +00:00
|
|
|
return ReplyWidgetPlain.super.prototype.teardown.apply( this, arguments );
|
2020-02-19 01:25:38 +00:00
|
|
|
};
|
|
|
|
|
2021-12-20 15:58:01 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2019-11-05 14:07:50 +00:00
|
|
|
ReplyWidgetPlain.prototype.getValue = function () {
|
|
|
|
return this.replyBodyWidget.getValue();
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = ReplyWidgetPlain;
|