User:Inductiveload/Gadget-MobileFrontendFixer.js

/** * The Mobile Wikitext editor is still in beta, and the visual editor is * pretty much completely useless. Try to add some tools. */

( function ( $, mw ) {

function MFWikitextFixer { // eslint-disable-next-line no-jquery/no-global-selector this.$textbox = $( '#wikitext-editor' ); }

MFWikitextFixer.prototype.addTools = function { var that = this;

var toolFactory = new OO.ui.ToolFactory; var toolGroupFactory = new OO.ui.ToolGroupFactory;

// Define the tool’s static properties and the action it performs function SignatureTool { SignatureTool.super.apply( this, arguments ); }		OO.inheritClass( SignatureTool, OO.ui.Tool ); SignatureTool.static.name = 'signature'; SignatureTool.static.icon = 'signature'; SignatureTool.static.title = 'Insert signature'; // Define the action that is performed when this tool is selected (clicked). SignatureTool.prototype.onSelect = function { that.$textbox.textSelection( 'replaceSelection',  +  ); this.setActive( false ); };		SignatureTool.prototype.onUpdateState = function {};

toolFactory.register( SignatureTool );

var toolList = [ 'signature' ];

// allow users to add their own tools mw.hook( 'wikisource.mobilewikitext.addtools' ) .fire( toolFactory, toolList, this.$textbox );

var toolbar = new OO.ui.Toolbar( toolFactory, toolGroupFactory );

// Add the MenuToolGroup to the toolbar. toolbar.setup( [			{				icon: 'code',				type: 'bar',				label: 'Tools',				title: 'Extra tools',				header: 'This is the header',				include: toolList			}		] );

// $( '.overlay-header' ) // bizarre - clicks don't work if inserted into the overlay // eslint-disable-next-line no-jquery/no-global-selector $( '.overlay-header-container' ) .prepend( $( ' ' )				.append( toolbar.$element )			);

toolbar.initialize; };

mw.loader.using( [ 'jquery.textSelection', 'oojs-ui-widgets' ], function {		$( function  { mw.hook( 'mobileFrontend.editorOpened' ).add( function ( editor ) {				if ( editor === 'wikitext' ) {					var fixer = new MFWikitextFixer;					fixer.addTools;				}			} ); } );	} );

// eslint-disable-next-line no-undef }( jQuery, mediaWiki ) );