comparison lib/js/urweb.js @ 1040:ca5136105c45

Get dynamic <select> working in IE
author Adam Chlipala <adamc@hcoop.net>
date Sun, 22 Nov 2009 16:40:09 -0500
parents 8932f855fa85
children 0d767c8d2923
comparison
equal deleted inserted replaced
1039:8932f855fa85 1040:ca5136105c45
443 443
444 addNode(x); 444 addNode(x);
445 populate(x); 445 populate(x);
446 } 446 }
447 447
448 function input(t, s, recreate, type) { 448 function input(x, s, recreate, type) {
449 var x = document.createElement(t);
450 if (type) x.type = type; 449 if (type) x.type = type;
451 x.dead = false; 450 x.dead = false;
452 x.signal = ss(s); 451 x.signal = ss(s);
453 x.sources = null; 452 x.sources = null;
454 x.recreate = recreate(x); 453 x.recreate = recreate(x);
457 456
458 return x; 457 return x;
459 } 458 }
460 459
461 function inp(s) { 460 function inp(s) {
462 var x = input("input", s, function(x) { return function(v) { if (x.value != v) x.value = v; }; }); 461 var x = input(document.createElement("input"), s,
462 function(x) { return function(v) { if (x.value != v) x.value = v; }; });
463 x.value = s.data; 463 x.value = s.data;
464 x.onkeyup = function() { sv(s, x.value) }; 464 x.onkeyup = function() { sv(s, x.value) };
465 465
466 return x; 466 return x;
467 } 467 }
468 468
469 function sel(s, content) { 469 function sel(s, content) {
470 var x = input("select", s, function(x) { return function(v) { if (x.value != v) x.value = v; }; }); 470 var dummy = document.createElement("span");
471 x.innerHTML = content; 471 dummy.innerHTML = "<select>" + content + "</select>";
472 var x = input(dummy.firstChild, s, function(x) { return function(v) { if (x.value != v) x.value = v; }; });
472 x.value = s.data; 473 x.value = s.data;
473 if (x.value != s.data) 474 if (x.value != s.data)
474 sv(s, x.value); 475 sv(s, x.value);
475 x.onchange = function() { sv(s, x.value) }; 476 x.onchange = function() { sv(s, x.value) };
476 477
477 return x; 478 return x;
478 } 479 }
479 480
480 function chk(s) { 481 function chk(s) {
481 var x = input("input", s, function(x) { return function(v) { if (x.checked != v) x.checked = v; }; }, "checkbox"); 482 var x = input(document.createElement("input"), s,
483 function(x) { return function(v) { if (x.checked != v) x.checked = v; }; }, "checkbox");
482 x.checked = s.data; 484 x.checked = s.data;
483 x.onchange = function() { sv(s, x.checked) }; 485 x.onchange = function() { sv(s, x.checked) };
484 486
485 return x; 487 return x;
486 } 488 }