changeset 2055:7c2229aa22fc

Adds AJAX-oriented widget cpassword.
author Ziv Scully <ziv@mit.edu>
date Sun, 10 Aug 2014 13:40:53 -0400
parents 4ad46302f659
children a9159911c3ba
files lib/js/urweb.js lib/ur/basis.urs src/css.sml src/monoize.sml
diffstat 4 files changed, 42 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/lib/js/urweb.js	Fri Aug 15 18:25:56 2014 -0400
+++ b/lib/js/urweb.js	Sun Aug 10 13:40:53 2014 -0400
@@ -1050,6 +1050,18 @@
     return x;
 }
 
+function password(s, name) {
+    if (suspendScripts)
+        return;
+
+    var x = input(document.createElement("input"), s,
+                  function(x) { return function(v) { if (x.value != v) x.value = v; }; }, "password", name);
+    x.value = s.data;
+    x.onkeyup = x.oninput = x.onchange = x.onpropertychange = function() { sv(s, x.value) };
+
+    return x;
+}
+
 function selectValue(x) {
     if (x.options.length == 0)
         return "";
--- a/lib/ur/basis.urs	Fri Aug 15 18:25:56 2014 -0400
+++ b/lib/ur/basis.urs	Sun Aug 10 13:40:53 2014 -0400
@@ -1013,6 +1013,8 @@
 
 val ctextbox : cformTag ([Value = string, Size = int, Source = source string, Placeholder = string, Onchange = transaction unit,
                           Ontext = transaction unit] ++ boxAttrs) []
+val cpassword : cformTag ([Value = string, Size = int, Source = source string, Placeholder = string, Onchange = transaction unit,
+                          Ontext = transaction unit] ++ boxAttrs) []
 val button : cformTag ([Value = string] ++ boxAttrs) []
 
 val ccheckbox : cformTag ([Value = bool, Size = int, Source = source bool, Onchange = transaction unit] ++ boxAttrs) []
--- a/src/css.sml	Fri Aug 15 18:25:56 2014 -0400
+++ b/src/css.sml	Sun Aug 10 13:40:53 2014 -0400
@@ -16,7 +16,7 @@
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
@@ -101,6 +101,7 @@
             ("submit", replaced),
             ("label", inline),
             ("ctextbox", replaced),
+            ("cpassword", replaced),
             ("button", replaced),
             ("ccheckbox", replaced),
             ("cselect", replaced),
--- a/src/monoize.sml	Fri Aug 15 18:25:56 2014 -0400
+++ b/src/monoize.sml	Sun Aug 10 13:40:53 2014 -0400
@@ -3276,14 +3276,14 @@
                                                     (rest, SOME value)
                                                   | _ => (attrs, NONE))
                                              | _ => (attrs, NONE)
-                                       
+
 
                 val (class, fm) = monoExp (env, st, fm) class
                 val (dynClass, fm) = monoExp (env, st, fm) dynClass
                 val (style, fm) = monoExp (env, st, fm) style
                 val (dynStyle, fm) = monoExp (env, st, fm) dynStyle
 
-                val dynamics = ["dyn", "ctextbox", "ccheckbox", "cselect", "coption", "ctextarea", "active", "script"]
+                val dynamics = ["dyn", "ctextbox", "cpassword", "ccheckbox", "cselect", "coption", "ctextarea", "active", "script"]
 
                 fun isSome (e, _) =
                     case e of
@@ -3736,6 +3736,29 @@
 				  fm)
                              end)
 
+                      | "cpassword" =>
+			(case List.find (fn ("Source", _, _) => true | _ => false) attrs of
+                             NONE =>
+                             let
+				 val (ts, fm) = tagStart "input"
+                             in
+				 ((L'.EStrcat (ts,
+                                               strH " type=\"password\" />"),
+                                   loc), fm)
+                             end
+                           | SOME (_, src, _) =>
+                             let
+				 val sc = strcat [str "password(exec(",
+						  (L'.EJavaScript (L'.Script, src), loc),
+						  str "))"]
+				 val sc = setAttrs sc
+                             in
+				 (strcat [str "<script type=\"text/javascript\">",
+					  sc,
+					  str "</script>"],
+				  fm)
+                             end)
+
                       | "ccheckbox" =>
 			(case List.find (fn ("Source", _, _) => true | _ => false) attrs of
                              NONE =>
@@ -4477,7 +4500,7 @@
                             (L'.TFfi ("Basis", "int"), loc)
                         else
                             un
-                            
+
                 val e2 = (L'.EAbs ("$x", t, (L'.TFun (un, un), loc),
                                    (L'.EAbs ("$y", un, un,
                                              (L'.EApp (