User:Ontone/js/veInsertCommentTool.js

From mediawiki.org

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/**
 * Adds 'Insert comment' tool to VisualEditor.
 *
 * [[MediaWiki:Gadgets-definition]] registration:
 * * veInsertCommentTool[default|ResourceLoader|dependencies=ext.visualEditor.core]|veInsertCommentTool.js
 *
 * Licence: GPLv3+
 */
 
 mw.loader.using( 'ext.visualEditor.desktopArticleTarget.init', function () {
  mw.libs.ve.addPlugin( function () {

/* Localization */
if(!mw.messages.exists('InsertCommentTool-toolname')) {
  mw.messages.set('InsertCommentTool-toolname', 'Insert comment');
}

InsertCommentTool = function VeUiInsertCommentTool() {
  InsertCommentTool.super.apply( this, arguments );
};
OO.inheritClass( InsertCommentTool, ve.ui.Tool );

InsertCommentTool.static.name = 'insertComment';
InsertCommentTool.static.group = 'insert';
InsertCommentTool.static.autoAddToGroup = false;
InsertCommentTool.static.autoAddToCatchall = false;
InsertCommentTool.static.icon = 'align-float-left';
InsertCommentTool.static.title = mw.msg('InsertCommentTool-toolname');

InsertCommentTool.static.commandName = 'insertComment';
ve.ui.toolFactory.register( InsertCommentTool );

ve.ui.commandRegistry.register(
	new ve.ui.Command(
		'insertComment', 'content', 'insert',
		{
			args: [
				[
					{ type: 'table' },
					{ type: 'tableSection', attributes: { style: 'body' } },
					{ type: 'tableRow' },
					{ type: 'tableCell', attributes: { style: 'data' } },
						{ type: 'paragraph' }, 'Comment', { type: '/paragraph' },
					{ type: '/tableCell' },
					{ type: '/tableRow' },
					{ type: 'tableRow' },
					{ type: 'tableCell', attributes: { style: 'data' } },
						{ type: 'paragraph' }, { type: 'mwSignature' }, { type: '/mwSignature' }, { type: '/paragraph' },
					{ type: '/tableCell' },
					{ type: '/tableRow' },
					{ type: '/tableSection' },
					{ type: '/table' },
				],
				// Annotate content to match surrounding annotations?
				false,
				// Move cursor to after the new content? (otherwise - select it)
				true
			],
			supportedSelections: [ 'linear' ]
		}
	)
);

ve.ui.triggerRegistry.register(
  'insertComment', {
    mac: new ve.ui.Trigger( 'cmd+shift+2' ),
    pc: new ve.ui.Trigger( 'ctrl+shift+2' )
  }
);

ve.init.mw.Target.static.toolbarGroups.push ( {
    include: [ 'insertComment' ]
} );

  } ); // mw.libs.ve.addPlugin
}); // mw.loader.using