aboutsummaryrefslogtreecommitdiffstats
path: root/src/ajax
diff options
context:
space:
mode:
authorTimmy Willison <timmywillisn@gmail.com>2013-08-15 14:15:49 -0400
committerTimmy Willison <timmywillisn@gmail.com>2013-08-15 14:15:49 -0400
commit6318ae6ab90d4b450dfadf32ab95fe52ed6331cb (patch)
tree50b247fed8569e909e380b281e9145bd1458a39e /src/ajax
parent7627b8b6d9ef6e57dbd20a55b946bd1991c1223e (diff)
downloadjquery-6318ae6ab90d4b450dfadf32ab95fe52ed6331cb.tar.gz
jquery-6318ae6ab90d4b450dfadf32ab95fe52ed6331cb.zip
AMD-ify jQuery sourcegit s! Woo! Fixes #14113, #14163.
Diffstat (limited to 'src/ajax')
-rw-r--r--src/ajax/jsonp.js13
-rw-r--r--src/ajax/load.js71
-rw-r--r--src/ajax/script.js7
-rw-r--r--src/ajax/var/nonce.js5
-rw-r--r--src/ajax/var/rquery.js3
-rw-r--r--src/ajax/xhr.js7
6 files changed, 104 insertions, 2 deletions
diff --git a/src/ajax/jsonp.js b/src/ajax/jsonp.js
index b8803df44..ff0d53899 100644
--- a/src/ajax/jsonp.js
+++ b/src/ajax/jsonp.js
@@ -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";
}
});
+
+});
diff --git a/src/ajax/load.js b/src/ajax/load.js
new file mode 100644
index 000000000..e9c21ef16
--- /dev/null
+++ b/src/ajax/load.js
@@ -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;
+};
+
+}); \ No newline at end of file
diff --git a/src/ajax/script.js b/src/ajax/script.js
index fe0562a84..f44329d4e 100644
--- a/src/ajax/script.js
+++ b/src/ajax/script.js
@@ -1,3 +1,8 @@
+define([
+ "../core",
+ "../ajax"
+], function( jQuery ) {
+
// Install script dataType
jQuery.ajaxSetup({
accepts: {
@@ -55,3 +60,5 @@ jQuery.ajaxTransport( "script", function( s ) {
};
}
});
+
+});
diff --git a/src/ajax/var/nonce.js b/src/ajax/var/nonce.js
new file mode 100644
index 000000000..0871aae88
--- /dev/null
+++ b/src/ajax/var/nonce.js
@@ -0,0 +1,5 @@
+define([
+ "../../core"
+], function( jQuery ) {
+ return jQuery.now();
+});
diff --git a/src/ajax/var/rquery.js b/src/ajax/var/rquery.js
new file mode 100644
index 000000000..eb26d4eb8
--- /dev/null
+++ b/src/ajax/var/rquery.js
@@ -0,0 +1,3 @@
+define(function() {
+ return /\?/;
+}); \ No newline at end of file
diff --git a/src/ajax/xhr.js b/src/ajax/xhr.js
index 3a9c9e968..6feb94d57 100644
--- a/src/ajax/xhr.js
+++ b/src/ajax/xhr.js
@@ -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 ) {
};
}
});
+
+});