adamc@580: function cons(v, ls) { adamc@580: return { n : ls, v : v }; adamc@580: } adamc@579: function callAll(ls) { adamc@585: for (; ls; ls = ls.n) adamc@579: ls.v(); adamc@579: } adamc@574: adamc@580: function sc(v) { adamc@580: return {v : v, h : null}; adamc@580: } adamc@580: function sv(s, v) { adamc@580: s.v = v; adamc@580: callAll(s.h); adamc@580: } adamc@601: function sg(s) { adamc@601: return s.v; adamc@601: } adamc@579: adamc@580: function ss(s) { adamc@580: return s; adamc@580: } adamc@580: function sr(v) { adamc@580: return {v : v, h : null}; adamc@580: } adamc@580: function sb(x,y) { adamc@580: var z = y(x.v); adamc@580: var s = {v : z.v, h : null}; adamc@580: adamc@580: function reZ() { adamc@580: z.h = cons(function() { s.v = z.v; callAll(s.h); }, z.h); adamc@580: } adamc@580: adamc@580: x.h = cons(function() { z = y(x.v); reZ(); s.v = z.v; callAll(s.h); }, x.h); adamc@580: reZ(); adamc@580: adamc@580: return s; adamc@580: } adamc@571: adamc@604: function lastParent() { adamc@604: var pos = document; adamc@604: adamc@600: while (pos.lastChild && pos.lastChild.nodeType == 1) adamc@600: pos = pos.lastChild; adamc@600: adamc@600: return pos.parentNode; adamc@600: } adamc@600: adamc@604: var thisScript = null; adamc@603: adamc@604: function addNode(node) { adamc@604: if (thisScript) { adamc@604: thisScript.parentNode.appendChild(node); adamc@604: thisScript.parentNode.removeChild(thisScript); adamc@604: } else adamc@604: lastParent().appendChild(node); adamc@603: } adamc@603: adamc@604: function runScripts(node) { adamc@604: var savedScript = thisScript; adamc@603: adamc@646: var scripts = node.getElementsByTagName("script"), scriptsCopy = {}; adamc@604: var len = scripts.length; adamc@646: for (var i = 0; i < len; ++i) adamc@646: scriptsCopy[i] = scripts[i]; adamc@604: for (var i = 0; i < len; ++i) { adamc@646: thisScript = scriptsCopy[i]; adamc@604: eval(thisScript.textContent); adamc@604: } adamc@604: adamc@604: thisScript = savedScript; adamc@603: } adamc@603: adamc@603: function populate(node, html) { adamc@603: node.innerHTML = html; adamc@604: runScripts(node); adamc@603: } adamc@603: adamc@571: function dyn(s) { adamc@571: var x = document.createElement("span"); adamc@604: populate(x, s.v); adamc@604: addNode(x); adamc@603: s.h = cons(function() { populate(x, s.v) }, s.h); adamc@571: } adamc@582: adamc@598: function inp(t, s) { adamc@598: var x = document.createElement(t); adamc@598: x.value = s.v; adamc@604: addNode(x); adamc@598: s.h = cons(function() { x.value = s.v }, s.h); adamc@598: x.onkeyup = function() { sv(s, x.value) }; adamc@606: return x; adamc@598: } adamc@598: adamc@597: function eh(x) { adamc@597: return x.split("&").join("&").split("<").join("<").split(">").join(">"); adamc@597: } adamc@597: adamc@582: function ts(x) { return x.toString() } adamc@586: function bs(b) { return (b ? "True" : "False") } adamc@586: adamc@584: function pf() { alert("Pattern match failure") } adamc@589: adamc@603: var closures = []; adamc@603: adamc@603: function ca(f) { adamc@603: var n = closures.length; adamc@603: closures[n] = f; adamc@603: return n; adamc@603: } adamc@603: adamc@603: function cr(n) { adamc@603: return closures[n](); adamc@603: } adamc@603: adamc@609: adamc@609: function getXHR() adamc@609: { adamc@609: try { adamc@609: return new XMLHttpRequest(); adamc@609: } catch (e) { adamc@609: try { adamc@609: return new ActiveXObject("Msxml2.XMLHTTP"); adamc@609: } catch (e) { adamc@609: try { adamc@609: return new ActiveXObject("Microsoft.XMLHTTP"); adamc@609: } catch (e) { adamc@609: throw "Your browser doesn't seem to support AJAX."; adamc@609: } adamc@609: } adamc@609: } adamc@609: } adamc@609: adamc@613: function rc(uri, parse, k) { adamc@609: var xhr = getXHR(); adamc@609: adamc@609: xhr.onreadystatechange = function() { adamc@612: if (xhr.readyState == 4) { adamc@612: var isok = false; adamc@612: adamc@612: try { adamc@612: if (xhr.status == 200) adamc@612: isok = true; adamc@612: } catch (e) { } adamc@612: adamc@612: if (isok) adamc@613: k(parse(xhr.responseText)); adamc@612: else adamc@612: alert("Error querying remote server!"); adamc@612: } adamc@609: }; adamc@609: adamc@609: xhr.open("GET", uri, true); adamc@609: xhr.send(null); adamc@609: }