User:Mikevoir/betterCodeMirror.js

mw.loader.using('mediawiki.api').then(function {	var lib = this._LIB;	// var api = new mw.Api; //currently unused	var betterCodeMirror = {		config: mw.config.get('wgAction'),		row: document.querySelector('.group-insert'),		textbox: $( '#wpTextbox' ),		quickOL: function {			// Add buttons			this.addButton('.group-insert', 'OL', addOL);			this.addButton('.group-insert', 'OL_tl', 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', '');				}			}		},		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, container.children[0]);			}		},		init: function {			if (this.config.wgAction && ['edit', 'submit'].includes(this.config.wgAction)) {				lib.waitFor('.CodeMirror', this.quickOL);			}		}	};

betterCodeMirror.init; });