Mercurial > urweb
diff lib/js/urweb.js @ 817:4585f744574a
ccheckbox
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Thu, 21 May 2009 10:34:56 -0400 |
parents | 26e911ee924c |
children | 395a5d450cc0 |
line wrap: on
line diff
--- a/lib/js/urweb.js Thu May 21 10:18:20 2009 -0400 +++ b/lib/js/urweb.js Thu May 21 10:34:56 2009 -0400 @@ -295,12 +295,12 @@ populate(x); } -function input(t, s) { +function input(t, s, recreate) { var x = document.createElement(t); x.dead = false; x.signal = ss(s); x.sources = null; - x.recreate = function(v) { if (x.value != v) x.value = v; }; + x.recreate = recreate(x); populate(x); addNode(x); @@ -308,7 +308,7 @@ } function inp(s) { - var x = input("input", s); + var x = input("input", s, function(x) { return function(v) { if (x.value != v) x.value = v; }; }); x.value = s.data; x.onkeyup = function() { sv(s, x.value) }; @@ -316,7 +316,7 @@ } function sel(s, content) { - var x = input("select", s); + var x = input("select", s, function(x) { return function(v) { if (x.value != v) x.value = v; }; }); x.innerHTML = content; x.value = s.data; x.onchange = function() { sv(s, x.value) }; @@ -324,6 +324,15 @@ return x; } +function chk(s) { + var x = input("input", s, function(x) { return function(v) { if (x.checked != v) x.checked = v; }; }); + x.type = "checkbox"; + x.checked = s.data; + x.onchange = function() { sv(s, x.checked) }; + + return x; +} + function addOnChange(x, f) { var old = x.onchange; x.onchange = function() { old(); f (); };