Mercurial > urweb
comparison lib/js/urweb.js @ 1039:8932f855fa85
grid0 working in IE
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Sun, 22 Nov 2009 15:30:15 -0500 |
parents | dcc6093e9575 |
children | ca5136105c45 |
comparison
equal
deleted
inserted
replaced
1038:dcc6093e9575 | 1039:8932f855fa85 |
---|---|
114 failHandlers = cons(f, failHandlers); | 114 failHandlers = cons(f, failHandlers); |
115 } | 115 } |
116 | 116 |
117 function doExn(v) { | 117 function doExn(v) { |
118 if (v == null || v.uw_error == null) { | 118 if (v == null || v.uw_error == null) { |
119 var s = (v == null ? "null" : v.toString()); | 119 var s = (v == null ? "null" : v.message ? v.message : v.toString()); |
120 if (v != null && v.fileName && v.lineNumber) | 120 if (v != null && v.fileName && v.lineNumber) |
121 s += " (" + v.fileName + ":" + v.lineNumber + ")"; | 121 s += " (" + v.fileName + ":" + v.lineNumber + ")"; |
122 runHandlers("Fail", failHandlers, s); | 122 runHandlers("Fail", failHandlers, s); |
123 } | 123 } |
124 } | 124 } |
287 var pos = document; | 287 var pos = document; |
288 | 288 |
289 while (pos.lastChild && pos.lastChild.nodeType == 1) | 289 while (pos.lastChild && pos.lastChild.nodeType == 1) |
290 pos = pos.lastChild; | 290 pos = pos.lastChild; |
291 | 291 |
292 return pos.parentNode; | 292 pos = pos.parentNode; |
293 | |
294 return pos; | |
293 } | 295 } |
294 | 296 |
295 function parent() { | 297 function parent() { |
296 return thisScript ? thisScript.parentNode : lastParent(); | 298 return thisScript ? thisScript.parentNode : lastParent(); |
297 } | 299 } |
313 var len = scripts.length; | 315 var len = scripts.length; |
314 for (var i = 0; i < len; ++i) | 316 for (var i = 0; i < len; ++i) |
315 scriptsCopy[i] = scripts[i]; | 317 scriptsCopy[i] = scripts[i]; |
316 for (var i = 0; i < len; ++i) { | 318 for (var i = 0; i < len; ++i) { |
317 thisScript = scriptsCopy[i]; | 319 thisScript = scriptsCopy[i]; |
320 | |
318 try { | 321 try { |
319 eval(thisScript.text); | 322 eval(thisScript.text); |
320 } catch (v) { | 323 } catch (v) { |
321 doExn(v); | 324 doExn(v); |
322 } | 325 } |
353 freeClosure(ls.data); | 356 freeClosure(ls.data); |
354 | 357 |
355 var next; | 358 var next; |
356 for (var child = firstChild; child && child != x; child = next) { | 359 for (var child = firstChild; child && child != x; child = next) { |
357 next = child.nextSibling; | 360 next = child.nextSibling; |
361 | |
358 killScript(child); | 362 killScript(child); |
359 if (child.getElementsByTagName) { | 363 if (child.getElementsByTagName) { |
360 var arr = child.getElementsByTagName("script"); | 364 var arr = child.getElementsByTagName("script"); |
361 for (var i = 0; i < arr.length; ++i) | 365 for (var i = 0; i < arr.length; ++i) |
362 killScript(arr[i]); | 366 killScript(arr[i]); |
365 if (child.parentNode) | 369 if (child.parentNode) |
366 child.parentNode.removeChild(child); | 370 child.parentNode.removeChild(child); |
367 } | 371 } |
368 | 372 |
369 var cls = {v : null}; | 373 var cls = {v : null}; |
370 var html = dynPrefix + flatten(cls, v); | 374 var html = flatten(cls, v); |
375 if (pnode != "table" && pnode != "tr") | |
376 html = dynPrefix + html; | |
371 x.closures = cls.v; | 377 x.closures = cls.v; |
372 | 378 |
373 if (pnode == "table") { | 379 if (pnode == "table") { |
374 var dummy = document.createElement("body"); | 380 var dummy = document.createElement("body"); |
375 dummy.innerHTML = "<table>" + html + "</table>"; | 381 dummy.innerHTML = "<table>" + html + "</table>"; |
376 runScripts(dummy); | 382 runScripts(dummy); |
377 var table = x.parentNode; | 383 var table = x.parentNode; |
378 | 384 |
379 if (table) { | 385 if (table) { |
380 var arr = dummy.getElementsByTagName("tbody"); | |
381 firstChild = null; | 386 firstChild = null; |
382 var tbody; | 387 var tbody; |
383 if (arr.length > 0 && table != null) | 388 |
389 var arr = dummy.getElementsByTagName("tbody"); | |
390 | |
391 var tbody; | |
392 if (arr.length > 0 && arr[0].parentNode == dummy.firstChild) { | |
384 tbody = arr[0]; | 393 tbody = arr[0]; |
385 else | 394 var next; |
395 for (var node = dummy.firstChild.firstChild; node; node = next) { | |
396 next = node.nextSibling; | |
397 | |
398 if (node.tagName != "TBODY") | |
399 tbody.appendChild(node); | |
400 } | |
401 } else | |
386 tbody = dummy.firstChild; | 402 tbody = dummy.firstChild; |
387 | 403 |
388 var next; | 404 var next; |
389 firstChild = document.createElement("script"); | 405 firstChild = document.createElement("script"); |
390 table.insertBefore(firstChild, x); | 406 table.insertBefore(firstChild, x); |
400 var table = x.parentNode; | 416 var table = x.parentNode; |
401 | 417 |
402 if (table) { | 418 if (table) { |
403 var arr = dummy.getElementsByTagName("tr"); | 419 var arr = dummy.getElementsByTagName("tr"); |
404 firstChild = null; | 420 firstChild = null; |
405 var tbody; | 421 var tr; |
406 if (arr.length > 0 && table != null) | 422 if (arr.length > 0 && table != null) |
407 tbody = arr[0]; | 423 tr = arr[0]; |
408 else | 424 else |
409 tbody = dummy.firstChild; | 425 tr = dummy.firstChild; |
410 | 426 |
411 var next; | 427 var next; |
412 firstChild = document.createElement("script"); | 428 firstChild = document.createElement("script"); |
413 table.insertBefore(firstChild, x); | 429 table.insertBefore(firstChild, x); |
414 for (var node = tbody.firstChild; node; node = next) { | 430 for (var node = tr.firstChild; node; node = next) { |
415 next = node.nextSibling; | 431 next = node.nextSibling; |
416 table.insertBefore(node, x); | 432 table.insertBefore(node, x); |
417 } | 433 } |
418 } | 434 } |
419 } else { | 435 } else { |
427 | 443 |
428 addNode(x); | 444 addNode(x); |
429 populate(x); | 445 populate(x); |
430 } | 446 } |
431 | 447 |
432 function input(t, s, recreate) { | 448 function input(t, s, recreate, type) { |
433 var x = document.createElement(t); | 449 var x = document.createElement(t); |
450 if (type) x.type = type; | |
434 x.dead = false; | 451 x.dead = false; |
435 x.signal = ss(s); | 452 x.signal = ss(s); |
436 x.sources = null; | 453 x.sources = null; |
437 x.recreate = recreate(x); | 454 x.recreate = recreate(x); |
438 addNode(x); | 455 addNode(x); |
459 | 476 |
460 return x; | 477 return x; |
461 } | 478 } |
462 | 479 |
463 function chk(s) { | 480 function chk(s) { |
464 var x = input("input", s, function(x) { return function(v) { if (x.checked != v) x.checked = v; }; }); | 481 var x = input("input", s, function(x) { return function(v) { if (x.checked != v) x.checked = v; }; }, "checkbox"); |
465 x.type = "checkbox"; | |
466 x.checked = s.data; | 482 x.checked = s.data; |
467 x.onchange = function() { sv(s, x.checked) }; | 483 x.onchange = function() { sv(s, x.checked) }; |
468 | 484 |
469 return x; | 485 return x; |
470 } | 486 } |