mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-12-18 02:51:26 +00:00
ee69365b82
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
51 lines
1.5 KiB
JavaScript
51 lines
1.5 KiB
JavaScript
var commandRegistry, sequenceRegistry;
|
|
|
|
// Adapted from ve.ui.MWWikitextDataTransferHandlerFactory
|
|
function importRegistry( parent, child ) {
|
|
var name;
|
|
// Copy existing items
|
|
for ( name in parent.registry ) {
|
|
child.register( parent.registry[ name ] );
|
|
}
|
|
// Copy any new items when they're added
|
|
parent.on( 'register', function ( name, data ) {
|
|
child.register( data );
|
|
} );
|
|
}
|
|
|
|
// Create new registries so that we can override the behavior for signatures
|
|
// without affecting normal VisualEditor.
|
|
commandRegistry = new ve.ui.CommandRegistry();
|
|
importRegistry( ve.ui.commandRegistry, commandRegistry );
|
|
sequenceRegistry = new ve.ui.SequenceRegistry();
|
|
importRegistry( ve.ui.sequenceRegistry, sequenceRegistry );
|
|
|
|
// Command to insert signature node. Unlike normal VisualEditor, we want to select
|
|
// the node (collapseToEnd=false), because we want to show its context menu.
|
|
commandRegistry.unregister( 'mwSignature' );
|
|
commandRegistry.register(
|
|
new ve.ui.Command( 'dtMwSignature', 'content', 'insert', {
|
|
args: [
|
|
[
|
|
{ type: 'dtMwSignature' },
|
|
{ type: '/dtMwSignature' }
|
|
],
|
|
// annotate
|
|
false,
|
|
// collapseToEnd
|
|
false
|
|
],
|
|
supportedSelections: [ 'linear' ]
|
|
} )
|
|
);
|
|
// Unlike normal VisualEditor, this is registered regardless of the namespace.
|
|
sequenceRegistry.unregister( 'wikitextSignature' );
|
|
sequenceRegistry.register(
|
|
new ve.ui.Sequence( 'dtWikitextSignature', 'dtMwSignature', '~~~~', 4 )
|
|
);
|
|
|
|
module.exports = {
|
|
commandRegistry: commandRegistry,
|
|
sequenceRegistry: sequenceRegistry
|
|
};
|