Bug Tracker

Changeset 2428

Show
Ignore:
Timestamp:
07/20/07 21:59:52 (1 year ago)
Author:
jeresig
Message:

Completely reworked the evalScripts() code, fixing bugs #1332, #975, and #777.

Location:
trunk/jquery/src
Files:
2 modified

Legend:

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

    r2420 r2428  
    7676            ifModified: ifModified, 
    7777            complete: function(res, status){ 
     78                // If successful, inject the HTML into all the matched elements 
    7879                if ( status == "success" || !ifModified && status == "notmodified" ) 
    79                     // Inject the HTML into all the matched elements 
    80                     self.attr("innerHTML", res.responseText) 
    81                       // Execute all the scripts inside of the newly-injected HTML 
    82                       .evalScripts() 
    83                       // Execute callback 
    84                       .each( callback, [res.responseText, status, res] ); 
    85                 else 
    86                     callback.apply( self, [res.responseText, status, res] ); 
     80                    self.html(res.responseText) 
     81 
     82                self.each( callback, [res.responseText, status, res] ); 
    8783            } 
    8884        }); 
     
    111107    serialize: function() { 
    112108        return jQuery.param( this ); 
    113     }, 
    114  
    115     /** 
    116      * Evaluate all script tags inside this jQuery. If they have a src attribute, 
    117      * the script is loaded, otherwise it's content is evaluated. 
    118      * 
    119      * @name evalScripts 
    120      * @type jQuery 
    121      * @private 
    122      * @cat Ajax 
    123      */ 
    124     evalScripts: function() { 
    125         return this.find("script").each(function(){ 
    126             if ( this.src ) 
    127                 jQuery.getScript( this.src ); 
    128             else 
    129                 jQuery.globalEval( this.text || this.textContent || this.innerHTML || "" ); 
    130         }).end(); 
    131109    } 
    132110 
     
    657635                try { 
    658636                    status = isTimeout == "timeout" && "timeout" || 
    659                                     !jQuery.httpSuccess( xml ) && "error" || 
    660                                     s.ifModified && jQuery.httpNotModified( xml, s.url ) && "notmodified" || 
    661                                     "success"; 
     637                        !jQuery.httpSuccess( xml ) && "error" || 
     638                        s.ifModified && jQuery.httpNotModified( xml, s.url ) && "notmodified" || 
     639                        "success"; 
     640 
    662641                    // Make sure that the request was successful or notmodified 
    663642                    if ( status != "error" && status != "timeout" ) { 
     
    784763        // If the type is "script", eval it in global context 
    785764        if ( type == "script" ) 
    786             jQuery.globalEval( data ); 
     765            (new Function( data ))(); 
    787766 
    788767        // Get the JavaScript object, if JSON is used. 
    789768        if ( type == "json" ) 
    790769            data = eval("(" + data + ")"); 
    791  
    792         // evaluate scripts within html 
    793         if ( type == "html" ) 
    794             jQuery("<div>").html(data).evalScripts(); 
    795770 
    796771        return data; 
     
    824799        // Return the resulting serialization 
    825800        return s.join("&"); 
    826     }, 
    827      
    828     // evalulates a script in global context 
    829     // not reliable for safari 
    830     globalEval: function( data ) { 
    831         data = jQuery.trim( data ); 
    832         if ( data ) { 
    833             if ( window.execScript ) 
    834                 window.execScript( data ); 
    835             else if ( jQuery.browser.safari ) 
    836                 // safari doesn't provide a synchronous global eval 
    837                 window.setTimeout( data, 0 ); 
    838             else 
    839                 eval.call( window, data ); 
    840         } 
    841801    } 
    842802 
  • trunk/jquery/src/jquery/jquery.js

    r2422 r2428  
    11721172 
    11731173            jQuery.each( a, function(){ 
    1174                 fn.apply( obj, [ clone ? this.cloneNode(true) : this ] ); 
     1174                if ( jQuery.nodeName(this, "script") ) { 
     1175                    if ( this.src ) 
     1176                        jQuery.ajax({ url: this.src, async: false, dataType: "script" }); 
     1177                    else 
     1178                        (new Function( this.text || this.textContent || this.innerHTML || "" ))(); 
     1179                } else 
     1180                    fn.apply( obj, [ clone ? this.cloneNode(true) : this ] ); 
    11751181            }); 
    1176  
    11771182        }); 
    11781183    }