User:Mikevoir/betterCodeMirror.js

(function {   // Load dependencies and cache    window.dev = window.dev || {};    if (!window.dev._LIB) { importScriptPage('User:Mikevoir/lib.js', 'community'); }	var lib;	var config = mw.config.get(['wgAction']);	var $textbox = $( '#wpTextbox1' );	var betterCodeMirror = {		init: function {			if (config.wgAction && ['edit', 'submit'].includes(config.wgAction)) {				lib.waitFor('.CodeMirror', this.quickOL);			}		},		addButton: function(query, content, handler) {			var addTo = document.querySelector(query);			if (addTo) {				var container = document.createElement('span');				container.classList.add('tool', 'oo-ui-widget', 'oo-ui-widget-enabled', 'oo-ui-buttonElement', 'oo-ui-buttonElement-frameless', 'oo-ui-iconElement', 'oo-ui-buttonWidget');				var button = document.createElement('a');				button.classList.add('oo-ui-buttonElement-button');				button.innerHTML = content;				button.role = 'button'; button.addEventListener('mouseup', handler); container.appendChild(button); addTo.insertBefore(container, addTo.children[0]); }		},		quickOL: function { // Add buttons betterCodeMirror.addButton('.group-insert', 'OL_tl', addOL); betterCodeMirror.addButton('.group-insert', 'OL', addOL); // Add call when clicked function addOL(event) { // OL call without TL params if (event.target.innerHTML == 'OL'){ $textbox.textSelection(						'replaceSelection',						''); // OL call with TL params }else if (event.target.innerHTML == 'OL_tl'){ $textbox.textSelection(						'replaceSelection',						''); }			}		},	};	// Start when LIB is loaded $.when(window.dev._LIB).then(function{		lib = window.dev._LIB;		betterCodeMirror.init;	}); });