2020-06-18 13:49:01 +00:00
|
|
|
var CommentTargetWidget = require( './dt-ve/CommentTargetWidget.js' );
|
2019-11-05 14:07:50 +00:00
|
|
|
|
2020-04-08 18:23:22 +00:00
|
|
|
require( './dt-ve/dt.ui.MWSignatureContextItem.js' );
|
|
|
|
require( './dt-ve/dt.dm.MWSignatureNode.js' );
|
|
|
|
require( './dt-ve/dt.ce.MWSignatureNode.js' );
|
2020-06-18 13:49:01 +00:00
|
|
|
require( './dt-ve/dt.ui.UsernameCompletionAction.js' );
|
|
|
|
require( './dt-ve/dt.ui.UsernameCompletionTool.js' );
|
2020-06-26 16:23:07 +00:00
|
|
|
require( './dt-ve/dt.dm.PingNode.js' );
|
|
|
|
require( './dt-ve/dt.ce.PingNode.js' );
|
2019-12-10 16:18:24 +00:00
|
|
|
|
2019-11-05 14:07:50 +00:00
|
|
|
/**
|
|
|
|
* DiscussionTools ReplyWidgetVisual class
|
|
|
|
*
|
|
|
|
* @class mw.dt.ReplyWidgetVisual
|
|
|
|
* @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]
|
2021-12-20 15:58:01 +00:00
|
|
|
* @param {string} [config.mode] Default edit mode, 'source' or 'visual'
|
2019-11-05 14:07:50 +00:00
|
|
|
*/
|
2021-12-20 17:06:24 +00:00
|
|
|
function ReplyWidgetVisual( commentController, commentDetails, config ) {
|
2020-09-21 20:13:35 +00:00
|
|
|
this.defaultMode = config.mode;
|
2020-04-27 16:23:27 +00:00
|
|
|
|
2020-05-22 12:20:06 +00:00
|
|
|
// Parent constructor
|
|
|
|
ReplyWidgetVisual.super.apply( this, arguments );
|
|
|
|
|
2020-04-27 16:23:27 +00:00
|
|
|
// TODO: Rename this widget to VE, as it isn't just visual mode
|
2021-03-13 14:39:39 +00:00
|
|
|
this.$element.addClass( 'ext-discussiontools-ui-replyWidget-ve' );
|
2019-11-05 14:07:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
OO.inheritClass( ReplyWidgetVisual, require( 'ext.discussionTools.ReplyWidget' ) );
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
2021-12-20 15:58:01 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2019-11-05 14:07:50 +00:00
|
|
|
ReplyWidgetVisual.prototype.createReplyBodyWidget = function ( config ) {
|
2021-02-28 22:06:12 +00:00
|
|
|
return new CommentTargetWidget( this, $.extend( {
|
2020-04-02 15:43:49 +00:00
|
|
|
defaultMode: this.defaultMode
|
2019-11-05 14:07:50 +00:00
|
|
|
}, config ) );
|
|
|
|
};
|
|
|
|
|
2021-12-20 15:58:01 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2019-11-05 14:07:50 +00:00
|
|
|
ReplyWidgetVisual.prototype.getValue = function () {
|
2020-03-06 15:18:30 +00:00
|
|
|
if ( this.getMode() === 'source' ) {
|
|
|
|
return this.replyBodyWidget.target.getSurface().getModel().getDom();
|
|
|
|
} else {
|
|
|
|
return this.replyBodyWidget.target.getSurface().getHtml();
|
|
|
|
}
|
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
|
|
|
ReplyWidgetVisual.prototype.clear = function ( preserveStorage ) {
|
|
|
|
if ( !preserveStorage ) {
|
|
|
|
this.replyBodyWidget.target.clearDocState();
|
|
|
|
}
|
2022-02-02 16:16:18 +00:00
|
|
|
// #clear removes all the surfaces, so must be done after #clearDocState
|
|
|
|
this.replyBodyWidget.clear();
|
2020-08-19 20:03:41 +00:00
|
|
|
|
2019-12-11 04:40:17 +00:00
|
|
|
// Parent method
|
|
|
|
ReplyWidgetVisual.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
|
|
|
ReplyWidgetVisual.prototype.isEmpty = function () {
|
|
|
|
var surface = this.replyBodyWidget.target.getSurface();
|
2020-04-29 15:30:57 +00:00
|
|
|
return !( surface && surface.getModel().getDocument().data.hasContent() );
|
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
|
|
|
ReplyWidgetVisual.prototype.getMode = function () {
|
|
|
|
return this.replyBodyWidget.target.getSurface() ?
|
|
|
|
this.replyBodyWidget.target.getSurface().getMode() :
|
|
|
|
this.defaultMode;
|
|
|
|
};
|
|
|
|
|
2021-12-20 15:58:01 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2022-02-22 23:10:43 +00:00
|
|
|
ReplyWidgetVisual.prototype.setup = function ( data, suppressNotifications ) {
|
2021-04-08 13:46:09 +00:00
|
|
|
var widget = this,
|
2020-04-29 16:43:11 +00:00
|
|
|
target = this.replyBodyWidget.target;
|
2020-04-10 12:57:51 +00:00
|
|
|
|
2020-09-25 17:08:08 +00:00
|
|
|
data = data || {};
|
|
|
|
|
2021-04-08 13:46:09 +00:00
|
|
|
var htmlOrDoc;
|
2020-04-29 16:43:11 +00:00
|
|
|
if ( this.storage.get( this.storagePrefix + '/saveable' ) ) {
|
|
|
|
htmlOrDoc = this.storage.get( this.storagePrefix + '/ve-dochtml' );
|
|
|
|
target.recovered = true;
|
|
|
|
} else {
|
2022-02-02 16:15:50 +00:00
|
|
|
htmlOrDoc = data.value;
|
2020-04-29 16:43:11 +00:00
|
|
|
}
|
|
|
|
|
2022-02-02 16:15:50 +00:00
|
|
|
htmlOrDoc = htmlOrDoc || ( this.getMode() === 'visual' ? '<p></p>' : '' );
|
|
|
|
|
2020-04-29 16:43:11 +00:00
|
|
|
target.originalHtml = htmlOrDoc instanceof HTMLDocument ? ve.properInnerHtml( htmlOrDoc.body ) : htmlOrDoc;
|
2020-09-25 17:08:08 +00:00
|
|
|
target.fromEditedState = !!data.value;
|
2020-04-29 16:43:11 +00:00
|
|
|
|
|
|
|
this.replyBodyWidget.setDocument( htmlOrDoc );
|
|
|
|
|
|
|
|
target.once( 'surfaceReady', function () {
|
2021-09-01 19:04:57 +00:00
|
|
|
target.getSurface().getView().connect( widget, {
|
|
|
|
focus: [ 'emit', 'bodyFocus' ]
|
|
|
|
} );
|
|
|
|
|
2020-04-29 16:43:11 +00:00
|
|
|
target.getSurface().getModel().setAutosaveDocId( widget.storagePrefix );
|
2022-02-22 23:10:43 +00:00
|
|
|
target.initAutosave( suppressNotifications );
|
2020-04-29 16:43:11 +00:00
|
|
|
widget.afterSetup();
|
2020-06-04 17:19:46 +00:00
|
|
|
|
|
|
|
// This needs to bind after surfaceReady so any initial population doesn't trigger it early:
|
2021-12-20 15:58:01 +00:00
|
|
|
widget.replyBodyWidget.once( 'change', widget.onFirstChange.bind( widget ) );
|
2020-04-29 16:43:11 +00:00
|
|
|
} );
|
2020-03-02 17:05:14 +00:00
|
|
|
|
2019-11-05 14:07:50 +00:00
|
|
|
// Parent method
|
2020-09-25 17:08:08 +00:00
|
|
|
ReplyWidgetVisual.super.prototype.setup.apply( this, arguments );
|
2019-11-05 14:07:50 +00:00
|
|
|
|
2020-05-17 20:12:23 +00:00
|
|
|
// Events
|
|
|
|
this.replyBodyWidget.connect( this, {
|
|
|
|
change: 'onInputChangeThrottled',
|
|
|
|
submit: 'onReplyClick'
|
|
|
|
} );
|
2019-11-05 14:07:50 +00:00
|
|
|
|
2020-04-27 16:23:27 +00:00
|
|
|
return this;
|
|
|
|
};
|
2020-03-02 17:05:14 +00:00
|
|
|
|
2021-12-20 15:58:01 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2020-04-27 16:23:27 +00:00
|
|
|
ReplyWidgetVisual.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 ReplyWidgetVisual.super.prototype.teardown.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
|
|
|
ReplyWidgetVisual.prototype.focus = function () {
|
|
|
|
var targetWidget = this.replyBodyWidget;
|
|
|
|
setTimeout( function () {
|
2020-09-21 19:52:47 +00:00
|
|
|
// Check surface still exists after timeout
|
|
|
|
if ( targetWidget.getSurface() ) {
|
|
|
|
targetWidget.getSurface().getModel().selectLastContentOffset();
|
|
|
|
targetWidget.focus();
|
|
|
|
}
|
2019-11-05 14:07:50 +00:00
|
|
|
} );
|
2020-04-27 16:23:27 +00:00
|
|
|
|
|
|
|
return this;
|
2019-11-05 14:07:50 +00:00
|
|
|
};
|
|
|
|
|
2020-05-06 22:03:16 +00:00
|
|
|
ve.trackSubscribe( 'activity.', function ( topic, data ) {
|
|
|
|
mw.track( 'dt.schemaVisualEditorFeatureUse', ve.extendObject( data, {
|
|
|
|
feature: topic.split( '.' )[ 1 ]
|
|
|
|
} ) );
|
|
|
|
} );
|
|
|
|
|
2019-11-05 14:07:50 +00:00
|
|
|
module.exports = ReplyWidgetVisual;
|