2021-04-08 13:46:09 +00:00
|
|
|
var registries = require( './dt.ui.registries.js' );
|
2020-04-08 18:23:22 +00:00
|
|
|
|
2019-11-05 14:07:50 +00:00
|
|
|
/**
|
|
|
|
* DiscussionTools-specific target, inheriting from the stand-alone target
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends ve.init.mw.Target
|
|
|
|
*
|
2021-02-28 22:06:12 +00:00
|
|
|
* @param {mw.dt.ReplyWidgetVisual} replyWidget
|
2019-11-05 14:07:50 +00:00
|
|
|
* @param {Object} config Configuration options
|
|
|
|
*/
|
2021-02-28 22:06:12 +00:00
|
|
|
function CommentTarget( replyWidget, config ) {
|
2019-11-05 14:07:50 +00:00
|
|
|
config = config || {};
|
|
|
|
|
2021-02-28 22:06:12 +00:00
|
|
|
this.replyWidget = replyWidget;
|
|
|
|
|
2019-11-05 14:07:50 +00:00
|
|
|
// Parent constructor
|
|
|
|
CommentTarget.super.call( this, ve.extendObject( {
|
2020-04-27 15:42:35 +00:00
|
|
|
toolbarConfig: { actions: true, $overlay: true, position: 'top' }
|
2019-11-05 14:07:50 +00:00
|
|
|
}, config ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
OO.inheritClass( CommentTarget, ve.init.mw.Target );
|
|
|
|
|
|
|
|
/* Static methods */
|
|
|
|
|
|
|
|
CommentTarget.static.name = 'discussionTools';
|
|
|
|
|
|
|
|
CommentTarget.static.modes = [ 'visual', 'source' ];
|
|
|
|
|
2020-12-15 19:45:05 +00:00
|
|
|
if ( OO.ui.isMobile() ) {
|
|
|
|
// Mobile currently expects one tool per group
|
|
|
|
CommentTarget.static.toolbarGroups = [
|
|
|
|
{
|
|
|
|
name: 'style',
|
|
|
|
classes: [ 've-test-toolbar-style' ],
|
|
|
|
type: 'list',
|
|
|
|
icon: 'textStyle',
|
|
|
|
title: OO.ui.deferMsg( 'visualeditor-toolbar-style-tooltip' ),
|
|
|
|
label: OO.ui.deferMsg( 'visualeditor-toolbar-style-tooltip' ),
|
|
|
|
invisibleLabel: true,
|
|
|
|
include: [ { group: 'textStyle' }, 'language', 'clear' ],
|
|
|
|
forceExpand: [ 'bold', 'italic', 'clear' ],
|
|
|
|
promote: [ 'bold', 'italic' ],
|
|
|
|
demote: [ 'strikethrough', 'code', 'underline', 'language', 'clear' ]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'link',
|
|
|
|
include: [ 'link' ]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'other',
|
|
|
|
include: [ 'usernameCompletion' ]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'editMode',
|
|
|
|
type: 'list',
|
|
|
|
icon: 'edit',
|
|
|
|
title: OO.ui.deferMsg( 'visualeditor-mweditmode-tooltip' ),
|
|
|
|
label: OO.ui.deferMsg( 'visualeditor-mweditmode-tooltip' ),
|
|
|
|
invisibleLabel: true,
|
|
|
|
include: [ 'editModeVisual', 'editModeSource' ]
|
|
|
|
}
|
|
|
|
];
|
|
|
|
} else {
|
|
|
|
CommentTarget.static.toolbarGroups = [
|
|
|
|
{
|
|
|
|
name: 'style',
|
|
|
|
title: OO.ui.deferMsg( 'visualeditor-toolbar-style-tooltip' ),
|
|
|
|
include: [ 'bold', 'italic', 'moreTextStyle' ]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'link',
|
|
|
|
include: [ 'link' ]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'other',
|
|
|
|
include: [ 'usernameCompletion' ]
|
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
2019-11-05 14:07:50 +00:00
|
|
|
|
|
|
|
CommentTarget.static.importRules = ve.copy( CommentTarget.static.importRules );
|
2020-02-06 23:48:26 +00:00
|
|
|
|
|
|
|
CommentTarget.static.importRules.external.conversions = ve.extendObject(
|
|
|
|
{},
|
|
|
|
CommentTarget.static.importRules.external.conversions,
|
|
|
|
{
|
|
|
|
mwHeading: 'paragraph'
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
CommentTarget.static.importRules.external.blacklist = ve.extendObject(
|
|
|
|
{},
|
|
|
|
CommentTarget.static.importRules.external.blacklist,
|
|
|
|
{
|
|
|
|
// Annotations
|
|
|
|
// Allow pasting external links
|
|
|
|
'link/mwExternal': false,
|
|
|
|
// Strip all table structure
|
|
|
|
mwTable: true,
|
|
|
|
tableSection: true,
|
|
|
|
tableRow: true,
|
|
|
|
tableCell: true
|
|
|
|
}
|
|
|
|
);
|
2019-11-05 14:07:50 +00:00
|
|
|
|
|
|
|
CommentTarget.prototype.attachToolbar = function () {
|
2021-02-28 22:08:54 +00:00
|
|
|
this.replyWidget.$headerWrapper.append(
|
2020-12-15 19:45:05 +00:00
|
|
|
this.getToolbar().$element.append( this.replyWidget.modeTabSelect ? this.replyWidget.modeTabSelect.$element : null )
|
2021-02-28 22:08:54 +00:00
|
|
|
);
|
|
|
|
this.getToolbar().$element.prepend( this.getSurface().getToolbarDialogs().$element );
|
2019-11-05 14:07:50 +00:00
|
|
|
};
|
|
|
|
|
2020-04-30 13:06:57 +00:00
|
|
|
CommentTarget.prototype.getSurfaceConfig = function ( config ) {
|
2020-09-21 20:13:35 +00:00
|
|
|
config = ve.extendObject( { mode: this.defaultMode }, config );
|
2020-04-30 13:06:57 +00:00
|
|
|
return CommentTarget.super.prototype.getSurfaceConfig.call( this, ve.extendObject( {
|
2020-09-21 20:13:35 +00:00
|
|
|
commandRegistry: config.mode === 'source' ? registries.wikitextCommandRegistry : registries.commandRegistry,
|
|
|
|
sequenceRegistry: config.mode === 'source' ? registries.wikitextSequenceRegistry : registries.sequenceRegistry,
|
|
|
|
dataTransferHandlerFactory: config.mode === 'source' ? ve.ui.wikitextDataTransferHandlerFactory : ve.ui.dataTransferHandlerFactory,
|
2020-04-30 13:06:57 +00:00
|
|
|
// eslint-disable-next-line no-jquery/no-global-selector
|
|
|
|
$overlayContainer: $( '#content' )
|
|
|
|
}, config ) );
|
|
|
|
};
|
|
|
|
|
2020-12-15 19:45:05 +00:00
|
|
|
CommentTarget.prototype.editSource = function () {
|
|
|
|
this.replyWidget.switch( 'source' );
|
|
|
|
};
|
|
|
|
|
|
|
|
CommentTarget.prototype.switchToVisualEditor = function () {
|
|
|
|
this.replyWidget.switch( 'visual' );
|
|
|
|
};
|
|
|
|
|
2019-11-05 14:07:50 +00:00
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.init.mw.targetFactory.register( CommentTarget );
|
|
|
|
|
|
|
|
module.exports = CommentTarget;
|