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

From TermiKnowledge
Jump to navigation Jump to search
Line 1: Line 1:
//single install
function makeMyTool() {
const singleInstall = false;
var template = [
{
type: 'mwTransclusionBlock',
attributes: { mw: { parts: [
{
template: {
target: { href: 'Template:SectionBlock', wt: 'SectionBlock'},
params: { 1: { wt: 'name' }, 2: { wt: 'category' } }
}
}
] } }
},{ type: '/mwTransclusionBlock' } ];
var commandName = 'termi_section_creator';
ve.ui.commandRegistry.register(
new ve.ui.Command(commandName, 'content', 'insert', {args: [ template, false, true], supportedSelections: ['linear'] } )
);
function MyTool() {
MyTool.parent.apply( this, arguments );
}
OO.inheritClass( MyTool, ve.ui.MWTransclusionDialogTool );


if ((!singleInstall || window.SectionCreator) && mw.config.get('wgNamespaceNumber') >= 0) {
MyTool.static.name = 'mytool';
$(function() {
MyTool.static.group = 'insert';
var SectionCreator = {
MyTool.static.title = 'My tool';
install: function() {
MyTool.static.commandName = commandName;
var tool = document.getElementById('t-section_creator');
ve.ui.toolFactory.register( MyTool );
if (tool) tool.parentNode.removeChild(tool);
console.log('Section creator installed');
//set up toolbox link
mw.util.addPortletLink('p-tb', 'javascript:SectionCreator.shout();',
"Create section", 't-section_creator', null);
console.log('Section creator installed');
},
shout: function() {
console.log('aaaaa');
}
};
window.SectionCreator = SectionCreator;
SectionCreator.install();
});
}
}
mw.hook( 've.loadModules' ).add( function( addPlugin ) {
addPlugin( function() {
return mw.loader.using( [ 'ext.visualEditor.core', 'ext.visualEditor.mwtransclusion' ] )
.then( function() {
makeMyTool();
} );
} );
} );

Revision as of 16:55, 2 December 2021

function makeMyTool() {
	var template = [
	{
		type: 'mwTransclusionBlock',
		attributes: { mw: { parts: [
			{
				template: {
					target: { href: 'Template:SectionBlock', wt: 'SectionBlock'},
					params: { 1: { wt: 'name' }, 2: { wt: 'category' } }
				}
			}
		] } }
	},{ type: '/mwTransclusionBlock' } ];
	
	var commandName = 'termi_section_creator';
	
	ve.ui.commandRegistry.register(
		new ve.ui.Command(commandName, 'content', 'insert', {args: [ template, false, true], supportedSelections: ['linear'] } )
	);
	
	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 );
	
	console.log('Section creator installed');
}

mw.hook( 've.loadModules' ).add( function( addPlugin ) {
	addPlugin( function() {
		return mw.loader.using( [ 'ext.visualEditor.core', 'ext.visualEditor.mwtransclusion' ] )
			.then( function() {
				makeMyTool();
			} );
	} );
} );