| 1 |
const registries = require( './dt.ui.registries.js' ); |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
function CommentTarget( replyWidget, config ) { |
| 13 |
config = config || {}; |
| 14 |
|
| 15 |
this.replyWidget = replyWidget; |
| 16 |
|
| 17 |
|
| 18 |
CommentTarget.super.call( this, ve.extendObject( { |
| 19 |
toolbarConfig: { position: 'top' } |
| 20 |
}, config ) ); |
| 21 |
} |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
OO.inheritClass( CommentTarget, ve.init.mw.Target ); |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
CommentTarget.static.name = 'discussionTools'; |
| 30 |
|
| 31 |
CommentTarget.static.modes = [ 'visual', 'source' ]; |
| 32 |
|
| 33 |
if ( OO.ui.isMobile() ) { |
| 34 |
|
| 35 |
CommentTarget.static.toolbarGroups = [ |
| 36 |
{ |
| 37 |
name: 'history', |
| 38 |
include: [ 'undo' ] |
| 39 |
}, |
| 40 |
{ |
| 41 |
name: 'style', |
| 42 |
classes: [ 've-test-toolbar-style' ], |
| 43 |
type: 'list', |
| 44 |
icon: 'textStyle', |
| 45 |
title: OO.ui.deferMsg( 'visualeditor-toolbar-style-tooltip' ), |
| 46 |
label: OO.ui.deferMsg( 'visualeditor-toolbar-style-tooltip' ), |
| 47 |
invisibleLabel: true, |
| 48 |
include: [ { group: 'textStyle' }, 'language', 'clear' ], |
| 49 |
forceExpand: [ 'bold', 'italic', 'clear' ], |
| 50 |
promote: [ 'bold', 'italic' ], |
| 51 |
demote: [ 'strikethrough', 'code', 'underline', 'language', 'clear' ] |
| 52 |
}, |
| 53 |
{ |
| 54 |
name: 'link', |
| 55 |
include: [ 'link' ] |
| 56 |
}, |
| 57 |
{ |
| 58 |
name: 'other', |
| 59 |
include: [ 'usernameCompletion' ] |
| 60 |
}, |
| 61 |
{ |
| 62 |
name: 'editMode', |
| 63 |
type: 'list', |
| 64 |
icon: 'edit', |
| 65 |
title: OO.ui.deferMsg( 'visualeditor-mweditmode-tooltip' ), |
| 66 |
label: OO.ui.deferMsg( 'visualeditor-mweditmode-tooltip' ), |
| 67 |
invisibleLabel: true, |
| 68 |
include: [ 'editModeVisual', 'editModeSource' ] |
| 69 |
} |
| 70 |
]; |
| 71 |
} else { |
| 72 |
CommentTarget.static.toolbarGroups = [ |
| 73 |
{ |
| 74 |
name: 'style', |
| 75 |
title: OO.ui.deferMsg( 'visualeditor-toolbar-style-tooltip' ), |
| 76 |
include: [ 'bold', 'italic', 'moreTextStyle' ] |
| 77 |
}, |
| 78 |
{ |
| 79 |
name: 'link', |
| 80 |
include: [ 'link' ] |
| 81 |
}, |
| 82 |
{ |
| 83 |
name: 'specialCharacter', |
| 84 |
include: [ 'specialCharacter' ] |
| 85 |
}, |
| 86 |
{ |
| 87 |
name: 'other', |
| 88 |
include: [ 'usernameCompletion' ] |
| 89 |
} |
| 90 |
]; |
| 91 |
} |
| 92 |
|
| 93 |
CommentTarget.static.importRules = ve.copy( CommentTarget.static.importRules ); |
| 94 |
|
| 95 |
CommentTarget.static.importRules.external.blacklist = ve.extendObject( |
| 96 |
{}, |
| 97 |
CommentTarget.static.importRules.external.blacklist, |
| 98 |
{ |
| 99 |
|
| 100 |
|
| 101 |
'link/mwExternal': false |
| 102 |
} |
| 103 |
); |
| 104 |
|
| 105 |
CommentTarget.static.importRulesForReplyTool = ve.copy( CommentTarget.static.importRules ); |
| 106 |
|
| 107 |
CommentTarget.static.importRulesForReplyTool.external.conversions = ve.extendObject( |
| 108 |
{}, |
| 109 |
CommentTarget.static.importRulesForReplyTool.external.conversions, |
| 110 |
{ |
| 111 |
mwHeading: 'paragraph' |
| 112 |
} |
| 113 |
); |
| 114 |
|
| 115 |
CommentTarget.static.importRulesForReplyTool.external.blacklist = ve.extendObject( |
| 116 |
{}, |
| 117 |
CommentTarget.static.importRulesForReplyTool.external.blacklist, |
| 118 |
{ |
| 119 |
|
| 120 |
mwTable: true, |
| 121 |
tableSection: true, |
| 122 |
tableRow: true, |
| 123 |
tableCell: true |
| 124 |
} |
| 125 |
); |
| 126 |
|
| 127 |
CommentTarget.prototype.attachToolbar = function () { |
| 128 |
this.replyWidget.$headerWrapper.append( |
| 129 |
this.getToolbar().$element.append( this.replyWidget.modeTabSelect ? this.replyWidget.modeTabSelect.$element : null ) |
| 130 |
); |
| 131 |
this.getToolbar().$element.prepend( this.getSurface().getToolbarDialogs( 'above' ).$element ); |
| 132 |
}; |
| 133 |
|
| 134 |
CommentTarget.prototype.getSurfaceConfig = function ( config ) { |
| 135 |
config = ve.extendObject( { mode: this.defaultMode }, config ); |
| 136 |
return CommentTarget.super.prototype.getSurfaceConfig.call( this, ve.extendObject( { |
| 137 |
commandRegistry: config.mode === 'source' ? registries.wikitextCommandRegistry : registries.commandRegistry, |
| 138 |
sequenceRegistry: config.mode === 'source' ? registries.wikitextSequenceRegistry : |
| 139 |
this.replyWidget.isNewTopic ? registries.sequenceRegistry : registries.sequenceRegistryForReplyTool, |
| 140 |
dataTransferHandlerFactory: config.mode === 'source' ? ve.ui.wikitextDataTransferHandlerFactory : ve.ui.dataTransferHandlerFactory, |
| 141 |
importRules: this.replyWidget.isNewTopic ? this.constructor.static.importRules : this.constructor.static.importRulesForReplyTool, |
| 142 |
|
| 143 |
$overlayContainer: $( '#content' ) |
| 144 |
}, config ) ); |
| 145 |
}; |
| 146 |
|
| 147 |
CommentTarget.prototype.editSource = function () { |
| 148 |
this.replyWidget.switch( 'source' ); |
| 149 |
}; |
| 150 |
|
| 151 |
CommentTarget.prototype.switchToVisualEditor = function () { |
| 152 |
this.replyWidget.switch( 'visual' ); |
| 153 |
}; |
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
ve.init.mw.targetFactory.register( CommentTarget ); |
| 158 |
|
| 159 |
module.exports = CommentTarget; |