if ( table && jQuery.nodeName( this, "table" ) && jQuery.nodeName( elems[0], "tr" ) )\r
obj = this.getElementsByTagName("tbody")[0] || this.appendChild( document.createElement("tbody") );\r
\r
+ var scripts = jQuery( [] );\r
+\r
jQuery.each(elems, function(){\r
var elem = clone ?\r
this.cloneNode( true ) :\r
this;\r
\r
- if ( !evalScript( 0, elem ) )\r
+ if ( jQuery.nodeName( elem, "script" ) ) {\r
+\r
+ // If scripts are waiting to be executed, wait on this script as well\r
+ if ( scripts.length )\r
+ scripts = scripts.add( elem );\r
+\r
+ // If nothing is waiting to be executed, run immediately\r
+ else\r
+ evalScript( 0, elem );\r
+\r
+ } else {\r
+ // Remove any inner scripts for later evaluation\r
+ if ( elem.nodeType == 1 )\r
+ scripts = scripts.add( jQuery( "script", elem ).remove() );\r
+\r
+ // Inject the elements into the document\r
callback.call( obj, elem );\r
+ }\r
});\r
+\r
+ scripts.each( evalScript );\r
});\r
}\r
};\r
\r
function evalScript( i, elem ) {\r
- var script = jQuery.nodeName( elem, "script" );\r
-\r
- if ( script ) {\r
- if ( elem.src )\r
- jQuery.ajax({\r
- url: elem.src,\r
- async: false,\r
- dataType: "script"\r
- });\r
-\r
- else\r
- jQuery.globalEval( elem.text || elem.textContent || elem.innerHTML || "" );\r
- \r
- if ( elem.parentNode )\r
- elem.parentNode.removeChild( elem );\r
+ if ( elem.src )\r
+ jQuery.ajax({\r
+ url: elem.src,\r
+ async: false,\r
+ dataType: "script"\r
+ });\r
\r
- } else if ( elem.nodeType == 1 )\r
- jQuery( "script", elem ).each( evalScript );\r
+ else\r
+ jQuery.globalEval( elem.text || elem.textContent || elem.innerHTML || "" );\r
\r
- return script;\r
+ if ( elem.parentNode )\r
+ elem.parentNode.removeChild( elem );\r
}\r
\r
jQuery.extend = jQuery.fn.extend = function() {\r
ok( $("#select1").val() == "3", "Check for modified (via val(String)) value of select element" );
});
+var scriptorder = 0;
+
test("html(String)", function() {
- expect(3);
+ expect(9);
var div = $("div");
div.html("<b>test</b>");
var pass = true;
$("#main").html('foo <form><script type="text/javascript">ok( true, "$().html().evalScripts() Evals Scripts Twice in Firefox, see #975" );</script></form>');
+ $("#main").html("<script>ok(scriptorder++ == 0, 'Script is executed in order');ok($('#scriptorder').length == 0,'Execute before html')<\/script><span id='scriptorder'><script>ok(scriptorder++ == 1, 'Script is executed in order');ok($('#scriptorder').length == 1,'Execute after html')<\/script></span><script>ok(scriptorder++ == 2, 'Script is executed in order');ok($('#scriptorder').length == 1,'Execute after html')<\/script>");
+
setTimeout( start, 100 );
});