corrade-nucleus-nucleons – Blame information for rev 20
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
20 | office | 1 | define([ |
2 | "./core", |
||
3 | "./var/rnotwhite", |
||
4 | "./ajax/var/nonce", |
||
5 | "./ajax/var/rquery", |
||
6 | "./core/init", |
||
7 | "./ajax/parseJSON", |
||
8 | "./ajax/parseXML", |
||
9 | "./deferred" |
||
10 | ], function( jQuery, rnotwhite, nonce, rquery ) { |
||
11 | |||
12 | var |
||
13 | // Document location |
||
14 | ajaxLocParts, |
||
15 | ajaxLocation, |
||
16 | |||
17 | rhash = /#.*$/, |
||
18 | rts = /([?&])_=[^&]*/, |
||
19 | rheaders = /^(.*?):[ \t]*([^\r\n]*)$/mg, |
||
20 | // #7653, #8125, #8152: local protocol detection |
||
21 | rlocalProtocol = /^(?:about|app|app-storage|.+-extension|file|res|widget):$/, |
||
22 | rnoContent = /^(?:GET|HEAD)$/, |
||
23 | rprotocol = /^\/\//, |
||
24 | rurl = /^([\w.+-]+:)(?:\/\/(?:[^\/?#]*@|)([^\/?#:]*)(?::(\d+)|)|)/, |
||
25 | |||
26 | /* Prefilters |
||
27 | * 1) They are useful to introduce custom dataTypes (see ajax/jsonp.js for an example) |
||
28 | * 2) These are called: |
||
29 | * - BEFORE asking for a transport |
||
30 | * - AFTER param serialization (s.data is a string if s.processData is true) |
||
31 | * 3) key is the dataType |
||
32 | * 4) the catchall symbol "*" can be used |
||
33 | * 5) execution will start with transport dataType and THEN continue down to "*" if needed |
||
34 | */ |
||
35 | prefilters = {}, |
||
36 | |||
37 | /* Transports bindings |
||
38 | * 1) key is the dataType |
||
39 | * 2) the catchall symbol "*" can be used |
||
40 | * 3) selection will start with transport dataType and THEN go to "*" if needed |
||
41 | */ |
||
42 | transports = {}, |
||
43 | |||
44 | // Avoid comment-prolog char sequence (#10098); must appease lint and evade compression |
||
45 | allTypes = "*/".concat("*"); |
||
46 | |||
47 | // #8138, IE may throw an exception when accessing |
||
48 | // a field from window.location if document.domain has been set |
||
49 | try { |
||
50 | ajaxLocation = location.href; |
||
51 | } catch( e ) { |
||
52 | // Use the href attribute of an A element |
||
53 | // since IE will modify it given document.location |
||
54 | ajaxLocation = document.createElement( "a" ); |
||
55 | ajaxLocation.href = ""; |
||
56 | ajaxLocation = ajaxLocation.href; |
||
57 | } |
||
58 | |||
59 | // Segment location into parts |
||
60 | ajaxLocParts = rurl.exec( ajaxLocation.toLowerCase() ) || []; |
||
61 | |||
62 | // Base "constructor" for jQuery.ajaxPrefilter and jQuery.ajaxTransport |
||
63 | function addToPrefiltersOrTransports( structure ) { |
||
64 | |||
65 | // dataTypeExpression is optional and defaults to "*" |
||
66 | return function( dataTypeExpression, func ) { |
||
67 | |||
68 | if ( typeof dataTypeExpression !== "string" ) { |
||
69 | func = dataTypeExpression; |
||
70 | dataTypeExpression = "*"; |
||
71 | } |
||
72 | |||
73 | var dataType, |
||
74 | i = 0, |
||
75 | dataTypes = dataTypeExpression.toLowerCase().match( rnotwhite ) || []; |
||
76 | |||
77 | if ( jQuery.isFunction( func ) ) { |
||
78 | // For each dataType in the dataTypeExpression |
||
79 | while ( (dataType = dataTypes[i++]) ) { |
||
80 | // Prepend if requested |
||
81 | if ( dataType[0] === "+" ) { |
||
82 | dataType = dataType.slice( 1 ) || "*"; |
||
83 | (structure[ dataType ] = structure[ dataType ] || []).unshift( func ); |
||
84 | |||
85 | // Otherwise append |
||
86 | } else { |
||
87 | (structure[ dataType ] = structure[ dataType ] || []).push( func ); |
||
88 | } |
||
89 | } |
||
90 | } |
||
91 | }; |
||
92 | } |
||
93 | |||
94 | // Base inspection function for prefilters and transports |
||
95 | function inspectPrefiltersOrTransports( structure, options, originalOptions, jqXHR ) { |
||
96 | |||
97 | var inspected = {}, |
||
98 | seekingTransport = ( structure === transports ); |
||
99 | |||
100 | function inspect( dataType ) { |
||
101 | var selected; |
||
102 | inspected[ dataType ] = true; |
||
103 | jQuery.each( structure[ dataType ] || [], function( _, prefilterOrFactory ) { |
||
104 | var dataTypeOrTransport = prefilterOrFactory( options, originalOptions, jqXHR ); |
||
105 | if ( typeof dataTypeOrTransport === "string" && !seekingTransport && !inspected[ dataTypeOrTransport ] ) { |
||
106 | options.dataTypes.unshift( dataTypeOrTransport ); |
||
107 | inspect( dataTypeOrTransport ); |
||
108 | return false; |
||
109 | } else if ( seekingTransport ) { |
||
110 | return !( selected = dataTypeOrTransport ); |
||
111 | } |
||
112 | }); |
||
113 | return selected; |
||
114 | } |
||
115 | |||
116 | return inspect( options.dataTypes[ 0 ] ) || !inspected[ "*" ] && inspect( "*" ); |
||
117 | } |
||
118 | |||
119 | // A special extend for ajax options |
||
120 | // that takes "flat" options (not to be deep extended) |
||
121 | // Fixes #9887 |
||
122 | function ajaxExtend( target, src ) { |
||
123 | var key, deep, |
||
124 | flatOptions = jQuery.ajaxSettings.flatOptions || {}; |
||
125 | |||
126 | for ( key in src ) { |
||
127 | if ( src[ key ] !== undefined ) { |
||
128 | ( flatOptions[ key ] ? target : ( deep || (deep = {}) ) )[ key ] = src[ key ]; |
||
129 | } |
||
130 | } |
||
131 | if ( deep ) { |
||
132 | jQuery.extend( true, target, deep ); |
||
133 | } |
||
134 | |||
135 | return target; |
||
136 | } |
||
137 | |||
138 | /* Handles responses to an ajax request: |
||
139 | * - finds the right dataType (mediates between content-type and expected dataType) |
||
140 | * - returns the corresponding response |
||
141 | */ |
||
142 | function ajaxHandleResponses( s, jqXHR, responses ) { |
||
143 | |||
144 | var ct, type, finalDataType, firstDataType, |
||
145 | contents = s.contents, |
||
146 | dataTypes = s.dataTypes; |
||
147 | |||
148 | // Remove auto dataType and get content-type in the process |
||
149 | while ( dataTypes[ 0 ] === "*" ) { |
||
150 | dataTypes.shift(); |
||
151 | if ( ct === undefined ) { |
||
152 | ct = s.mimeType || jqXHR.getResponseHeader("Content-Type"); |
||
153 | } |
||
154 | } |
||
155 | |||
156 | // Check if we're dealing with a known content-type |
||
157 | if ( ct ) { |
||
158 | for ( type in contents ) { |
||
159 | if ( contents[ type ] && contents[ type ].test( ct ) ) { |
||
160 | dataTypes.unshift( type ); |
||
161 | break; |
||
162 | } |
||
163 | } |
||
164 | } |
||
165 | |||
166 | // Check to see if we have a response for the expected dataType |
||
167 | if ( dataTypes[ 0 ] in responses ) { |
||
168 | finalDataType = dataTypes[ 0 ]; |
||
169 | } else { |
||
170 | // Try convertible dataTypes |
||
171 | for ( type in responses ) { |
||
172 | if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[0] ] ) { |
||
173 | finalDataType = type; |
||
174 | break; |
||
175 | } |
||
176 | if ( !firstDataType ) { |
||
177 | firstDataType = type; |
||
178 | } |
||
179 | } |
||
180 | // Or just use first one |
||
181 | finalDataType = finalDataType || firstDataType; |
||
182 | } |
||
183 | |||
184 | // If we found a dataType |
||
185 | // We add the dataType to the list if needed |
||
186 | // and return the corresponding response |
||
187 | if ( finalDataType ) { |
||
188 | if ( finalDataType !== dataTypes[ 0 ] ) { |
||
189 | dataTypes.unshift( finalDataType ); |
||
190 | } |
||
191 | return responses[ finalDataType ]; |
||
192 | } |
||
193 | } |
||
194 | |||
195 | /* Chain conversions given the request and the original response |
||
196 | * Also sets the responseXXX fields on the jqXHR instance |
||
197 | */ |
||
198 | function ajaxConvert( s, response, jqXHR, isSuccess ) { |
||
199 | var conv2, current, conv, tmp, prev, |
||
200 | converters = {}, |
||
201 | // Work with a copy of dataTypes in case we need to modify it for conversion |
||
202 | dataTypes = s.dataTypes.slice(); |
||
203 | |||
204 | // Create converters map with lowercased keys |
||
205 | if ( dataTypes[ 1 ] ) { |
||
206 | for ( conv in s.converters ) { |
||
207 | converters[ conv.toLowerCase() ] = s.converters[ conv ]; |
||
208 | } |
||
209 | } |
||
210 | |||
211 | current = dataTypes.shift(); |
||
212 | |||
213 | // Convert to each sequential dataType |
||
214 | while ( current ) { |
||
215 | |||
216 | if ( s.responseFields[ current ] ) { |
||
217 | jqXHR[ s.responseFields[ current ] ] = response; |
||
218 | } |
||
219 | |||
220 | // Apply the dataFilter if provided |
||
221 | if ( !prev && isSuccess && s.dataFilter ) { |
||
222 | response = s.dataFilter( response, s.dataType ); |
||
223 | } |
||
224 | |||
225 | prev = current; |
||
226 | current = dataTypes.shift(); |
||
227 | |||
228 | if ( current ) { |
||
229 | |||
230 | // There's only work to do if current dataType is non-auto |
||
231 | if ( current === "*" ) { |
||
232 | |||
233 | current = prev; |
||
234 | |||
235 | // Convert response if prev dataType is non-auto and differs from current |
||
236 | } else if ( prev !== "*" && prev !== current ) { |
||
237 | |||
238 | // Seek a direct converter |
||
239 | conv = converters[ prev + " " + current ] || converters[ "* " + current ]; |
||
240 | |||
241 | // If none found, seek a pair |
||
242 | if ( !conv ) { |
||
243 | for ( conv2 in converters ) { |
||
244 | |||
245 | // If conv2 outputs current |
||
246 | tmp = conv2.split( " " ); |
||
247 | if ( tmp[ 1 ] === current ) { |
||
248 | |||
249 | // If prev can be converted to accepted input |
||
250 | conv = converters[ prev + " " + tmp[ 0 ] ] || |
||
251 | converters[ "* " + tmp[ 0 ] ]; |
||
252 | if ( conv ) { |
||
253 | // Condense equivalence converters |
||
254 | if ( conv === true ) { |
||
255 | conv = converters[ conv2 ]; |
||
256 | |||
257 | // Otherwise, insert the intermediate dataType |
||
258 | } else if ( converters[ conv2 ] !== true ) { |
||
259 | current = tmp[ 0 ]; |
||
260 | dataTypes.unshift( tmp[ 1 ] ); |
||
261 | } |
||
262 | break; |
||
263 | } |
||
264 | } |
||
265 | } |
||
266 | } |
||
267 | |||
268 | // Apply converter (if not an equivalence) |
||
269 | if ( conv !== true ) { |
||
270 | |||
271 | // Unless errors are allowed to bubble, catch and return them |
||
272 | if ( conv && s[ "throws" ] ) { |
||
273 | response = conv( response ); |
||
274 | } else { |
||
275 | try { |
||
276 | response = conv( response ); |
||
277 | } catch ( e ) { |
||
278 | return { state: "parsererror", error: conv ? e : "No conversion from " + prev + " to " + current }; |
||
279 | } |
||
280 | } |
||
281 | } |
||
282 | } |
||
283 | } |
||
284 | } |
||
285 | |||
286 | return { state: "success", data: response }; |
||
287 | } |
||
288 | |||
289 | jQuery.extend({ |
||
290 | |||
291 | // Counter for holding the number of active queries |
||
292 | active: 0, |
||
293 | |||
294 | // Last-Modified header cache for next request |
||
295 | lastModified: {}, |
||
296 | etag: {}, |
||
297 | |||
298 | ajaxSettings: { |
||
299 | url: ajaxLocation, |
||
300 | type: "GET", |
||
301 | isLocal: rlocalProtocol.test( ajaxLocParts[ 1 ] ), |
||
302 | global: true, |
||
303 | processData: true, |
||
304 | async: true, |
||
305 | contentType: "application/x-www-form-urlencoded; charset=UTF-8", |
||
306 | /* |
||
307 | timeout: 0, |
||
308 | data: null, |
||
309 | dataType: null, |
||
310 | username: null, |
||
311 | password: null, |
||
312 | cache: null, |
||
313 | throws: false, |
||
314 | traditional: false, |
||
315 | headers: {}, |
||
316 | */ |
||
317 | |||
318 | accepts: { |
||
319 | "*": allTypes, |
||
320 | text: "text/plain", |
||
321 | html: "text/html", |
||
322 | xml: "application/xml, text/xml", |
||
323 | json: "application/json, text/javascript" |
||
324 | }, |
||
325 | |||
326 | contents: { |
||
327 | xml: /xml/, |
||
328 | html: /html/, |
||
329 | json: /json/ |
||
330 | }, |
||
331 | |||
332 | responseFields: { |
||
333 | xml: "responseXML", |
||
334 | text: "responseText", |
||
335 | json: "responseJSON" |
||
336 | }, |
||
337 | |||
338 | // Data converters |
||
339 | // Keys separate source (or catchall "*") and destination types with a single space |
||
340 | converters: { |
||
341 | |||
342 | // Convert anything to text |
||
343 | "* text": String, |
||
344 | |||
345 | // Text to html (true = no transformation) |
||
346 | "text html": true, |
||
347 | |||
348 | // Evaluate text as a json expression |
||
349 | "text json": jQuery.parseJSON, |
||
350 | |||
351 | // Parse text as xml |
||
352 | "text xml": jQuery.parseXML |
||
353 | }, |
||
354 | |||
355 | // For options that shouldn't be deep extended: |
||
356 | // you can add your own custom options here if |
||
357 | // and when you create one that shouldn't be |
||
358 | // deep extended (see ajaxExtend) |
||
359 | flatOptions: { |
||
360 | url: true, |
||
361 | context: true |
||
362 | } |
||
363 | }, |
||
364 | |||
365 | // Creates a full fledged settings object into target |
||
366 | // with both ajaxSettings and settings fields. |
||
367 | // If target is omitted, writes into ajaxSettings. |
||
368 | ajaxSetup: function( target, settings ) { |
||
369 | return settings ? |
||
370 | |||
371 | // Building a settings object |
||
372 | ajaxExtend( ajaxExtend( target, jQuery.ajaxSettings ), settings ) : |
||
373 | |||
374 | // Extending ajaxSettings |
||
375 | ajaxExtend( jQuery.ajaxSettings, target ); |
||
376 | }, |
||
377 | |||
378 | ajaxPrefilter: addToPrefiltersOrTransports( prefilters ), |
||
379 | ajaxTransport: addToPrefiltersOrTransports( transports ), |
||
380 | |||
381 | // Main method |
||
382 | ajax: function( url, options ) { |
||
383 | |||
384 | // If url is an object, simulate pre-1.5 signature |
||
385 | if ( typeof url === "object" ) { |
||
386 | options = url; |
||
387 | url = undefined; |
||
388 | } |
||
389 | |||
390 | // Force options to be an object |
||
391 | options = options || {}; |
||
392 | |||
393 | var transport, |
||
394 | // URL without anti-cache param |
||
395 | cacheURL, |
||
396 | // Response headers |
||
397 | responseHeadersString, |
||
398 | responseHeaders, |
||
399 | // timeout handle |
||
400 | timeoutTimer, |
||
401 | // Cross-domain detection vars |
||
402 | parts, |
||
403 | // To know if global events are to be dispatched |
||
404 | fireGlobals, |
||
405 | // Loop variable |
||
406 | i, |
||
407 | // Create the final options object |
||
408 | s = jQuery.ajaxSetup( {}, options ), |
||
409 | // Callbacks context |
||
410 | callbackContext = s.context || s, |
||
411 | // Context for global events is callbackContext if it is a DOM node or jQuery collection |
||
412 | globalEventContext = s.context && ( callbackContext.nodeType || callbackContext.jquery ) ? |
||
413 | jQuery( callbackContext ) : |
||
414 | jQuery.event, |
||
415 | // Deferreds |
||
416 | deferred = jQuery.Deferred(), |
||
417 | completeDeferred = jQuery.Callbacks("once memory"), |
||
418 | // Status-dependent callbacks |
||
419 | statusCode = s.statusCode || {}, |
||
420 | // Headers (they are sent all at once) |
||
421 | requestHeaders = {}, |
||
422 | requestHeadersNames = {}, |
||
423 | // The jqXHR state |
||
424 | state = 0, |
||
425 | // Default abort message |
||
426 | strAbort = "canceled", |
||
427 | // Fake xhr |
||
428 | jqXHR = { |
||
429 | readyState: 0, |
||
430 | |||
431 | // Builds headers hashtable if needed |
||
432 | getResponseHeader: function( key ) { |
||
433 | var match; |
||
434 | if ( state === 2 ) { |
||
435 | if ( !responseHeaders ) { |
||
436 | responseHeaders = {}; |
||
437 | while ( (match = rheaders.exec( responseHeadersString )) ) { |
||
438 | responseHeaders[ match[1].toLowerCase() ] = match[ 2 ]; |
||
439 | } |
||
440 | } |
||
441 | match = responseHeaders[ key.toLowerCase() ]; |
||
442 | } |
||
443 | return match == null ? null : match; |
||
444 | }, |
||
445 | |||
446 | // Raw string |
||
447 | getAllResponseHeaders: function() { |
||
448 | return state === 2 ? responseHeadersString : null; |
||
449 | }, |
||
450 | |||
451 | // Caches the header |
||
452 | setRequestHeader: function( name, value ) { |
||
453 | var lname = name.toLowerCase(); |
||
454 | if ( !state ) { |
||
455 | name = requestHeadersNames[ lname ] = requestHeadersNames[ lname ] || name; |
||
456 | requestHeaders[ name ] = value; |
||
457 | } |
||
458 | return this; |
||
459 | }, |
||
460 | |||
461 | // Overrides response content-type header |
||
462 | overrideMimeType: function( type ) { |
||
463 | if ( !state ) { |
||
464 | s.mimeType = type; |
||
465 | } |
||
466 | return this; |
||
467 | }, |
||
468 | |||
469 | // Status-dependent callbacks |
||
470 | statusCode: function( map ) { |
||
471 | var code; |
||
472 | if ( map ) { |
||
473 | if ( state < 2 ) { |
||
474 | for ( code in map ) { |
||
475 | // Lazy-add the new callback in a way that preserves old ones |
||
476 | statusCode[ code ] = [ statusCode[ code ], map[ code ] ]; |
||
477 | } |
||
478 | } else { |
||
479 | // Execute the appropriate callbacks |
||
480 | jqXHR.always( map[ jqXHR.status ] ); |
||
481 | } |
||
482 | } |
||
483 | return this; |
||
484 | }, |
||
485 | |||
486 | // Cancel the request |
||
487 | abort: function( statusText ) { |
||
488 | var finalText = statusText || strAbort; |
||
489 | if ( transport ) { |
||
490 | transport.abort( finalText ); |
||
491 | } |
||
492 | done( 0, finalText ); |
||
493 | return this; |
||
494 | } |
||
495 | }; |
||
496 | |||
497 | // Attach deferreds |
||
498 | deferred.promise( jqXHR ).complete = completeDeferred.add; |
||
499 | jqXHR.success = jqXHR.done; |
||
500 | jqXHR.error = jqXHR.fail; |
||
501 | |||
502 | // Remove hash character (#7531: and string promotion) |
||
503 | // Add protocol if not provided (prefilters might expect it) |
||
504 | // Handle falsy url in the settings object (#10093: consistency with old signature) |
||
505 | // We also use the url parameter if available |
||
506 | s.url = ( ( url || s.url || ajaxLocation ) + "" ).replace( rhash, "" ) |
||
507 | .replace( rprotocol, ajaxLocParts[ 1 ] + "//" ); |
||
508 | |||
509 | // Alias method option to type as per ticket #12004 |
||
510 | s.type = options.method || options.type || s.method || s.type; |
||
511 | |||
512 | // Extract dataTypes list |
||
513 | s.dataTypes = jQuery.trim( s.dataType || "*" ).toLowerCase().match( rnotwhite ) || [ "" ]; |
||
514 | |||
515 | // A cross-domain request is in order when we have a protocol:host:port mismatch |
||
516 | if ( s.crossDomain == null ) { |
||
517 | parts = rurl.exec( s.url.toLowerCase() ); |
||
518 | s.crossDomain = !!( parts && |
||
519 | ( parts[ 1 ] !== ajaxLocParts[ 1 ] || parts[ 2 ] !== ajaxLocParts[ 2 ] || |
||
520 | ( parts[ 3 ] || ( parts[ 1 ] === "http:" ? "80" : "443" ) ) !== |
||
521 | ( ajaxLocParts[ 3 ] || ( ajaxLocParts[ 1 ] === "http:" ? "80" : "443" ) ) ) |
||
522 | ); |
||
523 | } |
||
524 | |||
525 | // Convert data if not already a string |
||
526 | if ( s.data && s.processData && typeof s.data !== "string" ) { |
||
527 | s.data = jQuery.param( s.data, s.traditional ); |
||
528 | } |
||
529 | |||
530 | // Apply prefilters |
||
531 | inspectPrefiltersOrTransports( prefilters, s, options, jqXHR ); |
||
532 | |||
533 | // If request was aborted inside a prefilter, stop there |
||
534 | if ( state === 2 ) { |
||
535 | return jqXHR; |
||
536 | } |
||
537 | |||
538 | // We can fire global events as of now if asked to |
||
539 | fireGlobals = s.global; |
||
540 | |||
541 | // Watch for a new set of requests |
||
542 | if ( fireGlobals && jQuery.active++ === 0 ) { |
||
543 | jQuery.event.trigger("ajaxStart"); |
||
544 | } |
||
545 | |||
546 | // Uppercase the type |
||
547 | s.type = s.type.toUpperCase(); |
||
548 | |||
549 | // Determine if request has content |
||
550 | s.hasContent = !rnoContent.test( s.type ); |
||
551 | |||
552 | // Save the URL in case we're toying with the If-Modified-Since |
||
553 | // and/or If-None-Match header later on |
||
554 | cacheURL = s.url; |
||
555 | |||
556 | // More options handling for requests with no content |
||
557 | if ( !s.hasContent ) { |
||
558 | |||
559 | // If data is available, append data to url |
||
560 | if ( s.data ) { |
||
561 | cacheURL = ( s.url += ( rquery.test( cacheURL ) ? "&" : "?" ) + s.data ); |
||
562 | // #9682: remove data so that it's not used in an eventual retry |
||
563 | delete s.data; |
||
564 | } |
||
565 | |||
566 | // Add anti-cache in url if needed |
||
567 | if ( s.cache === false ) { |
||
568 | s.url = rts.test( cacheURL ) ? |
||
569 | |||
570 | // If there is already a '_' parameter, set its value |
||
571 | cacheURL.replace( rts, "$1_=" + nonce++ ) : |
||
572 | |||
573 | // Otherwise add one to the end |
||
574 | cacheURL + ( rquery.test( cacheURL ) ? "&" : "?" ) + "_=" + nonce++; |
||
575 | } |
||
576 | } |
||
577 | |||
578 | // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode. |
||
579 | if ( s.ifModified ) { |
||
580 | if ( jQuery.lastModified[ cacheURL ] ) { |
||
581 | jqXHR.setRequestHeader( "If-Modified-Since", jQuery.lastModified[ cacheURL ] ); |
||
582 | } |
||
583 | if ( jQuery.etag[ cacheURL ] ) { |
||
584 | jqXHR.setRequestHeader( "If-None-Match", jQuery.etag[ cacheURL ] ); |
||
585 | } |
||
586 | } |
||
587 | |||
588 | // Set the correct header, if data is being sent |
||
589 | if ( s.data && s.hasContent && s.contentType !== false || options.contentType ) { |
||
590 | jqXHR.setRequestHeader( "Content-Type", s.contentType ); |
||
591 | } |
||
592 | |||
593 | // Set the Accepts header for the server, depending on the dataType |
||
594 | jqXHR.setRequestHeader( |
||
595 | "Accept", |
||
596 | s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[0] ] ? |
||
597 | s.accepts[ s.dataTypes[0] ] + ( s.dataTypes[ 0 ] !== "*" ? ", " + allTypes + "; q=0.01" : "" ) : |
||
598 | s.accepts[ "*" ] |
||
599 | ); |
||
600 | |||
601 | // Check for headers option |
||
602 | for ( i in s.headers ) { |
||
603 | jqXHR.setRequestHeader( i, s.headers[ i ] ); |
||
604 | } |
||
605 | |||
606 | // Allow custom headers/mimetypes and early abort |
||
607 | if ( s.beforeSend && ( s.beforeSend.call( callbackContext, jqXHR, s ) === false || state === 2 ) ) { |
||
608 | // Abort if not done already and return |
||
609 | return jqXHR.abort(); |
||
610 | } |
||
611 | |||
612 | // aborting is no longer a cancellation |
||
613 | strAbort = "abort"; |
||
614 | |||
615 | // Install callbacks on deferreds |
||
616 | for ( i in { success: 1, error: 1, complete: 1 } ) { |
||
617 | jqXHR[ i ]( s[ i ] ); |
||
618 | } |
||
619 | |||
620 | // Get transport |
||
621 | transport = inspectPrefiltersOrTransports( transports, s, options, jqXHR ); |
||
622 | |||
623 | // If no transport, we auto-abort |
||
624 | if ( !transport ) { |
||
625 | done( -1, "No Transport" ); |
||
626 | } else { |
||
627 | jqXHR.readyState = 1; |
||
628 | |||
629 | // Send global event |
||
630 | if ( fireGlobals ) { |
||
631 | globalEventContext.trigger( "ajaxSend", [ jqXHR, s ] ); |
||
632 | } |
||
633 | // Timeout |
||
634 | if ( s.async && s.timeout > 0 ) { |
||
635 | timeoutTimer = setTimeout(function() { |
||
636 | jqXHR.abort("timeout"); |
||
637 | }, s.timeout ); |
||
638 | } |
||
639 | |||
640 | try { |
||
641 | state = 1; |
||
642 | transport.send( requestHeaders, done ); |
||
643 | } catch ( e ) { |
||
644 | // Propagate exception as error if not done |
||
645 | if ( state < 2 ) { |
||
646 | done( -1, e ); |
||
647 | // Simply rethrow otherwise |
||
648 | } else { |
||
649 | throw e; |
||
650 | } |
||
651 | } |
||
652 | } |
||
653 | |||
654 | // Callback for when everything is done |
||
655 | function done( status, nativeStatusText, responses, headers ) { |
||
656 | var isSuccess, success, error, response, modified, |
||
657 | statusText = nativeStatusText; |
||
658 | |||
659 | // Called once |
||
660 | if ( state === 2 ) { |
||
661 | return; |
||
662 | } |
||
663 | |||
664 | // State is "done" now |
||
665 | state = 2; |
||
666 | |||
667 | // Clear timeout if it exists |
||
668 | if ( timeoutTimer ) { |
||
669 | clearTimeout( timeoutTimer ); |
||
670 | } |
||
671 | |||
672 | // Dereference transport for early garbage collection |
||
673 | // (no matter how long the jqXHR object will be used) |
||
674 | transport = undefined; |
||
675 | |||
676 | // Cache response headers |
||
677 | responseHeadersString = headers || ""; |
||
678 | |||
679 | // Set readyState |
||
680 | jqXHR.readyState = status > 0 ? 4 : 0; |
||
681 | |||
682 | // Determine if successful |
||
683 | isSuccess = status >= 200 && status < 300 || status === 304; |
||
684 | |||
685 | // Get response data |
||
686 | if ( responses ) { |
||
687 | response = ajaxHandleResponses( s, jqXHR, responses ); |
||
688 | } |
||
689 | |||
690 | // Convert no matter what (that way responseXXX fields are always set) |
||
691 | response = ajaxConvert( s, response, jqXHR, isSuccess ); |
||
692 | |||
693 | // If successful, handle type chaining |
||
694 | if ( isSuccess ) { |
||
695 | |||
696 | // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode. |
||
697 | if ( s.ifModified ) { |
||
698 | modified = jqXHR.getResponseHeader("Last-Modified"); |
||
699 | if ( modified ) { |
||
700 | jQuery.lastModified[ cacheURL ] = modified; |
||
701 | } |
||
702 | modified = jqXHR.getResponseHeader("etag"); |
||
703 | if ( modified ) { |
||
704 | jQuery.etag[ cacheURL ] = modified; |
||
705 | } |
||
706 | } |
||
707 | |||
708 | // if no content |
||
709 | if ( status === 204 || s.type === "HEAD" ) { |
||
710 | statusText = "nocontent"; |
||
711 | |||
712 | // if not modified |
||
713 | } else if ( status === 304 ) { |
||
714 | statusText = "notmodified"; |
||
715 | |||
716 | // If we have data, let's convert it |
||
717 | } else { |
||
718 | statusText = response.state; |
||
719 | success = response.data; |
||
720 | error = response.error; |
||
721 | isSuccess = !error; |
||
722 | } |
||
723 | } else { |
||
724 | // We extract error from statusText |
||
725 | // then normalize statusText and status for non-aborts |
||
726 | error = statusText; |
||
727 | if ( status || !statusText ) { |
||
728 | statusText = "error"; |
||
729 | if ( status < 0 ) { |
||
730 | status = 0; |
||
731 | } |
||
732 | } |
||
733 | } |
||
734 | |||
735 | // Set data for the fake xhr object |
||
736 | jqXHR.status = status; |
||
737 | jqXHR.statusText = ( nativeStatusText || statusText ) + ""; |
||
738 | |||
739 | // Success/Error |
||
740 | if ( isSuccess ) { |
||
741 | deferred.resolveWith( callbackContext, [ success, statusText, jqXHR ] ); |
||
742 | } else { |
||
743 | deferred.rejectWith( callbackContext, [ jqXHR, statusText, error ] ); |
||
744 | } |
||
745 | |||
746 | // Status-dependent callbacks |
||
747 | jqXHR.statusCode( statusCode ); |
||
748 | statusCode = undefined; |
||
749 | |||
750 | if ( fireGlobals ) { |
||
751 | globalEventContext.trigger( isSuccess ? "ajaxSuccess" : "ajaxError", |
||
752 | [ jqXHR, s, isSuccess ? success : error ] ); |
||
753 | } |
||
754 | |||
755 | // Complete |
||
756 | completeDeferred.fireWith( callbackContext, [ jqXHR, statusText ] ); |
||
757 | |||
758 | if ( fireGlobals ) { |
||
759 | globalEventContext.trigger( "ajaxComplete", [ jqXHR, s ] ); |
||
760 | // Handle the global AJAX counter |
||
761 | if ( !( --jQuery.active ) ) { |
||
762 | jQuery.event.trigger("ajaxStop"); |
||
763 | } |
||
764 | } |
||
765 | } |
||
766 | |||
767 | return jqXHR; |
||
768 | }, |
||
769 | |||
770 | getJSON: function( url, data, callback ) { |
||
771 | return jQuery.get( url, data, callback, "json" ); |
||
772 | }, |
||
773 | |||
774 | getScript: function( url, callback ) { |
||
775 | return jQuery.get( url, undefined, callback, "script" ); |
||
776 | } |
||
777 | }); |
||
778 | |||
779 | jQuery.each( [ "get", "post" ], function( i, method ) { |
||
780 | jQuery[ method ] = function( url, data, callback, type ) { |
||
781 | // shift arguments if data argument was omitted |
||
782 | if ( jQuery.isFunction( data ) ) { |
||
783 | type = type || callback; |
||
784 | callback = data; |
||
785 | data = undefined; |
||
786 | } |
||
787 | |||
788 | return jQuery.ajax({ |
||
789 | url: url, |
||
790 | type: method, |
||
791 | dataType: type, |
||
792 | data: data, |
||
793 | success: callback |
||
794 | }); |
||
795 | }; |
||
796 | }); |
||
797 | |||
798 | // Attach a bunch of functions for handling common AJAX events |
||
799 | jQuery.each( [ "ajaxStart", "ajaxStop", "ajaxComplete", "ajaxError", "ajaxSuccess", "ajaxSend" ], function( i, type ) { |
||
800 | jQuery.fn[ type ] = function( fn ) { |
||
801 | return this.on( type, fn ); |
||
802 | }; |
||
803 | }); |
||
804 | |||
805 | return jQuery; |
||
806 | }); |