Commit 9ea8017f authored by David Serduke's avatar David Serduke

Fixed #1959 by postponing ALL script evaluations till the html insertion is...

Fixed #1959 by postponing ALL script evaluations till the html insertion is done. Before the code would immediately execute any scripts that weren't in subelements if no subelements prior had scripts in them (i.e. once any script was postponed they all were). This could cause inconsistent behavior. Since, at this time, we have to postpone some scripts it makes more sense to postpone them all.
parent f97f77c0
...@@ -494,16 +494,9 @@ jQuery.fn = jQuery.prototype = { ...@@ -494,16 +494,9 @@ jQuery.fn = jQuery.prototype = {
this.cloneNode( true ) : this.cloneNode( true ) :
this; this;
// execute all scripts after the elements have been injected
if ( jQuery.nodeName( elem, "script" ) ) { if ( jQuery.nodeName( elem, "script" ) ) {
// If scripts are waiting to be executed, wait on this script as well
if ( scripts.length )
scripts = scripts.add( elem ); scripts = scripts.add( elem );
// If nothing is waiting to be executed, run immediately
else
evalScript( 0, elem );
} else { } else {
// Remove any inner scripts for later evaluation // Remove any inner scripts for later evaluation
if ( elem.nodeType == 1 ) if ( elem.nodeType == 1 )
......
...@@ -1022,7 +1022,8 @@ test("html(String)", function() { ...@@ -1022,7 +1022,8 @@ test("html(String)", function() {
$("#main").html('foo <form><script type="text/javascript">ok( true, "$().html().evalScripts() Evals Scripts Twice in Firefox, see #975" );</script></form>'); $("#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>"); // it was decided that waiting to execute ALL scripts makes sense since nested ones have to wait anyway so this test case is changed, see #1959
$("#main").html("<script>ok(scriptorder++ == 0, 'Script is executed in order');ok($('#scriptorder').length == 1,'Execute after html (even though appears before)')<\/script><span id='scriptorder'><script>ok(scriptorder++ == 1, 'Script (nested) is executed in order');ok($('#scriptorder').length == 1,'Execute after html')<\/script></span><script>ok(scriptorder++ == 2, 'Script (unnested) is executed in order');ok($('#scriptorder').length == 1,'Execute after html')<\/script>");
setTimeout( start, 100 ); setTimeout( start, 100 );
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment