comparison lib/js/urweb.js @ 1538:ade93cd5bc59

Fix bug with <dyn> as first child of <table>
author Adam Chlipala <adam@chlipala.net>
date Sun, 14 Aug 2011 17:39:18 -0400
parents 883347f5c3c2
children 355a928871ff
comparison
equal deleted inserted replaced
1537:e627bab3eda7 1538:ade93cd5bc59
383 ls.data.dyns = remove(scr, ls.data.dyns); 383 ls.data.dyns = remove(scr, ls.data.dyns);
384 for (var ls = scr.closures; ls; ls = ls.next) 384 for (var ls = scr.closures; ls; ls = ls.next)
385 freeClosure(ls.data); 385 freeClosure(ls.data);
386 } 386 }
387 387
388 // Sometimes we wind up with tables that contain <script>s outside the single <tbody>.
389 // To avoid dealing with that case, we normalize by moving <script>s into <tbody>.
390 function normalizeTable(table) {
391 var orig = table;
392
393 var script, next;
394
395 while (table.tagName != "TABLE")
396 table = table.parentNode;
397
398 for (var tbody = table.firstChild; tbody; tbody = tbody.nextSibling) {
399 if (tbody.tagName == "TBODY") {
400 for (script = table.firstChild; script && script != tbody; script = next) {
401 next = script.nextSibling;
402
403 tbody.insertBefore(script, tbody.firstChild);
404 }
405
406 return;
407 }
408 }
409
410 var tbody = document.createElement("tbody");
411 for (script = table.firstChild; script; script = next) {
412 next = script.nextSibling;
413
414 tbody.insertBefore(script, tbody.firstChild);
415 }
416 table.appendChild(tbody);
417 }
418
388 function dyn(pnode, s) { 419 function dyn(pnode, s) {
389 var x = document.createElement("script"); 420 var x = document.createElement("script");
390 x.dead = false; 421 x.dead = false;
391 x.signal = s; 422 x.signal = s;
392 x.sources = null; 423 x.sources = null;
418 if (pnode != "table" && pnode != "tr") 449 if (pnode != "table" && pnode != "tr")
419 html = dynPrefix + html; 450 html = dynPrefix + html;
420 x.closures = cls.v; 451 x.closures = cls.v;
421 452
422 if (pnode == "table") { 453 if (pnode == "table") {
454 normalizeTable(x.parentNode);
455
423 var dummy = document.createElement("body"); 456 var dummy = document.createElement("body");
424 dummy.innerHTML = "<table>" + html + "</table>"; 457 dummy.innerHTML = "<table>" + html + "</table>";
425 runScripts(dummy); 458 runScripts(dummy);
426 var table = x.parentNode; 459 var table = x.parentNode;
427 460