2020-04-27 15:50:02 +00:00
|
|
|
var CommentTargetWidget = require( './CommentTargetWidget.js' );
|
2019-11-05 14:07:50 +00:00
|
|
|
|
2019-12-10 16:18:24 +00:00
|
|
|
require( './dt.ui.UsernameCompletion.js' );
|
|
|
|
|
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() {
|
2019-11-05 14:07:50 +00:00
|
|
|
// Parent constructor
|
2020-04-27 15:50:02 +00:00
|
|
|
ReplyWidgetVisual.super.apply( this, arguments );
|
2020-04-02 15:43:49 +00:00
|
|
|
|
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;
|
|
|
|
|
|
|
|
// 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
|
|
|
};
|
|
|
|
|
2020-04-27 16:23:27 +00:00
|
|
|
ReplyWidgetVisual.prototype.setValue = function ( value ) {
|
|
|
|
var target = this.replyBodyWidget.target;
|
|
|
|
if ( target && target.getSurface() ) {
|
|
|
|
target.setDocument( value );
|
|
|
|
} else {
|
|
|
|
// #setup hasn't been called yet, just save the value for when it is
|
|
|
|
this.initialValue = value;
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
};
|
2020-03-06 15:18:30 +00:00
|
|
|
|
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-10 12:57:51 +00:00
|
|
|
ReplyWidgetVisual.prototype.initAutoSave = function () {
|
|
|
|
// TODO: Implement
|
|
|
|
};
|
|
|
|
|
2019-11-05 14:07:50 +00:00
|
|
|
ReplyWidgetVisual.prototype.setup = function () {
|
2020-04-27 16:23:27 +00:00
|
|
|
this.replyBodyWidget.setDocument( this.initialValue || '<p></p>' );
|
|
|
|
this.initialValue = null;
|
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'
|
|
|
|
} );
|
2020-04-27 16:23:27 +00:00
|
|
|
this.replyBodyWidget.once( 'change', this.onFirstTransaction.bind( this ) );
|
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' );
|
|
|
|
|
|
|
|
// 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 );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = ReplyWidgetVisual;
|