changeset 901:f17638dd3080

dlist row add working with Konqueror
author Adam Chlipala <adamc@hcoop.net>
date Thu, 06 Aug 2009 14:24:40 -0400
parents ed381288ce9a
children 4b9f1de2c647
files lib/js/urweb.js src/monoize.sml
diffstat 2 files changed, 53 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/lib/js/urweb.js	Thu Aug 06 11:58:38 2009 -0400
+++ b/lib/js/urweb.js	Thu Aug 06 14:24:40 2009 -0400
@@ -252,7 +252,7 @@
         doExn(v);
       }
       if (thisScript.parentNode)
-        thisScripts.parentNode.removeChild(thisScript);
+        thisScript.parentNode.removeChild(thisScript);
     }
 
     thisScript = savedScript;
@@ -262,23 +262,22 @@
 
 // Dynamic tree entry points
 
-function dyn(s) {
-  var x = document.createElement("div");
-  x.style.display = "inline";
+function dyn(pnode, s) {
+  var x = document.createElement("script");
   x.dead = false;
   x.signal = s;
   x.sources = null;
   x.closures = null;
 
-  var first = null;
+  var child = null;
 
   x.recreate = function(v) {
     for (var ls = x.closures; ls; ls = ls.next)
       freeClosure(ls.data);
 
-    for (var node = first; node && node != x; ) {
-      if (node.getElementsByTagName) {
-        var arr = node.getElementsByTagName("div");
+    if (child) {
+      if (child.getElementsByTagName) {
+        var arr = child.getElementsByTagName("script");
         for (var i = 0; i < arr.length; ++i) {
           var span = arr[i];
           span.dead = true;
@@ -289,24 +288,36 @@
         }
       }
 
-      var old = node;
-      node = node.nextSibling;
-      if (old.parentNode)
-        old.parentNode.removeChild(old);
+      if (child.parentNode)
+        child.parentNode.removeChild(child);
     }
 
     var cls = {v : null};
-    var dummy = document.createElement("table");
-    dummy.innerHTML = flatten(cls, v);
+    var html = flatten(cls, v);
     x.closures = cls.v;
-    runScripts(dummy);
 
-    for (first = dummy.firstChild; first && first.tagName == "TBODY"; first = first.firstChild);
-    for (var node = first; node; ) {
-      var old = node;
-      node = node.nextSibling;
+    if (pnode == "table") {
+      var dummy = document.createElement("body");
+      dummy.innerHTML = "<table>" + html + "</table>";
+      runScripts(dummy);
+      var rows = dummy.firstChild.rows;
+      var nRows = rows.length;
+      var table = x.parentNode;
+
+      var arr = dummy.getElementsByTagName("tbody");
+      if (arr.length > 0) {
+        var tbody = arr[0], next;
+        for (var node = tbody.firstChild; node; node = next) {
+          next = node.nextSibling;
+          table.appendChild(node);
+        }
+      }
+    } else {
+      child = document.createElement("span");
+      child.innerHTML = html;
+      runScripts(child);
       if (x.parentNode)
-        x.parentNode.insertBefore(old, x);
+        x.parentNode.insertBefore(child, x);
     }
   };
 
--- a/src/monoize.sml	Thu Aug 06 11:58:38 2009 -0400
+++ b/src/monoize.sml	Thu Aug 06 14:24:40 2009 -0400
@@ -2644,14 +2644,28 @@
                     end
 
                   | "dyn" =>
-                    (case attrs of
-                         [("Signal", e, _)] =>
-                         ((L'.EStrcat
-                               ((L'.EPrim (Prim.String ("<script type=\"text/javascript\">dyn(")), loc),
-                                (L'.EStrcat ((L'.EJavaScript (L'.Script, e), loc),
-                                             (L'.EPrim (Prim.String (")</script>")), loc)), loc)), loc),
-                          fm)
-                       | _ => raise Fail "Monoize: Bad dyn attributes")
+                    let
+                        val inTable = case targs of
+                                          (L.CRecord (_, ctx), _) :: _ =>
+                                          List.exists (fn ((L.CName "Table", _), _) => true
+                                                        | _ => false) ctx
+                                        | _ => false
+                                               
+                        val tag = if inTable then
+                                      "table"
+                                  else
+                                      "span"
+                    in
+                        case attrs of
+                            [("Signal", e, _)] =>
+                            ((L'.EStrcat
+                                  ((L'.EPrim (Prim.String ("<script type=\"text/javascript\">dyn(\""
+                                                           ^ tag ^ "\", ")), loc),
+                                   (L'.EStrcat ((L'.EJavaScript (L'.Script, e), loc),
+                                                (L'.EPrim (Prim.String (")</script>")), loc)), loc)), loc),
+                             fm)
+                          | _ => raise Fail "Monoize: Bad dyn attributes"
+                    end
                     
                   | "submit" => normal ("input type=\"submit\"", NONE, NONE)
                   | "button" => normal ("input type=\"submit\"", NONE, NONE)