User:Mirokado/addrefs.js

// adapted from Advisor.js

var mk = mk || {};

// getPosition(e), observe(e, x, f), stopObserving(e, x, f), // and stopEvent(event) are inspired by the prototype.js framework // http://prototypejs.org/ mk.getPosition = function (e) { var x = 0; var y = 0; do { x += e.offsetLeft || 0; y += e.offsetTop || 0; e = e.offsetParent; } while (e); return {x: x, y: y}; };

mk.observe = function (e, eventName, f) { if (e.addEventListener) { e.addEventListener(eventName, f, false); } else { e.attachEvent('on' + eventName, f); } };

mk.stopObserving = function (e, eventName, f) { if (e.removeEventListener) { e.removeEventListener(eventName, f, false); } else { e.detachEvent('on' + eventName, f); } };

mk.stopEvent = function (event) { if (event.preventDefault) { event.preventDefault; event.stopPropagation; } else { event.returnValue = false; event.cancelBubble = true; } };

// === Internationalisation === // ct._ is a gettext-style internationalisation helper // (http://en.wikipedia.org/wiki/gettext) // If no translation is found for the parameter, it is returned as is. // Additionally, subsequent parameters are substituted for $1, $2, and so on. mk._ = function (s) { if (mk.translation && mk.translation[s]) { s = mk.translation[s]; }	var index = 1; while (arguments[index]) { s = s.replace('$' + index, arguments[index]); // todo: replace all? index++; }	return s; };

// === Editor compatibility layer === // Controlling access to wpTextbox1 helps abstract out compatibility // with editors like wikEd (http://en.wikipedia.org/wiki/User:Cacycle/wikEd)

mk.getWikiText = function { if (window.wikEdUseWikEd) { var obj = {sel: WikEdGetSelection}; WikEdParseDOM(obj, wikEdFrameBody); return obj.plain; }	return mk.eTextarea.value; };

mk.setWikiText = function (s) { if (window.wikEdUseWikEd) { // todo: wikEd compatibility alert(ct._('Changing text in wikEd is not yet supported.')); return; };	mk.eTextarea.value = s; };

// === int main === // This is the entry point mk.observe(window, 'load', function {	mk.eTextarea = document.getElementById('wpTextbox1');	if (mk.eTextarea == null) {		// This is not an ``?action=edit'' page		return;	} 	if (1) { 	 	// Not ready yet, need to do this only for section edits and 	 	// bind removal of this to the Save Page button 	 	return; 	}	var s = mk.getWikiText;	var xx = "\n \n";	mk.setWikiText(s + xx); });

// end of file