Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/*
 * Gadget to make some default changes to the editbox toolbar
 *
 * For example, change the "small" button from "<small>" to "{{smaller|...}}"
 */

/* eslint-disable one-var */

( function () {

	'use strict';

	var updateSizeButtons = function ( $wikieditor, $textbox ) {

		var $group = $wikieditor.find( '.group-size' );

		/* Remove button for <big> */
		$textbox.wikiEditor( 'removeFromToolbar', {
			section: 'advanced',
			group: 'size',
			tool: 'big'
		} );
		$textbox.wikiEditor( 'removeFromToolbar', {
			section: 'advanced',
			group: 'size',
			tool: 'small'
		} );

		$textbox.wikiEditor( 'addToToolbar', {
			section: 'advanced',
			group: 'size',
			tools: {
				big: {
					label: mw.msg('wikieditor-toolbar-tool-big'),
					type: 'button',
					oouiIcon: 'bigger',
					action: {
						type: 'encapsulate',
						options: {
							pre: '{{larger|',
							periMsg: 'wikieditor-toolbar-tool-big-example',
							post: '}}'
						}
					}
				},
				small: {
					label: mw.msg('wikieditor-toolbar-tool-small'),
					type: 'button',
					oouiIcon: 'smaller',
					action: {
						type: 'encapsulate',
						options: {
							pre: '{{smaller|',
							periMsg: 'wikieditor-toolbar-tool-big-example',
							post: '}}'
						}
					}
				}
			}
		} );

		// put them back at the start
		$group.find( '.tool[rel="small"]' ).prependTo( $group );
		$group.find( '.tool[rel="big"]' ).prependTo( $group );
	};

	/*
	 * Add new character groups
	 */
	var addCharGroups = function ( $textbox ) {

		$textbox.wikiEditor( 'addToToolbar', {
			section: 'characters',
			pages: {
				oldEnglish: {
					layout: 'characters',
					label: 'Old/Middle English',
					characters: [
						'Æ', 'æ', 'Ð', 'ð', 'Ᵹ', 'ᵹ', 'Ȝ', 'ȝ', 'Ꝛ', 'ꝛ',
						'Þ', 'þ', 'Ꝥ', 'ꝥ', 'Ƿ', 'ƿ',
						'⹒', '⁊', // et
						'Ǣ', 'ǣ', 'Ā', 'ā', 'Ċ', 'ċ', 'Ē', 'ē', 'Ḡ', 'ḡ', 'Ġ', 'ġ',
						'Ī', 'ī', 'Ō', 'ō', 'Ū', 'ū', 'Ȳ', 'ȳ',
						{
							label: '·',
							titleMsg: 'special-characters-title-interpunct',
							action: {
								type: 'replace',
								options: {
									peri: '·',
									selectPeri: false
								}
							}
						}
					]
				}
			}
		} );
	};

	/* Check if view is in edit mode and that the required modules are available.
	 * Then, customize the toolbar … */
	if ( [ 'edit', 'submit' ].indexOf( mw.config.get( 'wgAction' ) ) !== -1 ) {
		mw.loader.using( 'user.options' ).then( function () {
			// This can be the string "0" if the user disabled the preference
			// ([[phab:T54542#555387]])
			if ( mw.user.options.get( 'usebetatoolbar' ) === 1 ) {
				$.when(
					mw.loader.using( 'ext.wikiEditor' ), $.ready
				).then( function () {

					// eslint-disable-next-line no-jquery/no-global-selector
					var $wikieditor = $( '.wikiEditor-ui' ),
						$wptb1 = $wikieditor.find( '#wpTextbox1' );

					updateSizeButtons( $wikieditor, $wptb1 );
					addCharGroups( $wptb1 );
				} );
			}
		} );
	}

}() );