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] = [

'{{pharma-stub}}',

'{{WikiProject Pharmacology|class=|importance=}}',

'|class=|importance=',

'{{ping|+}}',

'{{ping|+|p=}}'

];

insertlistarray[1] = [

'–',

'—',

' ',

'
',

'{{nowrap|+}}',

'×',

'+',

'+',

'+',

'+'

];

insertlistarray[2] = [

'{{PMID|+}}',

'{{tlx|+}}',

'{{abbr|short|+}}',

'{{abbr|+|full}}',

'{{Outdent|::::::}}',

'#REDIRECT +',

'+',

'short',

'+'

];

insertlistarray[3] = [

'',

'{{reflist}}',

'{{reflist|30em}}',

'{{reflist-talk}}',

'{{refn|+}}',

'{{refn|name=|group=|+}}',

'{{reflist|group=+}}'

];

insertlistarray[4] = [

'{{efn|+}}',

'{{notelist}}',

'{{notelist|30em}}',

'{{notelist-talk}}',

'{{efn|group=|+}}',

'{{notelist|group=+}}'

];

insertlistarray[5] = [

'{{colbegin|n}}+{{colend}}',

'+',

'+',

'

+
',

'

+
'

];

insertlistarray[6] = [

'WP:MEDRS',

'WP:NPOV',

'WP:FRINGE',

'WP:UNDUE',

'WP:SOAPBOX',

'WP:5P+'

];

var insertlist = "";

var entityMap = {

"&": "&",

"<": "<",

">": ">",

'"': '"',

"'": ''',

"/": '/'

};

//

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('

');

// 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: {{pharma-stub}} {{WP:PHARM|class=|importance=}} |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

// {{citation needed}} 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