2020-06-18 13:49:01 +00:00
|
|
|
var CommentTargetWidget = require( './dt-ve/CommentTargetWidget.js' );
|
2019-11-05 14:07:50 +00:00
|
|
|
|
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-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 ReplyWidgetVisual() {
|
2020-04-29 18:45:20 +00:00
|
|
|
// TODO: Support 2017 wikitext editor
|
2020-04-27 16:23:27 +00:00
|
|
|
this.defaultMode = 'visual';
|
|
|
|
this.initialValue = null;
|
|
|
|
|
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
|
|
|
|
this.$element.addClass( 'dt-ui-replyWidget-ve' );
|
2019-11-05 14:07:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
OO.inheritClass( ReplyWidgetVisual, require( 'ext.discussionTools.ReplyWidget' ) );
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
ReplyWidgetVisual.prototype.createReplyBodyWidget = function ( config ) {
|
|
|
|
return new CommentTargetWidget( $.extend( {
|
2020-04-02 15:43:49 +00:00
|
|
|
defaultMode: this.defaultMode
|
2019-11-05 14:07:50 +00:00
|
|
|
}, config ) );
|
|
|
|
};
|
|
|
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
ReplyWidgetVisual.prototype.clear = function () {
|
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
|
|
|
this.replyBodyWidget.clear();
|
|
|
|
};
|
|
|
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2020-04-02 15:43:49 +00:00
|
|
|
ReplyWidgetVisual.prototype.getMode = function () {
|
|
|
|
return this.replyBodyWidget.target.getSurface() ?
|
|
|
|
this.replyBodyWidget.target.getSurface().getMode() :
|
|
|
|
this.defaultMode;
|
|
|
|
};
|
|
|
|
|
2020-04-29 16:43:11 +00:00
|
|
|
ReplyWidgetVisual.prototype.setup = function ( initialValue ) {
|
|
|
|
var htmlOrDoc,
|
|
|
|
widget = this,
|
|
|
|
target = this.replyBodyWidget.target;
|
2020-04-10 12:57:51 +00:00
|
|
|
|
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 {
|
|
|
|
htmlOrDoc = initialValue || '<p></p>';
|
|
|
|
}
|
|
|
|
|
|
|
|
target.originalHtml = htmlOrDoc instanceof HTMLDocument ? ve.properInnerHtml( htmlOrDoc.body ) : htmlOrDoc;
|
|
|
|
target.fromEditedState = !!initialValue;
|
|
|
|
|
|
|
|
this.replyBodyWidget.setDocument( htmlOrDoc );
|
|
|
|
|
|
|
|
target.once( 'surfaceReady', function () {
|
|
|
|
target.getSurface().getModel().setAutosaveDocId( widget.storagePrefix );
|
|
|
|
target.initAutosave();
|
|
|
|
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:
|
|
|
|
widget.replyBodyWidget.once( 'change', widget.onFirstTransaction.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
|
|
|
|
ReplyWidgetVisual.super.prototype.setup.call( this );
|
|
|
|
|
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
|
|
|
|
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' );
|
2020-04-29 16:43:11 +00:00
|
|
|
// TODO: Just teardown the whole target?
|
|
|
|
this.replyBodyWidget.target.clearDocState();
|
2020-04-27 16:23:27 +00:00
|
|
|
|
|
|
|
// Parent method
|
|
|
|
return ReplyWidgetVisual.super.prototype.teardown.call( this );
|
2019-11-05 14:07:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ReplyWidgetVisual.prototype.focus = function () {
|
|
|
|
var targetWidget = this.replyBodyWidget;
|
|
|
|
setTimeout( function () {
|
|
|
|
targetWidget.getSurface().getModel().selectLastContentOffset();
|
|
|
|
targetWidget.focus();
|
|
|
|
} );
|
2020-04-27 16:23:27 +00:00
|
|
|
|
|
|
|
return this;
|
2019-11-05 14:07:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ReplyWidgetVisual.prototype.setPending = function ( pending ) {
|
|
|
|
ReplyWidgetVisual.super.prototype.setPending.call( this, pending );
|
|
|
|
|
|
|
|
if ( pending ) {
|
2020-04-27 16:23:27 +00:00
|
|
|
this.replyBodyWidget.pushPending();
|
2019-11-05 14:07:50 +00:00
|
|
|
this.replyBodyWidget.setReadOnly( true );
|
|
|
|
} else {
|
2020-04-27 16:23:27 +00:00
|
|
|
this.replyBodyWidget.popPending();
|
2019-11-05 14:07:50 +00:00
|
|
|
this.replyBodyWidget.setReadOnly( false );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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;
|