User:AoV2/parsertricks
Appearance
This uses the API to render wiki-text after the page has loaded—useful for coloring links appropriately and generating tool-tips, image thumbnails, and other minutiae. ―AoV² 07:50, 27 March 2010 (UTC)
parsertricks = { 'i': 0, 'o': 0, 'b': "", sb: null};
parsertricks.wtxt = function(s){
parsertricks.b += '<span id="aov-' + parsertricks.i + '-a">' + s + '</span>';
return '<span id="aov-' + (parsertricks.i++) + '-b">' + s + '</span>';
}
parsertricks.init = function(s){
if(parsertricks.sb) return parsertricks.sb.innerHTML = s;
document.getElementById("bodyContent").innerHTML += '<div id="aov-sb" style="display:none !important;"></div>';
parsertricks.sb = document.getElementById("aov-sb");
return parsertricks.init(s);
}
parsertricks.refresh = function(){
url = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + "/api.php?action=parse&format=json&callback=parsertricks.cb&text=" + encodeURIComponent(parsertricks.b);
mw.loader.load(url);
parsertricks.b = "";
}
parsertricks.cb = function(obj){
parsertricks.init(obj.parse.text["*"]);
while(parsertricks.o < parsertricks.i) {
document.getElementById("aov-" + parsertricks.o + "-b").innerHTML = document.getElementById("aov-" + parsertricks.o + "-a").innerHTML;
parsertricks.o++;
}
}
parsertricks.wlink = function(foo, bar) {
return parsertricks.wtxt("[[" + foo + "|" + bar + "]]");
}