2024-05-24 12:31:30 +00:00
|
|
|
const 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( {
|
2022-05-19 02:48:24 +00:00
|
|
|
toolbarConfig: { 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 = [
|
2022-05-11 16:37:08 +00:00
|
|
|
{
|
|
|
|
name: 'history',
|
|
|
|
include: [ 'undo' ]
|
|
|
|
},
|
2020-12-15 19:45:05 +00:00
|
|
|
{
|
|
|
|
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' ]
|
|
|
|
},
|
2021-02-28 22:13:56 +00:00
|
|
|
{
|
|
|
|
name: 'specialCharacter',
|
|
|
|
include: [ 'specialCharacter' ]
|
2022-11-07 13:01:11 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'other',
|
|
|
|
include: [ 'usernameCompletion' ]
|
2020-12-15 19:45:05 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
2019-11-05 14:07:50 +00:00
|
|
|
|
|
|
|
CommentTarget.static.importRules = ve.copy( CommentTarget.static.importRules );
|
2020-02-06 23:48:26 +00:00
|
|
|
|
2022-07-30 23:57:22 +00:00
|
|
|
CommentTarget.static.importRules.external.blacklist = ve.extendObject(
|
|
|
|
{},
|
|
|
|
CommentTarget.static.importRules.external.blacklist,
|
|
|
|
{
|
|
|
|
// Annotations
|
|
|
|
// Allow pasting external links
|
|
|
|
'link/mwExternal': false
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
CommentTarget.static.importRulesForReplyTool = ve.copy( CommentTarget.static.importRules );
|
|
|
|
|
|
|
|
CommentTarget.static.importRulesForReplyTool.external.conversions = ve.extendObject(
|
2020-02-06 23:48:26 +00:00
|
|
|
{},
|
2022-07-30 23:57:22 +00:00
|
|
|
CommentTarget.static.importRulesForReplyTool.external.conversions,
|
2020-02-06 23:48:26 +00:00
|
|
|
{
|
|
|
|
mwHeading: 'paragraph'
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2022-07-30 23:57:22 +00:00
|
|
|
CommentTarget.static.importRulesForReplyTool.external.blacklist = ve.extendObject(
|
2020-02-06 23:48:26 +00:00
|
|
|
{},
|
2022-07-30 23:57:22 +00:00
|
|
|
CommentTarget.static.importRulesForReplyTool.external.blacklist,
|
2020-02-06 23:48:26 +00:00
|
|
|
{
|
|
|
|
// 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
|
|
|
);
|
2024-08-06 16:39:44 +00:00
|
|
|
this.getToolbar().$element.prepend( this.getSurface().getToolbarDialogs( 'above' ).$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,
|
2022-07-30 23:57:22 +00:00
|
|
|
sequenceRegistry: config.mode === 'source' ? registries.wikitextSequenceRegistry :
|
|
|
|
this.replyWidget.isNewTopic ? registries.sequenceRegistry : registries.sequenceRegistryForReplyTool,
|
2020-09-21 20:13:35 +00:00
|
|
|
dataTransferHandlerFactory: config.mode === 'source' ? ve.ui.wikitextDataTransferHandlerFactory : ve.ui.dataTransferHandlerFactory,
|
2022-07-30 23:57:22 +00:00
|
|
|
importRules: this.replyWidget.isNewTopic ? this.constructor.static.importRules : this.constructor.static.importRulesForReplyTool,
|
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;
|