jQuery: The Write Less, Do More JavaScript Library

Changeset 4094

Show
Ignore:
Timestamp:
12/10/07 19:04:59 (8 months ago)
Author:
davidserduke
Message:

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.

Location:
trunk/jquery
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/jquery/src/core.js

    r4091 r4094  
    495495                    this; 
    496496 
     497                // execute all scripts after the elements have been injected 
    497498                if ( jQuery.nodeName( elem, "script" ) ) { 
    498  
    499                     // If scripts are waiting to be executed, wait on this script as well 
    500                     if ( scripts.length ) 
    501                         scripts = scripts.add( elem ); 
    502  
    503                     // If nothing is waiting to be executed, run immediately 
    504                     else 
    505                         evalScript( 0, elem ); 
    506  
     499                    scripts = scripts.add( elem ); 
    507500                } else { 
    508501                    // Remove any inner scripts for later evaluation 
  • trunk/jquery/test/unit/core.js

    r4074 r4094  
    10231023    $("#main").html('foo <form><script type="text/javascript">ok( true, "$().html().evalScripts() Evals Scripts Twice in Firefox, see #975" );</script></form>'); 
    10241024 
    1025     $("#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>"); 
     1025    // 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 
     1026    $("#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>"); 
    10261027 
    10271028    setTimeout( start, 100 );