AMD-ify jQuery sourcegit s! Woo! Fixes #14113, #14163.

This commit is contained in:
Timmy Willison
2013-08-15 14:15:49 -04:00
parent 7627b8b6d9
commit 6318ae6ab9
77 changed files with 27783 additions and 1580 deletions

View File

@@ -1,3 +1,10 @@
define([
"../core",
"./var/nonce",
"./var/rquery",
"../ajax"
], function( jQuery, nonce, rquery ) {
var oldCallbacks = [],
rjsonp = /(=)\?(?=&|$)|\?\?/;
@@ -5,7 +12,7 @@ var oldCallbacks = [],
jQuery.ajaxSetup({
jsonp: "callback",
jsonpCallback: function() {
var callback = oldCallbacks.pop() || ( jQuery.expando + "_" + ( ajax_nonce++ ) );
var callback = oldCallbacks.pop() || ( jQuery.expando + "_" + ( nonce++ ) );
this[ callback ] = true;
return callback;
}
@@ -32,7 +39,7 @@ jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) {
if ( jsonProp ) {
s[ jsonProp ] = s[ jsonProp ].replace( rjsonp, "$1" + callbackName );
} else if ( s.jsonp !== false ) {
s.url += ( ajax_rquery.test( s.url ) ? "&" : "?" ) + s.jsonp + "=" + callbackName;
s.url += ( rquery.test( s.url ) ? "&" : "?" ) + s.jsonp + "=" + callbackName;
}
// Use data converter to retrieve json after script execution
@@ -78,3 +85,5 @@ jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) {
return "script";
}
});
});

71
src/ajax/load.js Normal file
View File

@@ -0,0 +1,71 @@
define([
"../core",
"../ajax",
"../traversing",
"../selector"
], function( jQuery ) {
// Keep a copy of the old load method
var _load = jQuery.fn.load;
/**
* Load a url into a page
*/
jQuery.fn.load = function( url, params, callback ) {
if ( typeof url !== "string" && _load ) {
return _load.apply( this, arguments );
}
var selector, type, response,
self = this,
off = url.indexOf(" ");
if ( off >= 0 ) {
selector = url.slice( off );
url = url.slice( 0, off );
}
// If it's a function
if ( jQuery.isFunction( params ) ) {
// We assume that it's the callback
callback = params;
params = undefined;
// Otherwise, build a param string
} else if ( params && typeof params === "object" ) {
type = "POST";
}
// If we have elements to modify, make the request
if ( self.length > 0 ) {
jQuery.ajax({
url: url,
// if "type" variable is undefined, then "GET" method will be used
type: type,
dataType: "html",
data: params
}).done(function( responseText ) {
// Save response for use in complete callback
response = arguments;
self.html( selector ?
// If a selector was specified, locate the right elements in a dummy div
// Exclude scripts to avoid IE 'Permission Denied' errors
jQuery("<div>").append( jQuery.parseHTML( responseText ) ).find( selector ) :
// Otherwise use the full result
responseText );
}).complete( callback && function( jqXHR, status ) {
self.each( callback, response || [ jqXHR.responseText, status, jqXHR ] );
});
}
return this;
};
});

View File

@@ -1,3 +1,8 @@
define([
"../core",
"../ajax"
], function( jQuery ) {
// Install script dataType
jQuery.ajaxSetup({
accepts: {
@@ -55,3 +60,5 @@ jQuery.ajaxTransport( "script", function( s ) {
};
}
});
});

5
src/ajax/var/nonce.js Normal file
View File

@@ -0,0 +1,5 @@
define([
"../../core"
], function( jQuery ) {
return jQuery.now();
});

3
src/ajax/var/rquery.js Normal file
View File

@@ -0,0 +1,3 @@
define(function() {
return /\?/;
});

View File

@@ -1,3 +1,8 @@
define([
"../core",
"../ajax"
], function( jQuery ) {
jQuery.ajaxSettings.xhr = function() {
try {
return new XMLHttpRequest();
@@ -109,3 +114,5 @@ jQuery.ajaxTransport(function( options ) {
};
}
});
});