User:Krinkle/insertVectorButtons.js

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)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/**
 * Insert Vector Buttons
 *
 * @author Krinkle, 2010–2015
 * @revision 2015-03-25
 * @source https://meta.wikimedia.org/wiki/User:Krinkle/Scripts/insertVectorButtons
 *
 * This script is released in the public domain.
 */
if ($.fn.wikiEditor && typeof kCustomMainInsertButton === 'undefined' && (mw.config.get('wgAction') == 'edit' || mw.config.get('wgAction') == 'submit')) {
	window.kCustomMainInsertButton = function (imageId, imageFile, speedTip, tagOpen, tagClose, sampleText, callback) {
		// Reason for the a[b]-method instead of the much shorter a.b-method
		// is to dynamically set the object name imageId
		var wikiOptions = {'section': 'main', 'group': 'insert', 'tools': {}};
		wikiOptions.tools[imageId] = {
			label: speedTip,
			type: 'button',
			icon: imageFile,
			action: {
				type: 'callback',
				execute: function () {
					$('#wpTextbox1').textSelection('encapsulateSelection',{
						pre: tagOpen,
						peri: sampleText,
						post: tagClose
					});
					if (callback) { callback(); }
				}
			}
		};
		$('#wpTextbox1').wikiEditor('addToToolbar', wikiOptions);
	};

	jQuery(function () {
		if (typeof kCustomMainInsertButton_config !== undefined) {
			kCustomMainInsertButton_config();
		}
	});

} else {
	window.kCustomMainInsertButton = function () {};
}