comparison 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
comparison
equal deleted inserted replaced
601:7c3c21eb5b4c 602:1d34d916c206
1 function cons(v, ls) {
2 return { n : ls, v : v };
3 }
4 function callAll(ls) {
5 for (; ls; ls = ls.n)
6 ls.v();
7 }
8
9 function sc(v) {
10 return {v : v, h : null};
11 }
12 function sv(s, v) {
13 s.v = v;
14 callAll(s.h);
15 }
16 function sg(s) {
17 return s.v;
18 }
19
20 function ss(s) {
21 return s;
22 }
23 function sr(v) {
24 return {v : v, h : null};
25 }
26 function sb(x,y) {
27 var z = y(x.v);
28 var s = {v : z.v, h : null};
29
30 function reZ() {
31 z.h = cons(function() { s.v = z.v; callAll(s.h); }, z.h);
32 }
33
34 x.h = cons(function() { z = y(x.v); reZ(); s.v = z.v; callAll(s.h); }, x.h);
35 reZ();
36
37 return s;
38 }
39
40 function myParent() {
41 var pos = document;
42
43 while (pos.lastChild && pos.lastChild.nodeType == 1)
44 pos = pos.lastChild;
45
46 return pos.parentNode;
47 }
48
49 function dyn(s) {
50 var x = document.createElement("span");
51 x.innerHTML = s.v;
52 myParent().appendChild(x);
53 s.h = cons(function() { x.innerHTML = s.v }, s.h);
54 }
55
56 function inp(t, s) {
57 var x = document.createElement(t);
58 x.value = s.v;
59 myParent().appendChild(x);
60 s.h = cons(function() { x.value = s.v }, s.h);
61 x.onkeyup = function() { sv(s, x.value) };
62 }
63
64 function eh(x) {
65 return x.split("&").join("&amp;").split("<").join("&lt;").split(">").join("&gt;");
66 }
67
68 function ts(x) { return x.toString() }
69 function bs(b) { return (b ? "True" : "False") }
70
71 function pf() { alert("Pattern match failure") }
72