Difference between revisions of "MediaWiki:Gadget-Section creator.js"
Jump to navigation
Jump to search
Line 1: | Line 1: | ||
function makeMyTool() { | function makeMyTool() { | ||
//Create and register command | //Create and register command | ||
var commandName = 'mycommand'; | |||
var myTemplate = [ { | var myTemplate = [ { | ||
type: 'mwTransclusionBlock', | type: 'mwTransclusionBlock', | ||
Line 25: | Line 28: | ||
ve.ui.commandRegistry.register( | ve.ui.commandRegistry.register( | ||
new ve.ui.Command( | new ve.ui.Command( commandName, 'content', 'insert', { | ||
args: [ myTemplate, false, true ], | args: [ myTemplate, false, true ], | ||
supportedSelections: [ 'linear' ] | supportedSelections: [ 'linear' ] | ||
} ) | } ) | ||
); | ); | ||
//Create and register tool | //Create and register tool | ||
Line 50: | Line 43: | ||
MyTool.static.group = 'insert'; | MyTool.static.group = 'insert'; | ||
MyTool.static.title = 'My tool'; | MyTool.static.title = 'My tool'; | ||
MyTool.static.commandName = | MyTool.static.commandName = commandName; | ||
ve.ui.toolFactory.register( MyTool ); | ve.ui.toolFactory.register( MyTool ); | ||
Revision as of 16:59, 2 December 2021
function makeMyTool() { //Create and register command var commandName = 'mycommand'; var myTemplate = [ { type: 'mwTransclusionBlock', attributes: { mw: { parts: [ { template: { target: { href: 'Template:MyTemplate', wt: 'MyTemplate' }, params: { 1: { wt: 'my parameter' } } } } ] } } }, { type: '/mwTransclusionBlock' } ]; ve.ui.commandRegistry.register( new ve.ui.Command( commandName, 'content', 'insert', { args: [ myTemplate, false, true ], supportedSelections: [ 'linear' ] } ) ); //Create and register tool function MyTool() { MyTool.parent.apply( this, arguments ); } OO.inheritClass( MyTool, ve.ui.MWTransclusionDialogTool ); MyTool.static.name = 'mytool'; MyTool.static.group = 'insert'; MyTool.static.title = 'My tool'; MyTool.static.commandName = commandName; ve.ui.toolFactory.register( MyTool ); } //Initialize mw.hook( 've.loadModules' ).add( function( addPlugin ) { addPlugin( function() { return mw.loader.using( [ 'ext.visualEditor.core', 'ext.visualEditor.mwwikitext', 'ext.visualEditor.mwtransclusion' ] ) .then( function() { makeMyTool(); } ); } ); } );