summaryrefslogtreecommitdiff
path: root/lib/js/urweb.js
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adam@chlipala.net>2011-08-14 17:39:18 -0400
committerGravatar Adam Chlipala <adam@chlipala.net>2011-08-14 17:39:18 -0400
commitc58370c7b4a4cc6027baf7b6ebfcc1dcab181666 (patch)
treee5943aaf8f088e60d96a4c87d7228ec3c62c9593 /lib/js/urweb.js
parent882b016302da2645ff07ccaf9c78eaa60f736461 (diff)
Fix bug with <dyn> as first child of <table>
Diffstat (limited to 'lib/js/urweb.js')
-rw-r--r--lib/js/urweb.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/js/urweb.js b/lib/js/urweb.js
index 6343543e..77fc5d79 100644
--- a/lib/js/urweb.js
+++ b/lib/js/urweb.js
@@ -385,6 +385,37 @@ function killScript(scr) {
freeClosure(ls.data);
}
+// Sometimes we wind up with tables that contain <script>s outside the single <tbody>.
+// To avoid dealing with that case, we normalize by moving <script>s into <tbody>.
+function normalizeTable(table) {
+ var orig = table;
+
+ var script, next;
+
+ while (table.tagName != "TABLE")
+ table = table.parentNode;
+
+ for (var tbody = table.firstChild; tbody; tbody = tbody.nextSibling) {
+ if (tbody.tagName == "TBODY") {
+ for (script = table.firstChild; script && script != tbody; script = next) {
+ next = script.nextSibling;
+
+ tbody.insertBefore(script, tbody.firstChild);
+ }
+
+ return;
+ }
+ }
+
+ var tbody = document.createElement("tbody");
+ for (script = table.firstChild; script; script = next) {
+ next = script.nextSibling;
+
+ tbody.insertBefore(script, tbody.firstChild);
+ }
+ table.appendChild(tbody);
+}
+
function dyn(pnode, s) {
var x = document.createElement("script");
x.dead = false;
@@ -420,6 +451,8 @@ function dyn(pnode, s) {
x.closures = cls.v;
if (pnode == "table") {
+ normalizeTable(x.parentNode);
+
var dummy = document.createElement("body");
dummy.innerHTML = "<table>" + html + "</table>";
runScripts(dummy);