Gadgets/VeExtendedBar

  • Summary: Adds a button for adding rlm template in the cursor position in VisualEditor.

More general info about Gadgets

Usage

edit

Use the new button in the toolbar to quickly add rlm template in the cursor position.

This script adds option for replace and replace all in VisualEditor.

Setup

edit

User setup

edit

Copy the following code to your common.js (in target project, that supports VisualEditor):

mw.libs.ve.addPlugin(function(){
/**
 * Adds direction mark tool to VE (for adding RLM) 
 */
(function () {
// localization for button name
if(!mw.messages.exists('DirectionTool-toolname')){
	mw.messages.set('DirectionTool-toolname', 'Add rlm template'); // translate it!
}
// localization for rlm template name
if(!mw.config.exists('rlmTemplateName')){
	// translate it!
	if ( wgContentLanguage == "fa" ) {
		mw.config.set('rlmTemplateName', 'رچ');
	} else if ( wgContentLanguage == "he" ) {
		mw.config.set('rlmTemplateName', 'כ');
	} else if ( wgContentLanguage == "yi" ) {
		mw.config.set('rlmTemplateName', 'ר');
	} else {
		mw.config.set('rlmTemplateName', 'Rlm');
	}

}
//end of localization
 
function DirectionTool( toolGroup, config ) {
	OO.ui.Tool.call( this, toolGroup, config );
}
OO.inheritClass( DirectionTool, OO.ui.Tool );
 
DirectionTool.static.name = 'DirectionTool';
DirectionTool.static.title = mw.msg('DirectionTool-toolname');
 
DirectionTool.prototype.onSelect = function () {
	this.toolbar.getSurface().getModel().getFragment().collapseRangeToEnd().insertContent([{
		'type': 'mwTransclusionInline',
		'attributes': {
			'mw': {
				parts: [ {
					template: {
						target: {
							href: wgFormattedNamespaces[10]+ ':'+ mw.config.get('rlmTemplateName'),
							wt: mw.config.get('rlmTemplateName')
						},
						params: {}
					}
				}]
			}
		}
	}]);
};
 
DirectionTool.prototype.onUpdateState = function () {
	this.setActive( false );
};
 
ve.ui.toolFactory.register( DirectionTool );
 
})();

});

Locate the "translate it" above and correct the translation if required.

Project setup

edit

To turn it as a gadget that users can select in their preferences (requires sysop rights):

mw.libs.ve.addPlugin('ext.gadget.VeDirectionMarkTool');
*VeExtendedBar[ResourceLoader|dependencies=ext.visualEditor.viewPageTarget.init]|VeExtendedBar.js
*VeDirectionMarkTool[ResourceLoader|rights=hidden|hidden|dependencies=ext.visualEditor.core]|VeDirectionMarkTool.js|VeDirectionMarkTool.css

(notice the first line is just a loader for the real script which is declared in the second line - this way it is possible to load the rlm option only once VE is activated)