Mercurial > urweb
changeset 817:4585f744574a
ccheckbox
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Thu, 21 May 2009 10:34:56 -0400 (2009-05-21) |
parents | 26e911ee924c |
children | 066493f7f008 |
files | lib/js/urweb.js lib/ur/basis.urs src/monoize.sml |
diffstat | 3 files changed, 38 insertions(+), 4 deletions(-) [+] |
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 (); };
--- a/lib/ur/basis.urs Thu May 21 10:18:20 2009 -0400 +++ b/lib/ur/basis.urs Thu May 21 10:34:56 2009 -0400 @@ -631,6 +631,8 @@ val ctextbox : cformTag [Value = string, Size = int, Source = source string] [] val button : cformTag [Value = string, Onclick = transaction unit] [] +val ccheckbox : cformTag [Value = bool, Size = int, Source = source bool] [] + con cselect = [Cselect] val cselect : cformTag [Source = source string, Onchange = transaction unit] cselect
--- a/src/monoize.sml Thu May 21 10:18:20 2009 -0400 +++ b/src/monoize.sml Thu May 21 10:34:56 2009 -0400 @@ -2648,6 +2648,29 @@ fm) end) + | "ccheckbox" => + (case List.find (fn ("Source", _, _) => true | _ => false) attrs of + NONE => + let + val (ts, fm) = tagStart "input type=\"checkbox\"" + in + ((L'.EStrcat (ts, + (L'.EPrim (Prim.String " />"), loc)), + loc), fm) + end + | SOME (_, src, _) => + let + val sc = strcat [str "chk(", + (L'.EJavaScript (L'.Script, src), loc), + str ")"] + val sc = setAttrs sc + in + (strcat [str "<span><script type=\"text/javascript\">", + sc, + str "</script></span>"], + fm) + end) + | "cselect" => (case List.find (fn ("Source", _, _) => true | _ => false) attrs of NONE =>