User:Mikevoir/lib.js

$(function {

mw.log('pre _LIB'); // Double-load protection. if (window.dev && window.dev._LIB) { return; }

var _LIB = { // Delay until element exists to run function waitFor: function(query, callback, extraDelay) { if ('function' == typeof callback && 'string' == typeof query) { extraDelay = extraDelay || 0; if (document.querySelector(query)) { setTimeout(callback, extraDelay); } else { // set up the mutation observer var observer = new MutationObserver(function (mutations, me) {						// mutations is an array of mutations that occurred						// me is the MutationObserver instance						var targetNode = document.querySelector(query);						if (targetNode) {							setTimeout(callback, extraDelay);							me.disconnect; // stop observing							return;						}					}); // start observing observer.observe(document, {					 childList: true,					  subtree: true					}); }			}		},		escapeSearch: function(string) { return string.replace(/[.*+?^${}|[\]\\]/g, '\\$&'); // $& means the whole matched string },		escapeReplace: function(string) { return string.replace(/\$/g, '$$$$'); }	};	mw.log('_LIB', _LIB); (window.dev = window.dev || {})._LIB = _LIB; });