Apply JQuery Core Style Guidelines to ajax.js and ajax/*.js,

This commit is contained in:
jaubourg
2011-01-23 05:51:41 +01:00
parent 30082d9eba
commit dd5bf42122
4 changed files with 182 additions and 199 deletions

View File

@@ -2,47 +2,42 @@
// Install script dataType
jQuery.ajaxSetup({
accepts: {
script: "text/javascript, application/javascript"
},
contents: {
script: /javascript/
},
converters: {
"text script": jQuery.globalEval
}
});
// Handle cache's special case and global
jQuery.ajaxPrefilter("script", function(s) {
jQuery.ajaxPrefilter( "script", function(s) {
if ( s.cache === undefined ) {
s.cache = false;
}
if ( s.crossDomain ) {
s.type = "GET";
s.global = false;
}
});
} );
// Bind script tag hack transport
jQuery.ajaxTransport("script", function(s) {
jQuery.ajaxTransport( "script", function(s) {
// This transport only deals with cross domain requests
if ( s.crossDomain ) {
var script,
head = document.getElementsByTagName("head")[0] || document.documentElement;
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";
@@ -53,9 +48,9 @@ jQuery.ajaxTransport("script", function(s) {
script.src = s.url;
// Attach handlers for all browsers
script.onload = script.onreadystatechange = function( _ , isAbort ) {
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;
@@ -66,10 +61,10 @@ jQuery.ajaxTransport("script", function(s) {
}
// Dereference the script
script = 0;
script = undefined;
// Callback if not abort
if ( ! isAbort ) {
if ( !isAbort ) {
callback( 200, "success" );
}
}
@@ -81,11 +76,11 @@ jQuery.ajaxTransport("script", function(s) {
abort: function() {
if ( script ) {
script.onload(0,1);
script.onload( 0, 1 );
}
}
};
}
});
} );
})( jQuery );