diff options
Diffstat (limited to 'libs/bower_components/jquery/src/ajax')
-rw-r--r-- | libs/bower_components/jquery/src/ajax/jsonp.js | 33 | ||||
-rw-r--r-- | libs/bower_components/jquery/src/ajax/load.js | 34 | ||||
-rw-r--r-- | libs/bower_components/jquery/src/ajax/parseJSON.js | 8 | ||||
-rw-r--r-- | libs/bower_components/jquery/src/ajax/parseXML.js | 10 | ||||
-rw-r--r-- | libs/bower_components/jquery/src/ajax/script.js | 26 | ||||
-rw-r--r-- | libs/bower_components/jquery/src/ajax/var/nonce.js | 4 | ||||
-rw-r--r-- | libs/bower_components/jquery/src/ajax/var/rquery.js | 6 | ||||
-rw-r--r-- | libs/bower_components/jquery/src/ajax/xhr.js | 83 |
8 files changed, 130 insertions, 74 deletions
diff --git a/libs/bower_components/jquery/src/ajax/jsonp.js b/libs/bower_components/jquery/src/ajax/jsonp.js index ff0d53899d..89ce44d11a 100644 --- a/libs/bower_components/jquery/src/ajax/jsonp.js +++ b/libs/bower_components/jquery/src/ajax/jsonp.js @@ -1,4 +1,4 @@ -define([ +define( [ "../core", "./var/nonce", "./var/rquery", @@ -9,14 +9,14 @@ var oldCallbacks = [], rjsonp = /(=)\?(?=&|$)|\?\?/; // Default jsonp settings -jQuery.ajaxSetup({ +jQuery.ajaxSetup( { jsonp: "callback", jsonpCallback: function() { var callback = oldCallbacks.pop() || ( jQuery.expando + "_" + ( nonce++ ) ); this[ callback ] = true; return callback; } -}); +} ); // Detect, normalize options and install callbacks for jsonp requests jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) { @@ -24,7 +24,10 @@ jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) { var callbackName, overwritten, responseContainer, jsonProp = s.jsonp !== false && ( rjsonp.test( s.url ) ? "url" : - typeof s.data === "string" && !( s.contentType || "" ).indexOf("application/x-www-form-urlencoded") && rjsonp.test( s.data ) && "data" + typeof s.data === "string" && + ( s.contentType || "" ) + .indexOf( "application/x-www-form-urlencoded" ) === 0 && + rjsonp.test( s.data ) && "data" ); // Handle iff the expected data type is "jsonp" or we have a parameter to set @@ -43,7 +46,7 @@ jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) { } // Use data converter to retrieve json after script execution - s.converters["script json"] = function() { + s.converters[ "script json" ] = function() { if ( !responseContainer ) { jQuery.error( callbackName + " was not called" ); } @@ -60,12 +63,20 @@ jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) { }; // Clean-up function (fires after converters) - jqXHR.always(function() { - // Restore preexisting value - window[ callbackName ] = overwritten; + jqXHR.always( function() { + + // If previous value didn't exist - remove it + if ( overwritten === undefined ) { + jQuery( window ).removeProp( callbackName ); + + // Otherwise restore preexisting value + } else { + window[ callbackName ] = overwritten; + } // Save back as free if ( s[ callbackName ] ) { + // make sure that re-using the options doesn't screw things around s.jsonpCallback = originalSettings.jsonpCallback; @@ -79,11 +90,11 @@ jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) { } responseContainer = overwritten = undefined; - }); + } ); // Delegate to script return "script"; } -}); +} ); -}); +} ); diff --git a/libs/bower_components/jquery/src/ajax/load.js b/libs/bower_components/jquery/src/ajax/load.js index 24ca95e99d..2ae4b39b95 100644 --- a/libs/bower_components/jquery/src/ajax/load.js +++ b/libs/bower_components/jquery/src/ajax/load.js @@ -1,10 +1,11 @@ -define([ +define( [ "../core", "../core/parseHTML", "../ajax", "../traversing", "../manipulation", "../selector", + // Optional event/alias dependency "../event/alias" ], function( jQuery ) { @@ -20,11 +21,11 @@ jQuery.fn.load = function( url, params, callback ) { return _load.apply( this, arguments ); } - var selector, response, type, + var selector, type, response, self = this, - off = url.indexOf(" "); + off = url.indexOf( " " ); - if ( off >= 0 ) { + if ( off > -1 ) { selector = jQuery.trim( url.slice( off, url.length ) ); url = url.slice( 0, off ); } @@ -43,14 +44,16 @@ jQuery.fn.load = function( url, params, callback ) { // If we have elements to modify, make the request if ( self.length > 0 ) { - jQuery.ajax({ + jQuery.ajax( { url: url, - // if "type" variable is undefined, then "GET" method will be used - type: type, + // If "type" variable is undefined, then "GET" method will be used. + // Make value of this field explicit since + // user can override it through ajaxSetup method + type: type || "GET", dataType: "html", data: params - }).done(function( responseText ) { + } ).done( function( responseText ) { // Save response for use in complete callback response = arguments; @@ -59,17 +62,22 @@ jQuery.fn.load = function( url, params, callback ) { // 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 ) : + 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 ] ); - }); + // If the request succeeds, this function gets "data", "status", "jqXHR" + // but they are ignored because response was set above. + // If it fails, this function gets "jqXHR", "status", "error" + } ).always( callback && function( jqXHR, status ) { + self.each( function() { + callback.apply( this, response || [ jqXHR.responseText, status, jqXHR ] ); + } ); + } ); } return this; }; -}); +} ); diff --git a/libs/bower_components/jquery/src/ajax/parseJSON.js b/libs/bower_components/jquery/src/ajax/parseJSON.js index 69b5c837d8..34efb79b21 100644 --- a/libs/bower_components/jquery/src/ajax/parseJSON.js +++ b/libs/bower_components/jquery/src/ajax/parseJSON.js @@ -1,12 +1,14 @@ -define([ +define( [ "../core" ], function( jQuery ) { var rvalidtokens = /(,)|(\[|{)|(}|])|"(?:[^"\\\r\n]|\\["\\\/bfnrt]|\\u[\da-fA-F]{4})*"\s*:?|true|false|null|-?(?!0\d)\d+(?:\.\d+|)(?:[eE][+-]?\d+|)/g; jQuery.parseJSON = function( data ) { + // Attempt to parse using the native JSON parser first if ( window.JSON && window.JSON.parse ) { + // Support: Android 2.3 // Workaround failure to string-cast null input return window.JSON.parse( data + "" ); @@ -41,11 +43,11 @@ jQuery.parseJSON = function( data ) { // Remove this token return ""; - }) ) ? + } ) ) ? ( Function( "return " + str ) )() : jQuery.error( "Invalid JSON: " + data ); }; return jQuery.parseJSON; -}); +} ); diff --git a/libs/bower_components/jquery/src/ajax/parseXML.js b/libs/bower_components/jquery/src/ajax/parseXML.js index 0b92c7a42b..a05e8002ee 100644 --- a/libs/bower_components/jquery/src/ajax/parseXML.js +++ b/libs/bower_components/jquery/src/ajax/parseXML.js @@ -1,4 +1,4 @@ -define([ +define( [ "../core" ], function( jQuery ) { @@ -10,14 +10,14 @@ jQuery.parseXML = function( data ) { } try { if ( window.DOMParser ) { // Standard - tmp = new DOMParser(); + tmp = new window.DOMParser(); xml = tmp.parseFromString( data, "text/xml" ); } else { // IE - xml = new ActiveXObject( "Microsoft.XMLDOM" ); + xml = new window.ActiveXObject( "Microsoft.XMLDOM" ); xml.async = "false"; xml.loadXML( data ); } - } catch( e ) { + } catch ( e ) { xml = undefined; } if ( !xml || !xml.documentElement || xml.getElementsByTagName( "parsererror" ).length ) { @@ -28,4 +28,4 @@ jQuery.parseXML = function( data ) { return jQuery.parseXML; -}); +} ); diff --git a/libs/bower_components/jquery/src/ajax/script.js b/libs/bower_components/jquery/src/ajax/script.js index f6598aaf3d..1aa4dbfbd5 100644 --- a/libs/bower_components/jquery/src/ajax/script.js +++ b/libs/bower_components/jquery/src/ajax/script.js @@ -1,15 +1,17 @@ -define([ +define( [ "../core", + "../var/document", "../ajax" -], function( jQuery ) { +], function( jQuery, document ) { // Install script dataType -jQuery.ajaxSetup({ +jQuery.ajaxSetup( { accepts: { - script: "text/javascript, application/javascript, application/ecmascript, application/x-ecmascript" + script: "text/javascript, application/javascript, " + + "application/ecmascript, application/x-ecmascript" }, contents: { - script: /(?:java|ecma)script/ + script: /\b(?:java|ecma)script\b/ }, converters: { "text script": function( text ) { @@ -17,7 +19,7 @@ jQuery.ajaxSetup({ return text; } } -}); +} ); // Handle cache's special case and global jQuery.ajaxPrefilter( "script", function( s ) { @@ -28,22 +30,22 @@ jQuery.ajaxPrefilter( "script", function( s ) { 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.head || jQuery("head")[0] || document.documentElement; + head = document.head || jQuery( "head" )[ 0 ] || document.documentElement; return { send: function( _, callback ) { - script = document.createElement("script"); + script = document.createElement( "script" ); script.async = true; @@ -88,6 +90,6 @@ jQuery.ajaxTransport( "script", function(s) { } }; } -}); +} ); -}); +} ); diff --git a/libs/bower_components/jquery/src/ajax/var/nonce.js b/libs/bower_components/jquery/src/ajax/var/nonce.js index 0871aae881..83fd557c87 100644 --- a/libs/bower_components/jquery/src/ajax/var/nonce.js +++ b/libs/bower_components/jquery/src/ajax/var/nonce.js @@ -1,5 +1,5 @@ -define([ +define( [ "../../core" ], function( jQuery ) { return jQuery.now(); -}); +} ); diff --git a/libs/bower_components/jquery/src/ajax/var/rquery.js b/libs/bower_components/jquery/src/ajax/var/rquery.js index 500a77a089..0502146ca8 100644 --- a/libs/bower_components/jquery/src/ajax/var/rquery.js +++ b/libs/bower_components/jquery/src/ajax/var/rquery.js @@ -1,3 +1,3 @@ -define(function() { - return (/\?/); -}); +define( function() { + return ( /\?/ ); +} ); diff --git a/libs/bower_components/jquery/src/ajax/xhr.js b/libs/bower_components/jquery/src/ajax/xhr.js index 0f560f45a2..7e41409715 100644 --- a/libs/bower_components/jquery/src/ajax/xhr.js +++ b/libs/bower_components/jquery/src/ajax/xhr.js @@ -1,28 +1,42 @@ -define([ +define( [ "../core", + "../var/document", "../var/support", "../ajax" -], function( jQuery, support ) { +], function( jQuery, document, support ) { // Create the request object // (This is still attached to ajaxSettings for backward compatibility) jQuery.ajaxSettings.xhr = window.ActiveXObject !== undefined ? - // Support: IE6+ + + // Support: IE6-IE8 function() { // XHR cannot access local files, always use ActiveX for that case - return !this.isLocal && + if ( this.isLocal ) { + return createActiveXHR(); + } - // Support: IE7-8 - // oldIE XHR does not support non-RFC2616 methods (#13240) - // See http://msdn.microsoft.com/en-us/library/ie/ms536648(v=vs.85).aspx - // and http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9 - // Although this check for six methods instead of eight - // since IE also does not support "trace" and "connect" - /^(get|post|head|put|delete|options)$/i.test( this.type ) && + // Support: IE 9-11 + // IE seems to error on cross-domain PATCH requests when ActiveX XHR + // is used. In IE 9+ always use the native XHR. + // Note: this condition won't catch Edge as it doesn't define + // document.documentMode but it also doesn't support ActiveX so it won't + // reach this code. + if ( document.documentMode > 8 ) { + return createStandardXHR(); + } + // Support: IE<9 + // oldIE XHR does not support non-RFC2616 methods (#13240) + // See http://msdn.microsoft.com/en-us/library/ie/ms536648(v=vs.85).aspx + // and http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9 + // Although this check for six methods instead of eight + // since IE also does not support "trace" and "connect" + return /^(get|post|head|put|delete|options)$/i.test( this.type ) && createStandardXHR() || createActiveXHR(); } : + // For all other browsers, use the standard XMLHttpRequest object createStandardXHR; @@ -32,12 +46,13 @@ var xhrId = 0, // Support: IE<10 // Open requests must be manually aborted on unload (#5280) -if ( window.ActiveXObject ) { - jQuery( window ).on( "unload", function() { +// See https://support.microsoft.com/kb/2856746 for more info +if ( window.attachEvent ) { + window.attachEvent( "onunload", function() { for ( var key in xhrCallbacks ) { xhrCallbacks[ key ]( undefined, true ); } - }); + } ); } // Determine support properties @@ -47,7 +62,8 @@ xhrSupported = support.ajax = !!xhrSupported; // Create transport if the browser can provide an xhr if ( xhrSupported ) { - jQuery.ajaxTransport(function( options ) { + jQuery.ajaxTransport( function( options ) { + // Cross domain only allowed if supported through XMLHttpRequest if ( !options.crossDomain || support.cors ) { @@ -60,7 +76,13 @@ if ( xhrSupported ) { id = ++xhrId; // Open the socket - xhr.open( options.type, options.url, options.async, options.username, options.password ); + xhr.open( + options.type, + options.url, + options.async, + options.username, + options.password + ); // Apply custom fields if provided if ( options.xhrFields ) { @@ -79,12 +101,13 @@ if ( xhrSupported ) { // akin to a jigsaw puzzle, we simply never set it to be sure. // (it can always be set on a per-request basis or even using ajaxSetup) // For same-domain requests, won't change header if already provided. - if ( !options.crossDomain && !headers["X-Requested-With"] ) { - headers["X-Requested-With"] = "XMLHttpRequest"; + if ( !options.crossDomain && !headers[ "X-Requested-With" ] ) { + headers[ "X-Requested-With" ] = "XMLHttpRequest"; } // Set headers for ( i in headers ) { + // Support: IE<9 // IE's ActiveXObject throws a 'Type Mismatch' exception when setting // request header to a null-value. @@ -107,6 +130,7 @@ if ( xhrSupported ) { // Was never called and is aborted or complete if ( callback && ( isAbort || xhr.readyState === 4 ) ) { + // Clean up delete xhrCallbacks[ id ]; callback = undefined; @@ -132,7 +156,8 @@ if ( xhrSupported ) { // statusText for faulty cross-domain requests try { statusText = xhr.statusText; - } catch( e ) { + } catch ( e ) { + // We normalize with Webkit giving an empty statusText statusText = ""; } @@ -144,6 +169,7 @@ if ( xhrSupported ) { // can do given current implementations) if ( !status && options.isLocal && !options.crossDomain ) { status = responses.text ? 200 : 404; + // IE - #1450: sometimes returns 1223 when it should be 204 } else if ( status === 1223 ) { status = 204; @@ -157,14 +183,21 @@ if ( xhrSupported ) { } }; + // Do send the request + // `xhr.send` may raise an exception, but it will be + // handled in jQuery.ajax (so no try/catch here) if ( !options.async ) { - // if we're in sync mode we fire the callback + + // If we're in sync mode we fire the callback callback(); } else if ( xhr.readyState === 4 ) { + // (IE6 & IE7) if it's in cache and has been // retrieved directly we need to fire the callback - setTimeout( callback ); + window.setTimeout( callback ); } else { + + // Register the callback, but delay it in case `xhr.send` throws // Add to the list of active xhr callbacks xhr.onreadystatechange = xhrCallbacks[ id ] = callback; } @@ -177,20 +210,20 @@ if ( xhrSupported ) { } }; } - }); + } ); } // Functions to create xhrs function createStandardXHR() { try { return new window.XMLHttpRequest(); - } catch( e ) {} + } catch ( e ) {} } function createActiveXHR() { try { return new window.ActiveXObject( "Microsoft.XMLHTTP" ); - } catch( e ) {} + } catch ( e ) {} } -}); +} ); |