X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fajax%2Fscript.js;h=764a80699e34f89666bee271381aff1686ae514f;hb=refs%2Fheads%2Fgetscript-fix;hp=75f34fce20b6bc753b6a79f937fd6173e0e8e9db;hpb=e221d39e981ceac030d2e0431570742fb51337d5;p=jquery.git diff --git a/src/ajax/script.js b/src/ajax/script.js index 75f34fc..764a806 100644 --- a/src/ajax/script.js +++ b/src/ajax/script.js @@ -2,41 +2,48 @@ // Install script dataType jQuery.ajaxSetup({ - accepts: { - script: "text/javascript, application/javascript" + script: "text/javascript, application/javascript, application/ecmascript, application/x-ecmascript" }, - contents: { - script: /javascript/ + script: /javascript|ecmascript/ }, - converters: { - "text script": jQuery.globalEval + "text script": function( text ) { + jQuery.globalEval( text ); + return text; + } } }); -// Bind script tag hack transport -jQuery.ajax.transport("script", function(s) { - - // Handle cache special case +// Handle cache's special case and global +jQuery.ajaxPrefilter( "script", function( s ) { if ( s.cache === undefined ) { s.cache = false; } + if ( s.crossDomain ) { + s.type = "GET"; + s.global = false; + } +} ); - // This transport only deals with cross domain get requests - if ( s.crossDomain && s.async && ( s.type === "GET" || ! s.data ) ) { +// Bind script tag hack transport +jQuery.ajaxTransport( "script", function(s) { - s.global = false; + // This transport primarily deals with cross domain requests + // but also sameDomain request within file:// due to + // http://code.google.com/p/chromium/issues/detail?id=4197 + 47416 + var local = location.protocol === 'file:'; + if ( s.crossDomain || local ) { var script, - head = document.getElementsByTagName("head")[0] || document.documentElement; + head = document.head || document.getElementsByTagName( "head" )[0] || document.documentElement; return { - send: function(_, callback) { + send: function( _, callback ) { - script = document.createElement("script"); + script = document.createElement( "script" ); script.async = "async"; @@ -47,9 +54,9 @@ jQuery.ajax.transport("script", function(s) { script.src = s.url; // Attach handlers for all browsers - script.onload = script.onreadystatechange = function( _ , statusText) { + script.onload = script.onreadystatechange = function( _, isAbort ) { - if ( ! script.readyState || /loaded|complete/.test( script.readyState ) ) { + if ( !script.readyState || /loaded|complete/.test( script.readyState ) ) { // Handle memory leak in IE script.onload = script.onreadystatechange = null; @@ -59,10 +66,13 @@ jQuery.ajax.transport("script", function(s) { head.removeChild( script ); } - script = 0; + // Dereference the script + script = undefined; - // Callback - callback( statusText ? 0 : 200, statusText || "success" ); + // Callback if not abort + if ( !isAbort ) { + callback( 200, "success" ); + } } }; // Use insertBefore instead of appendChild to circumvent an IE6 bug. @@ -70,13 +80,13 @@ jQuery.ajax.transport("script", function(s) { head.insertBefore( script, head.firstChild ); }, - abort: function(statusText) { + abort: function() { if ( script ) { - script.onload( 0 , statusText ); + script.onload( 0, 1 ); } } }; } -}); +} ); })( jQuery );