
<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
		<id>https://psaltiki.info/index.php?action=history&amp;feed=atom&amp;title=MediaWiki%3AInsertWikiEditorButton.js</id>
		<title>MediaWiki:InsertWikiEditorButton.js - Revision history</title>
		<link rel="self" type="application/atom+xml" href="https://psaltiki.info/index.php?action=history&amp;feed=atom&amp;title=MediaWiki%3AInsertWikiEditorButton.js"/>
		<link rel="alternate" type="text/html" href="https://psaltiki.info/index.php?title=MediaWiki:InsertWikiEditorButton.js&amp;action=history"/>
		<updated>2026-04-06T15:52:24Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>https://psaltiki.info/index.php?title=MediaWiki:InsertWikiEditorButton.js&amp;diff=1619&amp;oldid=prev</id>
		<title>Root: Created page with &quot;/**  * Insert WikiEditor Button  * @version 2015-11-12  * @source https://meta.wikimedia.org/wiki/User:Krinkle/Scripts/InsertWikiEditorButton  * @author Krinkle  * @author Loc...&quot;</title>
		<link rel="alternate" type="text/html" href="https://psaltiki.info/index.php?title=MediaWiki:InsertWikiEditorButton.js&amp;diff=1619&amp;oldid=prev"/>
				<updated>2017-06-22T02:37:04Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;/**  * Insert WikiEditor Button  * @version 2015-11-12  * @source https://meta.wikimedia.org/wiki/User:Krinkle/Scripts/InsertWikiEditorButton  * @author Krinkle  * @author Loc...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;/**&lt;br /&gt;
 * Insert WikiEditor Button&lt;br /&gt;
 * @version 2015-11-12&lt;br /&gt;
 * @source https://meta.wikimedia.org/wiki/User:Krinkle/Scripts/InsertWikiEditorButton&lt;br /&gt;
 * @author Krinkle&lt;br /&gt;
 * @author Locos epraix&lt;br /&gt;
 * @license Released in the public domain&lt;br /&gt;
 */&lt;br /&gt;
/*jshint browser: true */&lt;br /&gt;
/*global jQuery, mediaWiki */&lt;br /&gt;
(function ($, mw) {&lt;br /&gt;
	&amp;quot;use strict&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
	var $toolbar, queue = [];&lt;br /&gt;
&lt;br /&gt;
	function insertButton(btnObj) {&lt;br /&gt;
		$toolbar.wikiEditor('addToToolbar', btnObj);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	function handleQueue() {&lt;br /&gt;
		for (var i = 0; i &amp;lt; queue.length; i++) {&lt;br /&gt;
			insertButton(queue[i]);&lt;br /&gt;
		}&lt;br /&gt;
		queue = [];&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	function check() {&lt;br /&gt;
		if ($.wikiEditor &amp;amp;&amp;amp; $.fn.wikiEditor &amp;amp;&amp;amp; $('#wpTextbox1').length) {&lt;br /&gt;
			$toolbar = $('#wpTextbox1');&lt;br /&gt;
			handleQueue();&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	// Only on editpage&lt;br /&gt;
	if ($.inArray(mw.config.get('wgAction'), ['edit', 'submit', 'formedit']) !== -1) {&lt;br /&gt;
		/**&lt;br /&gt;
		 * krInsertWikiEditorButton&lt;br /&gt;
		 *&lt;br /&gt;
		 * @param options {Object} An object with options:&lt;br /&gt;
		 * - section {String} (optional) The name of the section in the WikiEditor. Defaults to 'main'&lt;br /&gt;
		 * - group {String} (optional) The name of the group in the WikiEditor. Defaults to 'insert'&lt;br /&gt;
		 * - id {String} (required) Unique id (ie. 'my-button')&lt;br /&gt;
		 * - icon {String} (recommended) URL to the icon, should be square about 21 to 22px&lt;br /&gt;
		 * - label {String} (required) Tooltip displayed when hovering button&lt;br /&gt;
		 * - insertBefore {String} (optional) Wikitext to be inserted before the cursor on-click&lt;br /&gt;
		 * - sampleText {String} (optional) Text inserted in place of the cursor if no text was selected&lt;br /&gt;
		 * - insertAfter {String} (optional) Wikitext to be inserted after the cursor on-click&lt;br /&gt;
		 * - callback {Function} (optional) Called when the button is clicked&lt;br /&gt;
		 * - autoSummary {mixed} (optional) Null or an Object with the following properties:&lt;br /&gt;
		 *   - summary {String} (required) Edit summary that should be used&lt;br /&gt;
		 *   - position {String} (optional) 'append', 'prepend' or 'replace'&lt;br /&gt;
		 *   - delimiter {String} (optional) delimiter between the (possibly) current summary and the to-be-inserted summary&lt;br /&gt;
		 */&lt;br /&gt;
		window.krInsertWikiEditorButton = function (options) {&lt;br /&gt;
			// Defaults&lt;br /&gt;
			options = $.extend({&lt;br /&gt;
				'section': 'main',&lt;br /&gt;
				'group': 'insert',&lt;br /&gt;
				'id': null,&lt;br /&gt;
				'icon': '//upload.wikimedia.org/wikipedia/commons/thumb/f/f0/Toolbaricon_bold_!.png/21px-Toolbaricon_bold_!.png',&lt;br /&gt;
				'label': '',&lt;br /&gt;
				'insertBefore': '',&lt;br /&gt;
				'sampleText': '',&lt;br /&gt;
				'insertAfter': '',&lt;br /&gt;
				'callback': null,&lt;br /&gt;
				'autoSummary': {&lt;br /&gt;
					'summary': null,&lt;br /&gt;
					'position': 'append',&lt;br /&gt;
					'delimiter': '; '&lt;br /&gt;
				}&lt;br /&gt;
			}, options);&lt;br /&gt;
			// Required&lt;br /&gt;
			if (!options.id || !options.label) {&lt;br /&gt;
				return false;&lt;br /&gt;
			}&lt;br /&gt;
			var btnObj = {&lt;br /&gt;
				'section': options.section,&lt;br /&gt;
				'group': options.group,&lt;br /&gt;
				'tools': {}&lt;br /&gt;
			};&lt;br /&gt;
			btnObj.tools[options.id] = {&lt;br /&gt;
				label: options.label,&lt;br /&gt;
				type: 'button',&lt;br /&gt;
				icon: options.icon,&lt;br /&gt;
				action: {&lt;br /&gt;
					type: 'callback',&lt;br /&gt;
					execute: function () {&lt;br /&gt;
						// encapsulateSelection&lt;br /&gt;
						$toolbar.textSelection('encapsulateSelection', {&lt;br /&gt;
							pre: options.insertBefore,&lt;br /&gt;
							peri: options.sampleText,&lt;br /&gt;
							post: options.insertAfter&lt;br /&gt;
						});&lt;br /&gt;
						// Auto summary&lt;br /&gt;
						if (options.autoSummary &amp;amp;&amp;amp; options.autoSummary.summary) {&lt;br /&gt;
							var $summary = $('#wpSummary'), currentSum = $summary.val();&lt;br /&gt;
							if (!$.trim(currentSum)) {&lt;br /&gt;
								$summary.val(options.autoSummary.summary);&lt;br /&gt;
							} else {&lt;br /&gt;
								switch (options.autoSummary.position) {&lt;br /&gt;
								case 'prepend':&lt;br /&gt;
									$summary.val(&lt;br /&gt;
										options.autoSummary.summary +&lt;br /&gt;
											options.autoSummary.delimiter +&lt;br /&gt;
											currentSum&lt;br /&gt;
									);&lt;br /&gt;
									break;&lt;br /&gt;
								case 'replace':&lt;br /&gt;
									$summary.val(options.autoSummary.summary);&lt;br /&gt;
									break;&lt;br /&gt;
								default: // 'append'&lt;br /&gt;
									$summary.val(&lt;br /&gt;
										currentSum +&lt;br /&gt;
											options.autoSummary.delimiter +&lt;br /&gt;
											options.autoSummary.summary&lt;br /&gt;
									);&lt;br /&gt;
								}&lt;br /&gt;
							}&lt;br /&gt;
						}&lt;br /&gt;
						// Callback&lt;br /&gt;
						if ($.isFunction(options.callback)) {&lt;br /&gt;
							options.callback();&lt;br /&gt;
						}&lt;br /&gt;
					}&lt;br /&gt;
				}&lt;br /&gt;
			};&lt;br /&gt;
			if ($toolbar) {&lt;br /&gt;
				insertButton(btnObj);&lt;br /&gt;
			} else {&lt;br /&gt;
				queue.push(btnObj);&lt;br /&gt;
			}&lt;br /&gt;
		};&lt;br /&gt;
		$.when(&lt;br /&gt;
			mw.loader.using( 'ext.wikiEditor.toolbar' ),&lt;br /&gt;
			$.ready&lt;br /&gt;
		).then(check);&lt;br /&gt;
	} else {&lt;br /&gt;
		// No-op function to avoid errors on other pages&lt;br /&gt;
		window.krInsertWikiEditorButton = function () {};&lt;br /&gt;
	}&lt;br /&gt;
	// Load callback&lt;br /&gt;
	if (window.kCustomMainInsertButton_config) {&lt;br /&gt;
		kCustomMainInsertButton_config();&lt;br /&gt;
	}&lt;br /&gt;
}(jQuery, mediaWiki));&lt;/div&gt;</summary>
		<author><name>Root</name></author>	</entry>

	</feed>