mediawiki-extensions-Discus.../modules/dt-ve/CommentTarget.js
Bartosz Dziewoński ee69365b82 Signature handling in visual mode
Load 'ext.visualEditor.mwsignature' (which implements VE's existing
handling for signatures), then subclass and override a bunch of things
in order to:

* Replace the context menu with a note that you don't need to type the
  signature when commenting using the reply widget

* Override the sequence/command to insert signature so that it selects
  it afterwards and thus displays the context menu

* Treat signatures as signature nodes when switching from wikitext,
  instead of the normal pre-save transform turning them into regular
  links and text

Bug: T255738
Change-Id: Icb542451c2307ab51e56bd627804096c7b5552c8
2020-07-16 01:32:19 +02:00

90 lines
2.1 KiB
JavaScript

var
registries = require( './dt.ui.registries.js' );
/**
* DiscussionTools-specific target, inheriting from the stand-alone target
*
* @class
* @extends ve.init.mw.Target
*
* @param {Object} config Configuration options
*/
function CommentTarget( config ) {
config = config || {};
// Parent constructor
CommentTarget.super.call( this, ve.extendObject( {
toolbarConfig: { actions: true, $overlay: true, position: 'top' }
}, config ) );
}
/* Inheritance */
OO.inheritClass( CommentTarget, ve.init.mw.Target );
/* Static methods */
CommentTarget.static.name = 'discussionTools';
CommentTarget.static.modes = [ 'visual', 'source' ];
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' ]
}
];
CommentTarget.static.importRules = ve.copy( CommentTarget.static.importRules );
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
}
);
CommentTarget.prototype.attachToolbar = function () {
this.$element.parent().parent().prepend( this.getToolbar().$element );
};
CommentTarget.prototype.getSurfaceConfig = function ( config ) {
return CommentTarget.super.prototype.getSurfaceConfig.call( this, ve.extendObject( {
commandRegistry: registries.commandRegistry,
sequenceRegistry: registries.sequenceRegistry,
// eslint-disable-next-line no-jquery/no-global-selector
$overlayContainer: $( '#content' )
}, config ) );
};
/* Registration */
ve.init.mw.targetFactory.register( CommentTarget );
module.exports = CommentTarget;