Mercurial > urweb
annotate lib/js/urweb.js @ 602:1d34d916c206
Combine lib* directories
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Tue, 13 Jan 2009 15:23:48 -0500 |
parents | jslib/urweb.js@7c3c21eb5b4c |
children | b1064de2b1f9 |
rev | line source |
---|---|
adamc@580 | 1 function cons(v, ls) { |
adamc@580 | 2 return { n : ls, v : v }; |
adamc@580 | 3 } |
adamc@579 | 4 function callAll(ls) { |
adamc@585 | 5 for (; ls; ls = ls.n) |
adamc@579 | 6 ls.v(); |
adamc@579 | 7 } |
adamc@574 | 8 |
adamc@580 | 9 function sc(v) { |
adamc@580 | 10 return {v : v, h : null}; |
adamc@580 | 11 } |
adamc@580 | 12 function sv(s, v) { |
adamc@580 | 13 s.v = v; |
adamc@580 | 14 callAll(s.h); |
adamc@580 | 15 } |
adamc@601 | 16 function sg(s) { |
adamc@601 | 17 return s.v; |
adamc@601 | 18 } |
adamc@579 | 19 |
adamc@580 | 20 function ss(s) { |
adamc@580 | 21 return s; |
adamc@580 | 22 } |
adamc@580 | 23 function sr(v) { |
adamc@580 | 24 return {v : v, h : null}; |
adamc@580 | 25 } |
adamc@580 | 26 function sb(x,y) { |
adamc@580 | 27 var z = y(x.v); |
adamc@580 | 28 var s = {v : z.v, h : null}; |
adamc@580 | 29 |
adamc@580 | 30 function reZ() { |
adamc@580 | 31 z.h = cons(function() { s.v = z.v; callAll(s.h); }, z.h); |
adamc@580 | 32 } |
adamc@580 | 33 |
adamc@580 | 34 x.h = cons(function() { z = y(x.v); reZ(); s.v = z.v; callAll(s.h); }, x.h); |
adamc@580 | 35 reZ(); |
adamc@580 | 36 |
adamc@580 | 37 return s; |
adamc@580 | 38 } |
adamc@571 | 39 |
adamc@600 | 40 function myParent() { |
adamc@600 | 41 var pos = document; |
adamc@600 | 42 |
adamc@600 | 43 while (pos.lastChild && pos.lastChild.nodeType == 1) |
adamc@600 | 44 pos = pos.lastChild; |
adamc@600 | 45 |
adamc@600 | 46 return pos.parentNode; |
adamc@600 | 47 } |
adamc@600 | 48 |
adamc@571 | 49 function dyn(s) { |
adamc@571 | 50 var x = document.createElement("span"); |
adamc@571 | 51 x.innerHTML = s.v; |
adamc@600 | 52 myParent().appendChild(x); |
adamc@580 | 53 s.h = cons(function() { x.innerHTML = s.v }, s.h); |
adamc@571 | 54 } |
adamc@582 | 55 |
adamc@598 | 56 function inp(t, s) { |
adamc@598 | 57 var x = document.createElement(t); |
adamc@598 | 58 x.value = s.v; |
adamc@600 | 59 myParent().appendChild(x); |
adamc@598 | 60 s.h = cons(function() { x.value = s.v }, s.h); |
adamc@598 | 61 x.onkeyup = function() { sv(s, x.value) }; |
adamc@598 | 62 } |
adamc@598 | 63 |
adamc@597 | 64 function eh(x) { |
adamc@597 | 65 return x.split("&").join("&").split("<").join("<").split(">").join(">"); |
adamc@597 | 66 } |
adamc@597 | 67 |
adamc@582 | 68 function ts(x) { return x.toString() } |
adamc@586 | 69 function bs(b) { return (b ? "True" : "False") } |
adamc@586 | 70 |
adamc@584 | 71 function pf() { alert("Pattern match failure") } |
adamc@589 | 72 |