| 1 |
const CommentTargetWidget = require( './dt-ve/CommentTargetWidget.js' ); |
| 2 |
|
| 3 |
require( './dt-ve/dt.ui.MWSignatureContextItem.js' ); |
| 4 |
require( './dt-ve/dt.dm.MWSignatureNode.js' ); |
| 5 |
require( './dt-ve/dt.ce.MWSignatureNode.js' ); |
| 6 |
require( './dt-ve/dt.ui.UsernameCompletionAction.js' ); |
| 7 |
require( './dt-ve/dt.ui.UsernameCompletionTool.js' ); |
| 8 |
require( './dt-ve/dt.dm.PingNode.js' ); |
| 9 |
require( './dt-ve/dt.ce.PingNode.js' ); |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
function ReplyWidgetVisual( commentController, commentDetails, config ) { |
| 23 |
this.defaultMode = config.mode; |
| 24 |
|
| 25 |
|
| 26 |
ReplyWidgetVisual.super.apply( this, arguments ); |
| 27 |
|
| 28 |
|
| 29 |
this.$element.addClass( 'ext-discussiontools-ui-replyWidget-ve' ); |
| 30 |
} |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
OO.inheritClass( ReplyWidgetVisual, require( './dt.ui.ReplyWidget.js' ) ); |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
ReplyWidgetVisual.prototype.createReplyBodyWidget = function ( config ) { |
| 42 |
return new CommentTargetWidget( this, Object.assign( { |
| 43 |
defaultMode: this.defaultMode |
| 44 |
}, config ) ); |
| 45 |
}; |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
ReplyWidgetVisual.prototype.getValue = function () { |
| 51 |
if ( this.getMode() === 'source' ) { |
| 52 |
return this.replyBodyWidget.target.getSurface().getModel().getDom(); |
| 53 |
} else { |
| 54 |
return this.replyBodyWidget.target.getSurface().getHtml(); |
| 55 |
} |
| 56 |
}; |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
ReplyWidgetVisual.prototype.clear = function ( preserveStorage ) { |
| 62 |
if ( !preserveStorage ) { |
| 63 |
this.replyBodyWidget.target.clearDocState(); |
| 64 |
} |
| 65 |
|
| 66 |
this.replyBodyWidget.clear(); |
| 67 |
|
| 68 |
|
| 69 |
ReplyWidgetVisual.super.prototype.clear.apply( this, arguments ); |
| 70 |
}; |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
ReplyWidgetVisual.prototype.isEmpty = function () { |
| 76 |
const surface = this.replyBodyWidget.target.getSurface(); |
| 77 |
return !( surface && surface.getModel().getDocument().data.hasContent() ); |
| 78 |
}; |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
ReplyWidgetVisual.prototype.getMode = function () { |
| 84 |
return this.replyBodyWidget.target.getSurface() ? |
| 85 |
this.replyBodyWidget.target.getSurface().getMode() : |
| 86 |
this.defaultMode; |
| 87 |
}; |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
ReplyWidgetVisual.prototype.setup = function ( data, suppressNotifications ) { |
| 93 |
const target = this.replyBodyWidget.target; |
| 94 |
|
| 95 |
data = data || {}; |
| 96 |
|
| 97 |
let htmlOrDoc; |
| 98 |
if ( this.storage.get( 'saveable' ) ) { |
| 99 |
htmlOrDoc = this.storage.get( 've-dochtml' ); |
| 100 |
target.recovered = true; |
| 101 |
} else { |
| 102 |
htmlOrDoc = data.value; |
| 103 |
} |
| 104 |
|
| 105 |
htmlOrDoc = htmlOrDoc || ( this.getMode() === 'visual' ? '<p></p>' : '' ); |
| 106 |
|
| 107 |
target.originalHtml = htmlOrDoc instanceof HTMLDocument ? ve.properInnerHtml( htmlOrDoc.body ) : htmlOrDoc; |
| 108 |
target.fromEditedState = !!data.value; |
| 109 |
|
| 110 |
this.replyBodyWidget.setDocument( htmlOrDoc ); |
| 111 |
|
| 112 |
target.once( 'surfaceReady', () => { |
| 113 |
target.getSurface().getView().connect( this, { |
| 114 |
focus: [ 'emit', 'bodyFocus' ] |
| 115 |
} ); |
| 116 |
|
| 117 |
target.initAutosave( { |
| 118 |
suppressNotifications: suppressNotifications, |
| 119 |
storage: this.storage |
| 120 |
} ); |
| 121 |
this.afterSetup(); |
| 122 |
|
| 123 |
|
| 124 |
this.replyBodyWidget.once( 'change', this.onFirstChange.bind( this ) ); |
| 125 |
} ); |
| 126 |
|
| 127 |
|
| 128 |
ReplyWidgetVisual.super.prototype.setup.apply( this, arguments ); |
| 129 |
|
| 130 |
|
| 131 |
this.replyBodyWidget.connect( this, { |
| 132 |
change: 'onInputChangeThrottled', |
| 133 |
cancel: 'tryTeardown', |
| 134 |
submit: 'onReplyClick' |
| 135 |
} ); |
| 136 |
|
| 137 |
return this; |
| 138 |
}; |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
ReplyWidgetVisual.prototype.teardown = function () { |
| 144 |
this.replyBodyWidget.disconnect( this ); |
| 145 |
this.replyBodyWidget.off( 'change' ); |
| 146 |
|
| 147 |
|
| 148 |
return ReplyWidgetVisual.super.prototype.teardown.apply( this, arguments ); |
| 149 |
}; |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
ReplyWidgetVisual.prototype.focus = function () { |
| 155 |
const targetWidget = this.replyBodyWidget; |
| 156 |
setTimeout( () => { |
| 157 |
|
| 158 |
if ( targetWidget.getSurface() ) { |
| 159 |
targetWidget.getSurface().getView().selectLastSelectableContentOffset(); |
| 160 |
targetWidget.focus(); |
| 161 |
} |
| 162 |
} ); |
| 163 |
|
| 164 |
return this; |
| 165 |
}; |
| 166 |
|
| 167 |
module.exports = ReplyWidgetVisual; |