Brought back jQuery.globalEval(), fixing bug #1425.

This commit is contained in:
John Resig 2007-07-31 02:59:53 +00:00
parent 4ae80a1e2c
commit 6b0d3bb273
2 changed files with 17 additions and 2 deletions

View File

@ -765,7 +765,7 @@ jQuery.extend({
// If the type is "script", eval it in global context // If the type is "script", eval it in global context
if ( type == "script" ) if ( type == "script" )
(new Function( data ))(); jQuery.globalEval( data );
// Get the JavaScript object, if JSON is used. // Get the JavaScript object, if JSON is used.
if ( type == "json" ) if ( type == "json" )

17
src/jquery/jquery.js vendored
View File

@ -1191,7 +1191,7 @@ jQuery.fn = jQuery.prototype = {
if ( this.src ) if ( this.src )
jQuery.ajax({ url: this.src, async: false, dataType: "script" }); jQuery.ajax({ url: this.src, async: false, dataType: "script" });
else else
(new Function( this.text || this.textContent || this.innerHTML || "" ))(); jQuery.globalEval( this.text || this.textContent || this.innerHTML || "" );
} else } else
fn.apply( obj, [ clone ? this.cloneNode(true) : this ] ); fn.apply( obj, [ clone ? this.cloneNode(true) : this ] );
}); });
@ -1322,6 +1322,21 @@ jQuery.extend({
elem.tagName && elem.ownerDocument && !elem.ownerDocument.body; elem.tagName && elem.ownerDocument && !elem.ownerDocument.body;
}, },
// Evalulates a script in a global context
// Evaluates Async. in Safari 2 :-(
globalEval: function( data ) {
data = jQuery.trim( data );
if ( data ) {
if ( window.execScript )
window.execScript( data );
else if ( jQuery.browser.safari )
// safari doesn't provide a synchronous global eval
window.setTimeout( data, 0 );
else
eval.call( window, data );
}
},
nodeName: function( elem, name ) { nodeName: function( elem, name ) {
return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase(); return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase();
}, },