corrade-nucleus-nucleons – Blame information for rev 20

Subversion Repositories:
Rev:
Rev Author Line No. Line
20 office 1 define([
2 "../core",
3 "../var/support",
4 "../ajax"
5 ], function( jQuery, support ) {
6  
7 jQuery.ajaxSettings.xhr = function() {
8 try {
9 return new XMLHttpRequest();
10 } catch( e ) {}
11 };
12  
13 var xhrId = 0,
14 xhrCallbacks = {},
15 xhrSuccessStatus = {
16 // file protocol always yields status code 0, assume 200
17 0: 200,
18 // Support: IE9
19 // #1450: sometimes IE returns 1223 when it should be 204
20 1223: 204
21 },
22 xhrSupported = jQuery.ajaxSettings.xhr();
23  
24 // Support: IE9
25 // Open requests must be manually aborted on unload (#5280)
26 if ( window.ActiveXObject ) {
27 jQuery( window ).on( "unload", function() {
28 for ( var key in xhrCallbacks ) {
29 xhrCallbacks[ key ]();
30 }
31 });
32 }
33  
34 support.cors = !!xhrSupported && ( "withCredentials" in xhrSupported );
35 support.ajax = xhrSupported = !!xhrSupported;
36  
37 jQuery.ajaxTransport(function( options ) {
38 var callback;
39  
40 // Cross domain only allowed if supported through XMLHttpRequest
41 if ( support.cors || xhrSupported && !options.crossDomain ) {
42 return {
43 send: function( headers, complete ) {
44 var i,
45 xhr = options.xhr(),
46 id = ++xhrId;
47  
48 xhr.open( options.type, options.url, options.async, options.username, options.password );
49  
50 // Apply custom fields if provided
51 if ( options.xhrFields ) {
52 for ( i in options.xhrFields ) {
53 xhr[ i ] = options.xhrFields[ i ];
54 }
55 }
56  
57 // Override mime type if needed
58 if ( options.mimeType && xhr.overrideMimeType ) {
59 xhr.overrideMimeType( options.mimeType );
60 }
61  
62 // X-Requested-With header
63 // For cross-domain requests, seeing as conditions for a preflight are
64 // akin to a jigsaw puzzle, we simply never set it to be sure.
65 // (it can always be set on a per-request basis or even using ajaxSetup)
66 // For same-domain requests, won't change header if already provided.
67 if ( !options.crossDomain && !headers["X-Requested-With"] ) {
68 headers["X-Requested-With"] = "XMLHttpRequest";
69 }
70  
71 // Set headers
72 for ( i in headers ) {
73 xhr.setRequestHeader( i, headers[ i ] );
74 }
75  
76 // Callback
77 callback = function( type ) {
78 return function() {
79 if ( callback ) {
80 delete xhrCallbacks[ id ];
81 callback = xhr.onload = xhr.onerror = null;
82  
83 if ( type === "abort" ) {
84 xhr.abort();
85 } else if ( type === "error" ) {
86 complete(
87 // file: protocol always yields status 0; see #8605, #14207
88 xhr.status,
89 xhr.statusText
90 );
91 } else {
92 complete(
93 xhrSuccessStatus[ xhr.status ] || xhr.status,
94 xhr.statusText,
95 // Support: IE9
96 // Accessing binary-data responseText throws an exception
97 // (#11426)
98 typeof xhr.responseText === "string" ? {
99 text: xhr.responseText
100 } : undefined,
101 xhr.getAllResponseHeaders()
102 );
103 }
104 }
105 };
106 };
107  
108 // Listen to events
109 xhr.onload = callback();
110 xhr.onerror = callback("error");
111  
112 // Create the abort callback
113 callback = xhrCallbacks[ id ] = callback("abort");
114  
115 // Do send the request
116 // This may raise an exception which is actually
117 // handled in jQuery.ajax (so no try/catch here)
118 xhr.send( options.hasContent && options.data || null );
119 },
120  
121 abort: function() {
122 if ( callback ) {
123 callback();
124 }
125 }
126 };
127 }
128 });
129  
130 });