User:Gryllida/WikiEditorEmoticons.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
mw.loader.using(['mediawiki.api'], function () {
	var customizeToolbar = function () {
		// add emotions
		$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
			'section': 'main',
			'group': 'insert',
			'tools': {
				// smiling
				'addSmilingFace': {
					label: 'Add a smiling face',
					type: 'button',
					icon: '//upload.wikimedia.org/wikipedia/commons/thumb/8/85/Smiley.svg/22px-Smiley.svg.png',
					action: {
						type: 'encapsulate',
						options: {
							pre: "[[File:Smiley.svg|x20px|:-)]]" // text to be inserted
						}
					}
				},
				// smiling end
				// File:Smiley XD.svg
				// laughing
				'addLaughingFace': {
					label: 'Add a laughing face',
					type: 'button',
					icon: '//upload.wikimedia.org/wikipedia/commons/thumb/2/2c/Smiley_XD.svg/22px-Smiley_XD.svg.png',
					action: {
						type: 'encapsulate',
						options: {
							pre: "[[File:Smiley XD.svg|x20px|:-)]]" // text to be inserted
						}
					}
				},
				// frowning
				// Frowning-smiley.svg
				'addFrowningFace': {
					label: 'Add a frowning face',
					type: 'button',
					icon: '//upload.wikimedia.org/wikipedia/commons/thumb/6/62/Frowning-smiley.svg/22px-Frowning-smiley.svg.png',
					action: {
						type: 'encapsulate',
						options: {
							pre: "[[File:Frowning-smiley.svg|x20px|:-)]]" // text to be inserted
						}
					}
				},
			}
		} );
		console.log(4);
	};
	// Check if view is in edit mode and that the required modules are available. Then, customize the toolbar … 
	if ( $.inArray( mw.config.get( 'wgAction' ), [ 'edit', 'submit' ] ) !== -1 ) {
		mw.loader.using( 'user.options' ).then( function () {
			console.log(1);
			// 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( customizeToolbar );
			}
		} );
	}
	// == WikiEditor codes end ==
});