Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1551 lars 1
/*
2
 * jQuery XDomainRequest Transport Plugin
3
 * https://github.com/blueimp/jQuery-File-Upload
4
 *
5
 * Copyright 2011, Sebastian Tschan
6
 * https://blueimp.net
7
 *
8
 * Licensed under the MIT license:
9
 * https://opensource.org/licenses/MIT
10
 *
11
 * Based on Julian Aubourg's ajaxHooks xdr.js:
12
 * https://github.com/jaubourg/ajaxHooks/
13
 */
14
 
15
/* global define, require, XDomainRequest */
16
 
17
(function (factory) {
18
  'use strict';
19
  if (typeof define === 'function' && define.amd) {
20
    // Register as an anonymous AMD module:
21
    define(['jquery'], factory);
22
  } else if (typeof exports === 'object') {
23
    // Node/CommonJS:
24
    factory(require('jquery'));
25
  } else {
26
    // Browser globals:
27
    factory(window.jQuery);
28
  }
29
})(function ($) {
30
  'use strict';
31
  if (window.XDomainRequest && !$.support.cors) {
32
    $.ajaxTransport(function (s) {
33
      if (s.crossDomain && s.async) {
34
        if (s.timeout) {
35
          s.xdrTimeout = s.timeout;
36
          delete s.timeout;
37
        }
38
        var xdr;
39
        return {
40
          send: function (headers, completeCallback) {
41
            var addParamChar = /\?/.test(s.url) ? '&' : '?';
42
            /**
43
             * Callback wrapper function
44
             *
45
             * @param {number} status HTTP status code
46
             * @param {string} statusText HTTP status text
47
             * @param {object} [responses] Content-type specific responses
48
             * @param {string} [responseHeaders] Response headers string
49
             */
50
            function callback(status, statusText, responses, responseHeaders) {
51
              xdr.onload = xdr.onerror = xdr.ontimeout = $.noop;
52
              xdr = null;
53
              completeCallback(status, statusText, responses, responseHeaders);
54
            }
55
            xdr = new XDomainRequest();
56
            // XDomainRequest only supports GET and POST:
57
            if (s.type === 'DELETE') {
58
              s.url = s.url + addParamChar + '_method=DELETE';
59
              s.type = 'POST';
60
            } else if (s.type === 'PUT') {
61
              s.url = s.url + addParamChar + '_method=PUT';
62
              s.type = 'POST';
63
            } else if (s.type === 'PATCH') {
64
              s.url = s.url + addParamChar + '_method=PATCH';
65
              s.type = 'POST';
66
            }
67
            xdr.open(s.type, s.url);
68
            xdr.onload = function () {
69
              callback(
70
                200,
71
                'OK',
72
                { text: xdr.responseText },
73
                'Content-Type: ' + xdr.contentType
74
              );
75
            };
76
            xdr.onerror = function () {
77
              callback(404, 'Not Found');
78
            };
79
            if (s.xdrTimeout) {
80
              xdr.ontimeout = function () {
81
                callback(0, 'timeout');
82
              };
83
              xdr.timeout = s.xdrTimeout;
84
            }
85
            xdr.send((s.hasContent && s.data) || null);
86
          },
87
          abort: function () {
88
            if (xdr) {
89
              xdr.onerror = $.noop();
90
              xdr.abort();
91
            }
92
          }
93
        };
94
      }
95
    });
96
  }
97
});