From a5e3aa5dd540db971b8aed79c54431d219965862 Mon Sep 17 00:00:00 2001 From: Cherif BOUCHELAGHEM Date: Thu, 7 May 2020 20:18:43 +0100 Subject: [PATCH] 2.4.6 --- dist/amd/can-ajax.js | 214 ++++++++++++++++++++++ dist/cjs/can-ajax.js | 199 +++++++++++++++++++++ dist/global/can-ajax.js | 386 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 799 insertions(+) create mode 100644 dist/amd/can-ajax.js create mode 100644 dist/cjs/can-ajax.js create mode 100644 dist/global/can-ajax.js diff --git a/dist/amd/can-ajax.js b/dist/amd/can-ajax.js new file mode 100644 index 0000000..184cc3a --- /dev/null +++ b/dist/amd/can-ajax.js @@ -0,0 +1,214 @@ +/*can-ajax@2.4.5#can-ajax*/ +define([ + 'require', + 'exports', + 'module', + 'can-globals/global', + 'can-reflect', + 'can-namespace', + 'can-parse-uri', + 'can-param' +], function (require, exports, module) { + (function (global, require, exports, module) { + 'use strict'; + var Global = require('can-globals/global'); + var canReflect = require('can-reflect'); + var namespace = require('can-namespace'); + var parseURI = require('can-parse-uri'); + var param = require('can-param'); + var xhrs = [ + function () { + return new XMLHttpRequest(); + }, + function () { + return new ActiveXObject('Microsoft.XMLHTTP'); + }, + function () { + return new ActiveXObject('MSXML2.XMLHTTP.3.0'); + }, + function () { + return new ActiveXObject('MSXML2.XMLHTTP'); + } + ], _xhrf = null; + var originUrl = parseURI(Global().location.href); + var globalSettings = {}; + var makeXhr = function () { + if (_xhrf != null) { + return _xhrf(); + } + for (var i = 0, l = xhrs.length; i < l; i++) { + try { + var f = xhrs[i], req = f(); + if (req != null) { + _xhrf = f; + return req; + } + } catch (e) { + continue; + } + } + return function () { + }; + }; + var contentTypes = { + json: 'application/json', + form: 'application/x-www-form-urlencoded' + }; + var _xhrResp = function (xhr, options) { + try { + var type = options.dataType || xhr.getResponseHeader('Content-Type').split(';')[0]; + if (type && (xhr.responseText || xhr.responseXML)) { + switch (type) { + case 'text/xml': + case 'xml': + return xhr.responseXML; + case 'text/json': + case 'application/json': + case 'text/javascript': + case 'application/javascript': + case 'application/x-javascript': + case 'json': + return xhr.responseText && JSON.parse(xhr.responseText); + default: + return xhr.responseText; + } + } else { + return xhr; + } + } catch (e) { + return xhr; + } + }; + function ajax(o) { + var xhr = makeXhr(), timer, n = 0; + var deferred = {}, isFormData; + var promise = new Promise(function (resolve, reject) { + deferred.resolve = resolve; + deferred.reject = reject; + }); + var requestUrl; + var isAborted = false; + promise.abort = function () { + isAborted = true; + xhr.abort(); + }; + o = [ + { + userAgent: 'XMLHttpRequest', + lang: 'en', + type: 'GET', + data: null, + dataType: 'json' + }, + globalSettings, + o + ].reduce(function (a, b, i) { + return canReflect.assignDeep(a, b); + }); + var async = o.async !== false; + if (!o.contentType) { + o.contentType = o.type.toUpperCase() === 'GET' ? contentTypes.form : contentTypes.json; + } + if (o.crossDomain == null) { + try { + requestUrl = parseURI(o.url); + o.crossDomain = !!(requestUrl.protocol && requestUrl.protocol !== originUrl.protocol || requestUrl.host && requestUrl.host !== originUrl.host); + } catch (e) { + o.crossDomain = true; + } + } + if (o.timeout) { + timer = setTimeout(function () { + xhr.abort(); + if (o.timeoutFn) { + o.timeoutFn(o.url); + } + }, o.timeout); + } + xhr.onreadystatechange = function () { + try { + if (xhr.readyState === 4) { + if (timer) { + clearTimeout(timer); + } + if (xhr.status < 300) { + if (o.success) { + o.success(_xhrResp(xhr, o)); + } + } else if (o.error) { + o.error(xhr, xhr.status, xhr.statusText); + } + if (o.complete) { + o.complete(xhr, xhr.statusText); + } + if (xhr.status >= 200 && xhr.status < 300) { + deferred.resolve(_xhrResp(xhr, o)); + } else { + deferred.reject(_xhrResp(xhr, o)); + } + } else if (o.progress) { + o.progress(++n); + } + } catch (e) { + deferred.reject(e); + } + }; + var url = o.url, data = null, type = o.type.toUpperCase(); + var isJsonContentType = o.contentType === contentTypes.json; + var isPost = type === 'POST' || type === 'PUT'; + if (!isPost && o.data) { + url += '?' + (isJsonContentType ? JSON.stringify(o.data) : param(o.data)); + } + xhr.open(type, url, async); + var isSimpleCors = o.crossDomain && [ + 'GET', + 'POST', + 'HEAD' + ].indexOf(type) !== -1; + isFormData = typeof FormData !== 'undefined' && o.data instanceof FormData; + if (isPost) { + if (isFormData) { + data = o.data; + } else { + if (isJsonContentType && !isSimpleCors) { + data = typeof o.data === 'object' ? JSON.stringify(o.data) : o.data; + xhr.setRequestHeader('Content-Type', 'application/json'); + } else { + data = param(o.data); + xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); + } + } + } else { + xhr.setRequestHeader('Content-Type', o.contentType); + } + if (!isSimpleCors) { + xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); + } + if (o.xhrFields) { + for (var f in o.xhrFields) { + xhr[f] = o.xhrFields[f]; + } + } + function send() { + if (!isAborted) { + xhr.send(data); + } + } + if (o.beforeSend) { + var result = o.beforeSend.call(o, xhr, o); + if (canReflect.isPromise(result)) { + result.then(send).catch(deferred.reject); + return promise; + } + } + send(); + return promise; + } + module.exports = namespace.ajax = ajax; + module.exports.ajaxSetup = function (o) { + globalSettings = o || {}; + }; + }(function () { + return this; + }(), require, exports, module)); +}); \ No newline at end of file diff --git a/dist/cjs/can-ajax.js b/dist/cjs/can-ajax.js new file mode 100644 index 0000000..f37f144 --- /dev/null +++ b/dist/cjs/can-ajax.js @@ -0,0 +1,199 @@ +/*can-ajax@2.4.5#can-ajax*/ +'use strict'; +var Global = require('can-globals/global/global'); +var canReflect = require('can-reflect'); +var namespace = require('can-namespace'); +var parseURI = require('can-parse-uri'); +var param = require('can-param'); +var xhrs = [ + function () { + return new XMLHttpRequest(); + }, + function () { + return new ActiveXObject('Microsoft.XMLHTTP'); + }, + function () { + return new ActiveXObject('MSXML2.XMLHTTP.3.0'); + }, + function () { + return new ActiveXObject('MSXML2.XMLHTTP'); + } + ], _xhrf = null; +var originUrl = parseURI(Global().location.href); +var globalSettings = {}; +var makeXhr = function () { + if (_xhrf != null) { + return _xhrf(); + } + for (var i = 0, l = xhrs.length; i < l; i++) { + try { + var f = xhrs[i], req = f(); + if (req != null) { + _xhrf = f; + return req; + } + } catch (e) { + continue; + } + } + return function () { + }; +}; +var contentTypes = { + json: 'application/json', + form: 'application/x-www-form-urlencoded' +}; +var _xhrResp = function (xhr, options) { + try { + var type = options.dataType || xhr.getResponseHeader('Content-Type').split(';')[0]; + if (type && (xhr.responseText || xhr.responseXML)) { + switch (type) { + case 'text/xml': + case 'xml': + return xhr.responseXML; + case 'text/json': + case 'application/json': + case 'text/javascript': + case 'application/javascript': + case 'application/x-javascript': + case 'json': + return xhr.responseText && JSON.parse(xhr.responseText); + default: + return xhr.responseText; + } + } else { + return xhr; + } + } catch (e) { + return xhr; + } +}; +function ajax(o) { + var xhr = makeXhr(), timer, n = 0; + var deferred = {}, isFormData; + var promise = new Promise(function (resolve, reject) { + deferred.resolve = resolve; + deferred.reject = reject; + }); + var requestUrl; + var isAborted = false; + promise.abort = function () { + isAborted = true; + xhr.abort(); + }; + o = [ + { + userAgent: 'XMLHttpRequest', + lang: 'en', + type: 'GET', + data: null, + dataType: 'json' + }, + globalSettings, + o + ].reduce(function (a, b, i) { + return canReflect.assignDeep(a, b); + }); + var async = o.async !== false; + if (!o.contentType) { + o.contentType = o.type.toUpperCase() === 'GET' ? contentTypes.form : contentTypes.json; + } + if (o.crossDomain == null) { + try { + requestUrl = parseURI(o.url); + o.crossDomain = !!(requestUrl.protocol && requestUrl.protocol !== originUrl.protocol || requestUrl.host && requestUrl.host !== originUrl.host); + } catch (e) { + o.crossDomain = true; + } + } + if (o.timeout) { + timer = setTimeout(function () { + xhr.abort(); + if (o.timeoutFn) { + o.timeoutFn(o.url); + } + }, o.timeout); + } + xhr.onreadystatechange = function () { + try { + if (xhr.readyState === 4) { + if (timer) { + clearTimeout(timer); + } + if (xhr.status < 300) { + if (o.success) { + o.success(_xhrResp(xhr, o)); + } + } else if (o.error) { + o.error(xhr, xhr.status, xhr.statusText); + } + if (o.complete) { + o.complete(xhr, xhr.statusText); + } + if (xhr.status >= 200 && xhr.status < 300) { + deferred.resolve(_xhrResp(xhr, o)); + } else { + deferred.reject(_xhrResp(xhr, o)); + } + } else if (o.progress) { + o.progress(++n); + } + } catch (e) { + deferred.reject(e); + } + }; + var url = o.url, data = null, type = o.type.toUpperCase(); + var isJsonContentType = o.contentType === contentTypes.json; + var isPost = type === 'POST' || type === 'PUT'; + if (!isPost && o.data) { + url += '?' + (isJsonContentType ? JSON.stringify(o.data) : param(o.data)); + } + xhr.open(type, url, async); + var isSimpleCors = o.crossDomain && [ + 'GET', + 'POST', + 'HEAD' + ].indexOf(type) !== -1; + isFormData = typeof FormData !== 'undefined' && o.data instanceof FormData; + if (isPost) { + if (isFormData) { + data = o.data; + } else { + if (isJsonContentType && !isSimpleCors) { + data = typeof o.data === 'object' ? JSON.stringify(o.data) : o.data; + xhr.setRequestHeader('Content-Type', 'application/json'); + } else { + data = param(o.data); + xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); + } + } + } else { + xhr.setRequestHeader('Content-Type', o.contentType); + } + if (!isSimpleCors) { + xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); + } + if (o.xhrFields) { + for (var f in o.xhrFields) { + xhr[f] = o.xhrFields[f]; + } + } + function send() { + if (!isAborted) { + xhr.send(data); + } + } + if (o.beforeSend) { + var result = o.beforeSend.call(o, xhr, o); + if (canReflect.isPromise(result)) { + result.then(send).catch(deferred.reject); + return promise; + } + } + send(); + return promise; +} +module.exports = namespace.ajax = ajax; +module.exports.ajaxSetup = function (o) { + globalSettings = o || {}; +}; \ No newline at end of file diff --git a/dist/global/can-ajax.js b/dist/global/can-ajax.js new file mode 100644 index 0000000..7154900 --- /dev/null +++ b/dist/global/can-ajax.js @@ -0,0 +1,386 @@ +/*[process-shim]*/ +(function(global, env) { + // jshint ignore:line + if (typeof process === "undefined") { + global.process = { + argv: [], + cwd: function() { + return ""; + }, + browser: true, + env: { + NODE_ENV: env || "development" + }, + version: "", + platform: + global.navigator && + global.navigator.userAgent && + /Windows/.test(global.navigator.userAgent) + ? "win" + : "" + }; + } +})( + typeof self == "object" && self.Object == Object + ? self + : typeof process === "object" && + Object.prototype.toString.call(process) === "[object process]" + ? global + : window, + "development" +); + +/*[global-shim-start]*/ +(function(exports, global, doEval) { + // jshint ignore:line + var origDefine = global.define; + + var get = function(name) { + var parts = name.split("."), + cur = global, + i; + for (i = 0; i < parts.length; i++) { + if (!cur) { + break; + } + cur = cur[parts[i]]; + } + return cur; + }; + var set = function(name, val) { + var parts = name.split("."), + cur = global, + i, + part, + next; + for (i = 0; i < parts.length - 1; i++) { + part = parts[i]; + next = cur[part]; + if (!next) { + next = cur[part] = {}; + } + cur = next; + } + part = parts[parts.length - 1]; + cur[part] = val; + }; + var useDefault = function(mod) { + if (!mod || !mod.__esModule) return false; + var esProps = { __esModule: true, default: true }; + for (var p in mod) { + if (!esProps[p]) return false; + } + return true; + }; + + var hasCjsDependencies = function(deps) { + return ( + deps[0] === "require" && deps[1] === "exports" && deps[2] === "module" + ); + }; + + var modules = + (global.define && global.define.modules) || + (global._define && global._define.modules) || + {}; + var ourDefine = (global.define = function(moduleName, deps, callback) { + var module; + if (typeof deps === "function") { + callback = deps; + deps = []; + } + var args = [], + i; + for (i = 0; i < deps.length; i++) { + args.push( + exports[deps[i]] + ? get(exports[deps[i]]) + : modules[deps[i]] || get(deps[i]) + ); + } + // CJS has no dependencies but 3 callback arguments + if (hasCjsDependencies(deps) || (!deps.length && callback.length)) { + module = { exports: {} }; + args[0] = function(name) { + return exports[name] ? get(exports[name]) : modules[name]; + }; + args[1] = module.exports; + args[2] = module; + } else if (!args[0] && deps[0] === "exports") { + // Babel uses the exports and module object. + module = { exports: {} }; + args[0] = module.exports; + if (deps[1] === "module") { + args[1] = module; + } + } else if (!args[0] && deps[0] === "module") { + args[0] = { id: moduleName }; + } + + global.define = origDefine; + var result = callback ? callback.apply(null, args) : undefined; + global.define = ourDefine; + + // Favor CJS module.exports over the return value + result = module && module.exports ? module.exports : result; + modules[moduleName] = result; + + // Set global exports + var globalExport = exports[moduleName]; + if (globalExport && !get(globalExport)) { + if (useDefault(result)) { + result = result["default"]; + } + set(globalExport, result); + } + }); + global.define.orig = origDefine; + global.define.modules = modules; + global.define.amd = true; + ourDefine("@loader", [], function() { + // shim for @@global-helpers + var noop = function() {}; + return { + get: function() { + return { prepareGlobal: noop, retrieveGlobal: noop }; + }, + global: global, + __exec: function(__load) { + doEval(__load.source, global); + } + }; + }); +})( + {}, + typeof self == "object" && self.Object == Object + ? self + : typeof process === "object" && + Object.prototype.toString.call(process) === "[object process]" + ? global + : window, + function(__$source__, __$global__) { + // jshint ignore:line + eval("(function() { " + __$source__ + " \n }).call(__$global__);"); + } +); + +/*can-ajax@2.4.5#can-ajax*/ +define('can-ajax', [ + 'require', + 'exports', + 'module', + 'can-globals/global/global', + 'can-reflect', + 'can-namespace', + 'can-parse-uri', + 'can-param' +], function (require, exports, module) { + (function (global, require, exports, module) { + 'use strict'; + var Global = require('can-globals/global/global'); + var canReflect = require('can-reflect'); + var namespace = require('can-namespace'); + var parseURI = require('can-parse-uri'); + var param = require('can-param'); + var xhrs = [ + function () { + return new XMLHttpRequest(); + }, + function () { + return new ActiveXObject('Microsoft.XMLHTTP'); + }, + function () { + return new ActiveXObject('MSXML2.XMLHTTP.3.0'); + }, + function () { + return new ActiveXObject('MSXML2.XMLHTTP'); + } + ], _xhrf = null; + var originUrl = parseURI(Global().location.href); + var globalSettings = {}; + var makeXhr = function () { + if (_xhrf != null) { + return _xhrf(); + } + for (var i = 0, l = xhrs.length; i < l; i++) { + try { + var f = xhrs[i], req = f(); + if (req != null) { + _xhrf = f; + return req; + } + } catch (e) { + continue; + } + } + return function () { + }; + }; + var contentTypes = { + json: 'application/json', + form: 'application/x-www-form-urlencoded' + }; + var _xhrResp = function (xhr, options) { + try { + var type = options.dataType || xhr.getResponseHeader('Content-Type').split(';')[0]; + if (type && (xhr.responseText || xhr.responseXML)) { + switch (type) { + case 'text/xml': + case 'xml': + return xhr.responseXML; + case 'text/json': + case 'application/json': + case 'text/javascript': + case 'application/javascript': + case 'application/x-javascript': + case 'json': + return xhr.responseText && JSON.parse(xhr.responseText); + default: + return xhr.responseText; + } + } else { + return xhr; + } + } catch (e) { + return xhr; + } + }; + function ajax(o) { + var xhr = makeXhr(), timer, n = 0; + var deferred = {}, isFormData; + var promise = new Promise(function (resolve, reject) { + deferred.resolve = resolve; + deferred.reject = reject; + }); + var requestUrl; + var isAborted = false; + promise.abort = function () { + isAborted = true; + xhr.abort(); + }; + o = [ + { + userAgent: 'XMLHttpRequest', + lang: 'en', + type: 'GET', + data: null, + dataType: 'json' + }, + globalSettings, + o + ].reduce(function (a, b, i) { + return canReflect.assignDeep(a, b); + }); + var async = o.async !== false; + if (!o.contentType) { + o.contentType = o.type.toUpperCase() === 'GET' ? contentTypes.form : contentTypes.json; + } + if (o.crossDomain == null) { + try { + requestUrl = parseURI(o.url); + o.crossDomain = !!(requestUrl.protocol && requestUrl.protocol !== originUrl.protocol || requestUrl.host && requestUrl.host !== originUrl.host); + } catch (e) { + o.crossDomain = true; + } + } + if (o.timeout) { + timer = setTimeout(function () { + xhr.abort(); + if (o.timeoutFn) { + o.timeoutFn(o.url); + } + }, o.timeout); + } + xhr.onreadystatechange = function () { + try { + if (xhr.readyState === 4) { + if (timer) { + clearTimeout(timer); + } + if (xhr.status < 300) { + if (o.success) { + o.success(_xhrResp(xhr, o)); + } + } else if (o.error) { + o.error(xhr, xhr.status, xhr.statusText); + } + if (o.complete) { + o.complete(xhr, xhr.statusText); + } + if (xhr.status >= 200 && xhr.status < 300) { + deferred.resolve(_xhrResp(xhr, o)); + } else { + deferred.reject(_xhrResp(xhr, o)); + } + } else if (o.progress) { + o.progress(++n); + } + } catch (e) { + deferred.reject(e); + } + }; + var url = o.url, data = null, type = o.type.toUpperCase(); + var isJsonContentType = o.contentType === contentTypes.json; + var isPost = type === 'POST' || type === 'PUT'; + if (!isPost && o.data) { + url += '?' + (isJsonContentType ? JSON.stringify(o.data) : param(o.data)); + } + xhr.open(type, url, async); + var isSimpleCors = o.crossDomain && [ + 'GET', + 'POST', + 'HEAD' + ].indexOf(type) !== -1; + isFormData = typeof FormData !== 'undefined' && o.data instanceof FormData; + if (isPost) { + if (isFormData) { + data = o.data; + } else { + if (isJsonContentType && !isSimpleCors) { + data = typeof o.data === 'object' ? JSON.stringify(o.data) : o.data; + xhr.setRequestHeader('Content-Type', 'application/json'); + } else { + data = param(o.data); + xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); + } + } + } else { + xhr.setRequestHeader('Content-Type', o.contentType); + } + if (!isSimpleCors) { + xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); + } + if (o.xhrFields) { + for (var f in o.xhrFields) { + xhr[f] = o.xhrFields[f]; + } + } + function send() { + if (!isAborted) { + xhr.send(data); + } + } + if (o.beforeSend) { + var result = o.beforeSend.call(o, xhr, o); + if (canReflect.isPromise(result)) { + result.then(send).catch(deferred.reject); + return promise; + } + } + send(); + return promise; + } + module.exports = namespace.ajax = ajax; + module.exports.ajaxSetup = function (o) { + globalSettings = o || {}; + }; + }(function () { + return this; + }(), require, exports, module)); +}); +/*[global-shim-end]*/ +(function(global) { // jshint ignore:line + global._define = global.define; + global.define = global.define.orig; +} +)(typeof self == "object" && self.Object == Object ? self : (typeof process === "object" && Object.prototype.toString.call(process) === "[object process]") ? global : window); \ No newline at end of file