| 1 |
const utils = require( 'ext.discussionTools.init' ).utils; |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
function ReplyWidgetPlain() { |
| 14 |
|
| 15 |
ReplyWidgetPlain.super.apply( this, arguments ); |
| 16 |
|
| 17 |
if ( OO.ui.isMobile() ) { |
| 18 |
const toolFactory = new OO.ui.ToolFactory(), |
| 19 |
toolGroupFactory = new OO.ui.ToolGroupFactory(); |
| 20 |
|
| 21 |
toolFactory.register( mw.libs.ve.MWEditModeVisualTool ); |
| 22 |
toolFactory.register( mw.libs.ve.MWEditModeSourceTool ); |
| 23 |
this.switchToolbar = new OO.ui.Toolbar( toolFactory, toolGroupFactory, { |
| 24 |
classes: [ 'ext-discussiontools-ui-replyWidget-editSwitch' ] |
| 25 |
} ); |
| 26 |
|
| 27 |
this.switchToolbar.on( 'switchEditor', ( mode ) => { |
| 28 |
this.switch( mode ); |
| 29 |
} ); |
| 30 |
|
| 31 |
this.switchToolbar.setup( [ { |
| 32 |
name: 'editMode', |
| 33 |
type: 'list', |
| 34 |
icon: 'edit', |
| 35 |
title: mw.msg( 'visualeditor-mweditmode-tooltip' ), |
| 36 |
label: mw.msg( 'visualeditor-mweditmode-tooltip' ), |
| 37 |
invisibleLabel: true, |
| 38 |
include: [ 'editModeVisual', 'editModeSource' ] |
| 39 |
} ] ); |
| 40 |
|
| 41 |
this.switchToolbar.emit( 'updateState' ); |
| 42 |
|
| 43 |
this.$headerWrapper.append( this.switchToolbar.$element ); |
| 44 |
} |
| 45 |
|
| 46 |
this.$element.addClass( 'ext-discussiontools-ui-replyWidget-plain' ); |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
OO.inheritClass( ReplyWidgetPlain, require( './dt.ui.ReplyWidget.js' ) ); |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
ReplyWidgetPlain.prototype.createReplyBodyWidget = function ( config ) { |
| 59 |
const textInput = new OO.ui.MultilineTextInputWidget( Object.assign( { |
| 60 |
rows: 3, |
| 61 |
|
| 62 |
maxRows: 999, |
| 63 |
autosize: true, |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
classes: [ 'mw-editfont-' + mw.user.options.get( 'editfont' ) ] |
| 69 |
}, config ) ); |
| 70 |
textInput.$input.attr( 'aria-label', config.placeholder ); |
| 71 |
|
| 72 |
textInput.$input.addClass( 'ime-position-inside' ); |
| 73 |
|
| 74 |
return textInput; |
| 75 |
}; |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
ReplyWidgetPlain.prototype.focus = function () { |
| 81 |
this.replyBodyWidget.focus(); |
| 82 |
|
| 83 |
return this; |
| 84 |
}; |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
ReplyWidgetPlain.prototype.clear = function ( preserveStorage ) { |
| 90 |
this.replyBodyWidget.setValue( '' ); |
| 91 |
|
| 92 |
if ( !preserveStorage ) { |
| 93 |
this.storage.remove( 'body' ); |
| 94 |
} |
| 95 |
|
| 96 |
|
| 97 |
ReplyWidgetPlain.super.prototype.clear.apply( this, arguments ); |
| 98 |
}; |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
ReplyWidgetPlain.prototype.isEmpty = function () { |
| 104 |
return utils.htmlTrim( this.replyBodyWidget.getValue() ) === ''; |
| 105 |
}; |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
ReplyWidgetPlain.prototype.getMode = function () { |
| 111 |
return 'source'; |
| 112 |
}; |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
ReplyWidgetPlain.prototype.onInputChange = function () { |
| 118 |
if ( this.isTornDown ) { |
| 119 |
|
| 120 |
return; |
| 121 |
} |
| 122 |
|
| 123 |
|
| 124 |
ReplyWidgetPlain.super.prototype.onInputChange.apply( this, arguments ); |
| 125 |
|
| 126 |
const wikitext = this.getValue(); |
| 127 |
this.storage.set( 'body', wikitext ); |
| 128 |
}; |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
ReplyWidgetPlain.prototype.setup = function ( data ) { |
| 134 |
const autosaveValue = this.storage.get( 'body' ); |
| 135 |
|
| 136 |
data = data || {}; |
| 137 |
|
| 138 |
|
| 139 |
ReplyWidgetPlain.super.prototype.setup.apply( this, arguments ); |
| 140 |
|
| 141 |
|
| 142 |
this.replyBodyWidget.connect( this, { change: this.onInputChangeThrottled } ); |
| 143 |
this.replyBodyWidget.$input.on( 'focus', this.emit.bind( this, 'bodyFocus' ) ); |
| 144 |
|
| 145 |
this.replyBodyWidget.setValue( data.value || autosaveValue ); |
| 146 |
|
| 147 |
|
| 148 |
this.replyBodyWidget.once( 'change', this.onFirstChange.bind( this ) ); |
| 149 |
|
| 150 |
this.afterSetup(); |
| 151 |
|
| 152 |
return this; |
| 153 |
}; |
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
ReplyWidgetPlain.prototype.teardown = function () { |
| 159 |
this.replyBodyWidget.disconnect( this ); |
| 160 |
this.replyBodyWidget.off( 'change' ); |
| 161 |
|
| 162 |
|
| 163 |
return ReplyWidgetPlain.super.prototype.teardown.apply( this, arguments ); |
| 164 |
}; |
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
ReplyWidgetPlain.prototype.getValue = function () { |
| 170 |
return this.replyBodyWidget.getValue(); |
| 171 |
}; |
| 172 |
|
| 173 |
module.exports = ReplyWidgetPlain; |