User:Garzfoth/Scripts/CustomQuickInsertButtons.js

// Migrated from https://en.wikipedia.org/wiki/User:Garzfoth/common.js on 2021-05-05

// Notes: // • For changelogs prior to migration, see https://en.wikipedia.org/w/index.php?title=User:Garzfoth/common.js&action=history // • I moved the escapeHtml function outside of the if scope and renamed it during migration. Hopefully that didn't break anything. // • TODO: General review & cleanup?

// // Custom quick insert buttons for editor //

function escapeHtmlForCQIB(string) { return String(string).replace(/[&<>"'\/]/g, function (s) {		return entityMap[s];	}); }

if (mw.config.get('wgAction') === "edit" || mw.config.get('wgAction') === "submit") { var insertlistarray = Array; // 	insertlistarray[0] = [ ,		,		'|class=|importance=', ,			];	insertlistarray[1] = [ '–',		'&mdash;', ' ',		' ',		'+',		'×',		'+',		'+',		' + ',		' + '	];	insertlistarray[2] = [ ,		,		'short', '+',		'',		'#REDIRECT +', '+', '+|short', '+'	];	insertlistarray[3] = [ ' ',		,		,		,		,		,			];	insertlistarray[4] = [ ,		,		,		,		,			];	insertlistarray[5] = [ '+',		' ',		' + ',		' + ',		'"+"'	];	insertlistarray[6] = [ 'WP:MEDRS', 'WP:NPOV', 'WP:FRINGE', 'WP:UNDUE', 'WP:SOAPBOX', 'WP:5P+' ];	var insertlist = ""; var entityMap = { "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': '&quot;',		"'": '&#39;',		"/": '&#x2F;'	};	// 	for (var x = 0; x < insertlistarray.length; x++) {		if (x !== 0) {			insertlist += " ";		}		for (var i = 0; i < insertlistarray[x].length; i++) {			insertlist += ""+escapeHtmlForCQIB(insertlistarray[x][i])+" ";		}	}	$(".editOptions").prepend(' '+insertlist+' General template messages | Cleanup template messages | Inline template messages ');	// https://en.wikipedia.org/wiki/MediaWiki:Gadget-charinsert.js	// https://en.wikipedia.org/wiki/MediaWiki:Gadget-charinsert-core.css	// https://en.wikipedia.org/wiki/MediaWiki:Gadget-charinsert-core.js	// 	//dualCharInsert = 'PHARM:  |class=|importance='; /*window.charinsertCustom = { "Insert": dualCharInsert, "Wiki markup": dualCharInsert }*/	// http://stackoverflow.com/questions/31376229/how-do-i-modify-the-mediawiki-charinsert-extension-to-enable-the-insertion-of-wi // and others??? // 	// foo $(function {		var $currentlyFocused = $('#wpTextbox1');		// Apply to dynamically created textboxes as well as normal ones		//$(document).on('focus', 'textarea, input:text', function  { //	$currentlyFocused = $(this); //});

$('a.mw-charinsert').each(function {			var text = this.text;			var parts = text.split('+');			if (text === '+') parts = [text];			var front = decodeURIComponent(parts[0] || );			var back  = decodeURIComponent(parts[1] || );			$(this).click(function (e) { e.preventDefault; //mw.toolbar.insertTags(front, back, ''); if ($currentlyFocused.length) { $currentlyFocused.textSelection(						'encapsulateSelection', {							pre: front,							peri: '',							post: back						}					); }				return false; });		});	}); } // END