2019-11-05 14:07:50 +00:00
|
|
|
var
|
|
|
|
CommentTargetWidget = require( './CommentTargetWidget.js' );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DiscussionTools ReplyWidgetVisual class
|
|
|
|
*
|
|
|
|
* @class mw.dt.ReplyWidgetVisual
|
|
|
|
* @extends mw.dt.ReplyWidget
|
|
|
|
* @constructor
|
|
|
|
* @param {Object} comment Parsed comment object
|
|
|
|
* @param {Object} [config] Configuration options
|
|
|
|
*/
|
|
|
|
function ReplyWidgetVisual( comment, config ) {
|
|
|
|
// Parent constructor
|
|
|
|
ReplyWidgetVisual.super.call( this, comment, config );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
OO.inheritClass( ReplyWidgetVisual, require( 'ext.discussionTools.ReplyWidget' ) );
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
ReplyWidgetVisual.prototype.createReplyBodyWidget = function ( config ) {
|
|
|
|
return new CommentTargetWidget( $.extend( {
|
|
|
|
defaultMode: 'source'
|
|
|
|
}, 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-03-06 15:18:30 +00:00
|
|
|
// TODO: Implement getMode to get current mode from surface
|
|
|
|
|
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();
|
|
|
|
return !surface || !surface.getModel().hasBeenModified();
|
|
|
|
};
|
|
|
|
|
|
|
|
ReplyWidgetVisual.prototype.setup = function () {
|
2020-03-02 17:05:14 +00:00
|
|
|
var surface;
|
|
|
|
|
2019-11-05 14:07:50 +00:00
|
|
|
// Parent method
|
|
|
|
ReplyWidgetVisual.super.prototype.setup.call( this );
|
|
|
|
|
|
|
|
this.replyBodyWidget.setDocument( '<p></p>' );
|
|
|
|
|
2020-03-02 17:05:14 +00:00
|
|
|
surface = this.replyBodyWidget.target.getSurface();
|
|
|
|
|
|
|
|
this.mode = surface.getMode();
|
2019-11-05 14:07:50 +00:00
|
|
|
|
|
|
|
// Events
|
2020-03-02 17:05:14 +00:00
|
|
|
surface.getModel().getDocument()
|
|
|
|
.connect( this, { transact: this.onInputChangeThrottled } )
|
2020-02-19 01:25:38 +00:00
|
|
|
.once( 'transact', this.onFirstTransaction.bind( this ) );
|
2020-03-02 17:05:14 +00:00
|
|
|
surface.connect( this, { submit: 'onReplyClick' } );
|
2019-11-05 14:07:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ReplyWidgetVisual.prototype.focus = function () {
|
|
|
|
var targetWidget = this.replyBodyWidget;
|
|
|
|
setTimeout( function () {
|
|
|
|
targetWidget.getSurface().getModel().selectLastContentOffset();
|
|
|
|
targetWidget.focus();
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
|
|
|
ReplyWidgetVisual.prototype.setPending = function ( pending ) {
|
|
|
|
ReplyWidgetVisual.super.prototype.setPending.call( this, pending );
|
|
|
|
|
|
|
|
if ( pending ) {
|
|
|
|
// TODO
|
|
|
|
// this.replyBodyWidget.pushPending();
|
|
|
|
this.replyBodyWidget.setReadOnly( true );
|
|
|
|
} else {
|
|
|
|
// this.replyBodyWidget.popPending();
|
|
|
|
this.replyBodyWidget.setReadOnly( false );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = ReplyWidgetVisual;
|