comparison lib/js/urweb.js @ 1702:06791667937e

New JavaScript FFI function: setInnerHTML
author Adam Chlipala <adam@chlipala.net>
date Wed, 14 Mar 2012 10:10:56 -0400
parents ea292bf9431f
children 6f2f74cc4ead
comparison
equal deleted inserted replaced
1701:6a4461757829 1702:06791667937e
834 834
835 addNode(x); 835 addNode(x);
836 populate(x); 836 populate(x);
837 } 837 }
838 838
839 function setInnerHTML(node, html) {
840 var x;
841
842 if (node.previousSibling && node.previousSibling.closures != undefined) {
843 x = node.previousSibling;
844
845 for (var ls = x.closures; ls; ls = ls.next)
846 freeClosure(ls.data);
847
848 if (node.getElementsByTagName) {
849 var arr = node.getElementsByTagName("script");
850 for (var i = 0; i < arr.length; ++i)
851 killScript(arr[i]);
852 }
853 } else {
854 x = document.createElement("script");
855 x.dead = false;
856 x.sources = null;
857
858 if (node.parentNode)
859 node.parentNode.insertBefore(x, node);
860 else
861 whine("setInnerHTML: node is not already in the DOM tree");
862 }
863
864 var cls = {v : null};
865 var html = flatten(cls, html);
866 x.closures = cls.v;
867 node.innerHTML = html;
868 runScripts(node);
869 }
870
839 function input(x, s, recreate, type, name) { 871 function input(x, s, recreate, type, name) {
840 if (name) x.name = name; 872 if (name) x.name = name;
841 if (type) x.type = type; 873 if (type) x.type = type;
842 x.dead = false; 874 x.dead = false;
843 x.signal = ss(s); 875 x.signal = ss(s);