changeset 816:26e911ee924c

Split JavaScript inp() into separate functions
author Adam Chlipala <adamc@hcoop.net>
date Thu, 21 May 2009 10:18:20 -0400
parents 493f44759879
children 4585f744574a
files lib/js/urweb.js src/monoize.sml
diffstat 2 files changed, 23 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/lib/js/urweb.js	Sun May 17 18:41:43 2009 -0400
+++ b/lib/js/urweb.js	Thu May 21 10:18:20 2009 -0400
@@ -295,7 +295,7 @@
   populate(x);
 }
 
-function inp(t, s, content) {
+function input(t, s) {
   var x = document.createElement(t);
   x.dead = false;
   x.signal = ss(s);
@@ -303,14 +303,23 @@
   x.recreate = function(v) { if (x.value != v) x.value = v; };
   populate(x);
   addNode(x);
-  if (t == "select") {
-    x.innerHTML = content;
-    x.value = s.data;
-    x.onchange = function() { sv(s, x.value) };
-  } else {
-    x.value = s.data;
-    x.onkeyup = function() { sv(s, x.value) };
-  }
+
+  return x;
+}
+
+function inp(s) {
+  var x = input("input", s);
+  x.value = s.data;
+  x.onkeyup = function() { sv(s, x.value) };
+
+  return x;
+}
+
+function sel(s, content) {
+  var x = input("select", s);
+  x.innerHTML = content;
+  x.value = s.data;
+  x.onchange = function() { sv(s, x.value) };
 
   return x;
 }
--- a/src/monoize.sml	Sun May 17 18:41:43 2009 -0400
+++ b/src/monoize.sml	Thu May 21 10:18:20 2009 -0400
@@ -2565,9 +2565,9 @@
                                                  loc)), loc), fm)
                               end
                             | SOME (_, src, _) =>
-                              (strcat [str "<span><script type=\"text/javascript\">inp(\"input\",",
+                              (strcat [str "<span><script type=\"text/javascript\">inp(",
                                        (L'.EJavaScript (L'.Script, src), loc),
-                                       str ",\"\")</script></span>"],
+                                       str ")</script></span>"],
                                fm))
                        | _ => (Print.prefaces "Targs" (map (fn t => ("T", CorePrint.p_con env t)) targs);
                                raise Fail "No name passed to textbox tag"))
@@ -2637,9 +2637,9 @@
                          end
                        | SOME (_, src, _) =>
                          let
-                             val sc = strcat [str "inp(\"input\",",
+                             val sc = strcat [str "inp(",
                                               (L'.EJavaScript (L'.Script, src), loc),
-                                              str ",\"\")"]
+                                              str ")"]
                              val sc = setAttrs sc
                          in
                              (strcat [str "<span><script type=\"text/javascript\">",
@@ -2662,7 +2662,7 @@
                          let
                              val (xml, fm) = monoExp (env, st, fm) xml
 
-                             val sc = strcat [str "inp(\"select\",",
+                             val sc = strcat [str "sel(",
                                               (L'.EJavaScript (L'.Script, src), loc),
                                               str ",",
                                               (L'.EJavaScript (L'.Script, xml), loc),