jQuery: The Write Less, Do More JavaScript Library

Changeset 3296

Show
Ignore:
Timestamp:
09/15/07 02:16:29 (1 year ago)
Author:
jeresig
Message:

Fixed bug #1594, #1565, #1598 - all of which were concerning the improper execution of embedded scripts in IE and Safari.

Location:
trunk/jquery
Files:
2 modified

Legend:

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

    r3281 r3296  
    395395 
    396396            jQuery.each( a, function(){ 
    397                 if ( jQuery.nodeName(this, "script") ) { 
    398                     if ( this.src ) 
    399                         jQuery.ajax({ url: this.src, async: false, dataType: "script" }); 
    400                     else 
    401                         jQuery.globalEval( this.text || this.textContent || this.innerHTML || "" ); 
    402                 } else 
    403                     fn.apply( obj, [ clone ? this.cloneNode(true) : this ] ); 
     397                var elem = clone ? this.cloneNode(true) : this; 
     398                if ( !evalScript(0, elem) ) 
     399                    fn.call( obj, elem ); 
    404400            }); 
    405401        }); 
    406402    } 
    407403}; 
     404 
     405function evalScript(i, elem){ 
     406    var script = jQuery.nodeName(elem, "script"); 
     407 
     408    if ( script ) { 
     409        if ( elem.src ) 
     410            jQuery.ajax({ url: elem.src, async: false, dataType: "script" }); 
     411        else 
     412            jQuery.globalEval( elem.text || elem.textContent || elem.innerHTML || "" ); 
     413     
     414        if ( elem.parentNode ) 
     415            elem.parentNode.removeChild(elem); 
     416 
     417    } else if ( elem.nodeType == 1 ) 
     418    jQuery("script", elem).each(evalScript); 
     419 
     420    return script; 
     421} 
    408422 
    409423jQuery.extend = jQuery.fn.extend = function() { 
  • trunk/jquery/test/unit/core.js

    r3139 r3296  
    822822 
    823823test("html(String)", function() { 
    824     expect(1); 
     824    expect(3); 
    825825    var div = $("div"); 
    826826    div.html("<b>test</b>"); 
     
    831831    ok( pass, "Set HTML" ); 
    832832 
    833     // Ccommented out until we can resolve it    
    834     // $("#main").html('<script type="text/javascript">ok( true, "$().html().evalScripts() Evals Scripts Twice in Firefox, see #975" );</script>').evalScripts(); 
     833    stop(); 
     834 
     835    $("#main").html('<script type="text/javascript">ok( true, "$().html().evalScripts() Evals Scripts Twice in Firefox, see #975" );</script>'); 
     836 
     837    $("#main").html('foo <form><script type="text/javascript">ok( true, "$().html().evalScripts() Evals Scripts Twice in Firefox, see #975" );</script></form>'); 
     838 
     839    setTimeout( start, 100 ); 
    835840}); 
    836841