Difference between revisions of "MediaWiki:Gadget-Section creator.js"

From TermiKnowledge
Jump to navigation Jump to search
Line 3: Line 3:
var commandName = 'mycommand';
var commandName = 'mycommand';
var title = 'Insert Section';
var myTemplate = [ {
var myTemplate = [ {
Line 42: Line 43:
MyTool.static.name = 'mytool';
MyTool.static.name = 'mytool';
MyTool.static.group = 'insert';
MyTool.static.group = 'insert';
MyTool.static.title = 'My tool';
MyTool.static.title = title;
MyTool.static.commandName = commandName;
MyTool.static.commandName = commandName;
ve.ui.toolFactory.register( MyTool );
ve.ui.toolFactory.register( MyTool );

Revision as of 17:00, 2 December 2021

function makeMyTool() {
	//Create and register command
	
	var commandName = 'mycommand';
	var title = 'Insert Section';
	
	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 = title;
	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();
			} );
	} );
} );