Debian Codegraph @

extensions/DiscussionTools/modules/dt-ve/CommentTargetWidget.js

raw symbols SCIP
1 require( './CommentTarget.js' );
2
3 /**
4 * DiscussionTools TargetWidget class
5 *
6 * @class
7 * @extends ve.ui.MWTargetWidget
8 *
9 * @constructor
10 * @param {mw.dt.ReplyWidgetVisual} replyWidget
11 * @param {Object} [config] Configuration options
12 */
13 function CommentTargetWidget( replyWidget, config ) {
14 const excludeCommands = [
15 'blockquoteWrap', // T258194
16 // Disable to allow Tab/Shift+Tab to move focus out of the widget (T172694)
17 'indent',
18 'outdent',
19 // Save commands get loaded from articletarget module, which we load
20 // to get the edit switching tool for mobile
21 'showSave',
22 'showChanges',
23 'showPreview',
24 'saveMinoredit',
25 'saveWatchthis'
26 ];
27
28 if ( !replyWidget.isNewTopic ) {
29 excludeCommands.push(
30 // Disable commands for things whose wikitext markup doesn't work when indented
31 'heading1',
32 'heading2',
33 'heading3',
34 'heading4',
35 'heading5',
36 'heading6',
37 'insertTable',
38 'transclusionFromSequence', // T253667
39 'preformatted'
40 );
41 }
42
43 config = Object.assign( {
44 excludeCommands: excludeCommands
45 }, config );
46
47 this.replyWidget = replyWidget;
48 this.authors = config.authors;
49
50 // Parent constructor
51 CommentTargetWidget.super.call( this, config );
52
53 // Initialization
54 this.$element.addClass( 'ext-discussiontools-ui-targetWidget' );
55 }
56
57 /* Inheritance */
58
59 OO.inheritClass( CommentTargetWidget, ve.ui.MWTargetWidget );
60
61 /**
62 * @inheritdoc
63 */
64 CommentTargetWidget.prototype.createTarget = function () {
65 return ve.init.mw.targetFactory.create( 'discussionTools', this.replyWidget, {
66 // A lot of places expect ve.init.target to exist...
67 register: true,
68 toolbarGroups: this.toolbarGroups,
69 modes: this.modes,
70 defaultMode: this.defaultMode
71 } );
72 };
73
74 /**
75 * @inheritdoc
76 */
77 CommentTargetWidget.prototype.setDocument = function ( docOrHtml ) {
78 const mode = this.target.getDefaultMode(),
79 doc = ( mode === 'visual' && typeof docOrHtml === 'string' ) ?
80 this.target.parseDocument( docOrHtml ) :
81 docOrHtml,
82 // TODO: This could be upstreamed:
83 dmDoc = this.target.constructor.static.createModelFromDom( doc, mode );
84
85 // Parent method
86 CommentTargetWidget.super.prototype.setDocument.call( this, dmDoc );
87
88 // Remove MW specific classes as the widget is already inside the content area
89 this.getSurface().getView().$element.removeClass( 'mw-body-content' );
90 this.getSurface().$placeholder.removeClass( 'mw-body-content' );
91
92 // Fix jquery.ime position (T255191)
93 this.getSurface().getView().getDocument().getDocumentNode().$element.addClass( 'ime-position-inside' );
94
95 // HACK
96 this.getSurface().authors = this.authors;
97 };
98
99 module.exports = CommentTargetWidget;