123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354 |
- /******/ (function(modules) { // webpackBootstrap
- /******/ // The module cache
- /******/ var installedModules = {};
- /******/
- /******/ // The require function
- /******/ function __webpack_require__(moduleId) {
- /******/
- /******/ // Check if module is in cache
- /******/ if(installedModules[moduleId]) {
- /******/ return installedModules[moduleId].exports;
- /******/ }
- /******/ // Create a new module (and put it into the cache)
- /******/ var module = installedModules[moduleId] = {
- /******/ i: moduleId,
- /******/ l: false,
- /******/ exports: {}
- /******/ };
- /******/
- /******/ // Execute the module function
- /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
- /******/
- /******/ // Flag the module as loaded
- /******/ module.l = true;
- /******/
- /******/ // Return the exports of the module
- /******/ return module.exports;
- /******/ }
- /******/
- /******/
- /******/ // expose the modules object (__webpack_modules__)
- /******/ __webpack_require__.m = modules;
- /******/
- /******/ // expose the module cache
- /******/ __webpack_require__.c = installedModules;
- /******/
- /******/ // identity function for calling harmony imports with the correct context
- /******/ __webpack_require__.i = function(value) { return value; };
- /******/
- /******/ // define getter function for harmony exports
- /******/ __webpack_require__.d = function(exports, name, getter) {
- /******/ if(!__webpack_require__.o(exports, name)) {
- /******/ Object.defineProperty(exports, name, {
- /******/ configurable: false,
- /******/ enumerable: true,
- /******/ get: getter
- /******/ });
- /******/ }
- /******/ };
- /******/
- /******/ // getDefaultExport function for compatibility with non-harmony modules
- /******/ __webpack_require__.n = function(module) {
- /******/ var getter = module && module.__esModule ?
- /******/ function getDefault() { return module['default']; } :
- /******/ function getModuleExports() { return module; };
- /******/ __webpack_require__.d(getter, 'a', getter);
- /******/ return getter;
- /******/ };
- /******/
- /******/ // Object.prototype.hasOwnProperty.call
- /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
- /******/
- /******/ // __webpack_public_path__
- /******/ __webpack_require__.p = "";
- /******/
- /******/ // Load entry module and return exports
- /******/ return __webpack_require__(__webpack_require__.s = 4);
- /******/ })
- /************************************************************************/
- /******/ ([
- /* 0 */,
- /* 1 */
- /***/ (function(module, exports, __webpack_require__) {
- "use strict";
- var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
- module.exports = {
- type: function type(ob) {
- return Object.prototype.toString.call(ob).slice(8, -1).toLowerCase();
- },
- isObject: function isObject(ob, real) {
- if (real) {
- return this.type(ob) === "object";
- } else {
- return ob && (typeof ob === 'undefined' ? 'undefined' : _typeof(ob)) === 'object';
- }
- },
- isFormData: function isFormData(val) {
- return typeof FormData !== 'undefined' && val instanceof FormData;
- },
- trim: function trim(str) {
- return str.replace(/(^\s*)|(\s*$)/g, '');
- },
- encode: function encode(val) {
- return encodeURIComponent(val).replace(/%40/gi, '@').replace(/%3A/gi, ':').replace(/%24/g, '$').replace(/%2C/gi, ',').replace(/%20/g, '+').replace(/%5B/gi, '[').replace(/%5D/gi, ']');
- },
- formatParams: function formatParams(data) {
- var str = "";
- var first = true;
- var that = this;
- if (!this.isObject(data)) {
- return data;
- }
- function _encode(sub, path) {
- var encode = that.encode;
- var type = that.type(sub);
- if (type == "array") {
- sub.forEach(function (e, i) {
- if (!that.isObject(e)) i = "";
- _encode(e, path + ('%5B' + i + '%5D'));
- });
- } else if (type == "object") {
- for (var key in sub) {
- if (path) {
- _encode(sub[key], path + "%5B" + encode(key) + "%5D");
- } else {
- _encode(sub[key], encode(key));
- }
- }
- } else {
- if (!first) {
- str += "&";
- }
- first = false;
- str += path + "=" + encode(sub);
- }
- }
- _encode(data, "");
- return str;
- },
- // Do not overwrite existing attributes
- merge: function merge(a, b) {
- for (var key in b) {
- if (!a.hasOwnProperty(key)) {
- a[key] = b[key];
- } else if (this.isObject(b[key], 1) && this.isObject(a[key], 1)) {
- this.merge(a[key], b[key]);
- }
- }
- return a;
- }
- };
- /***/ }),
- /* 2 */,
- /* 3 */,
- /* 4 */
- /***/ (function(module, exports, __webpack_require__) {
- function KEEP(_,cb){cb();}
- "use strict";
- var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- /*
- * author: wendu
- * email: 824783146@qq.com
- **/
- var util = __webpack_require__(1);
- var isBrowser = typeof document !== "undefined";
- //EngineWrapper can help generating a http engine quickly through a adapter
- function EngineWrapper(adapter) {
- var AjaxEngine = function () {
- function AjaxEngine() {
- _classCallCheck(this, AjaxEngine);
- this.requestHeaders = {};
- this.readyState = 0;
- this.timeout = 0; // 0 stands for no timeout
- this.responseURL = "";
- this.responseHeaders = {};
- }
- _createClass(AjaxEngine, [{
- key: "_call",
- value: function _call(name) {
- this[name] && this[name].apply(this, [].splice.call(arguments, 1));
- }
- }, {
- key: "_changeReadyState",
- value: function _changeReadyState(state) {
- this.readyState = state;
- this._call("onreadystatechange");
- }
- }, {
- key: "open",
- value: function open(method, url) {
- this.method = method;
- if (!url) {
- url = location.href;
- } else {
- url = util.trim(url);
- if (url.indexOf("http") !== 0) {
- // Normalize the request url
- if (isBrowser) {
- var t = document.createElement("a");
- t.href = url;
- url = t.href;
- }
- }
- }
- this.responseURL = url;
- this._changeReadyState(1);
- }
- }, {
- key: "send",
- value: function send(arg) {
- var _this = this;
- arg = arg || null;
- var self = this;
- if (adapter) {
- var request = {
- method: self.method,
- url: self.responseURL,
- headers: self.requestHeaders || {},
- body: arg
- };
- util.merge(request, self._options || {});
- if (request.method === "GET") {
- request.body = null;
- }
- self._changeReadyState(3);
- var timer = void 0;
- self.timeout = self.timeout || 0;
- if (self.timeout > 0) {
- timer = setTimeout(function () {
- if (self.readyState === 3) {
- _this._call("onloadend");
- self._changeReadyState(0);
- self._call("ontimeout");
- }
- }, self.timeout);
- }
- request.timeout = self.timeout;
- adapter(request, function (response) {
- function getAndDelete(key) {
- var t = response[key];
- delete response[key];
- return t;
- }
- // If the request has already timeout, return
- if (self.readyState !== 3) return;
- clearTimeout(timer);
- // Make sure the type of status is integer
- self.status = getAndDelete("statusCode") - 0;
- var responseText = getAndDelete("responseText");
- var statusMessage = getAndDelete("statusMessage");
- // Network error, set the status code 0
- if (!self.status) {
- self.statusText = responseText;
- self._call("onerror", { msg: statusMessage });
- } else {
- // Parsing the response headers to array in a object, because
- // there may be multiple values with the same header name
- var responseHeaders = getAndDelete("headers");
- var headers = {};
- for (var field in responseHeaders) {
- var value = responseHeaders[field];
- var key = field.toLowerCase();
- // Is array
- if ((typeof value === "undefined" ? "undefined" : _typeof(value)) === "object") {
- headers[key] = value;
- } else {
- headers[key] = headers[key] || [];
- headers[key].push(value);
- }
- }
- var cookies = headers["set-cookie"];
- if (isBrowser && cookies) {
- cookies.forEach(function (e) {
- // Remove the http-Only property of the cookie
- // so that JavaScript can operate it.
- document.cookie = e.replace(/;\s*httpOnly/ig, "");
- });
- }
- self.responseHeaders = headers;
- // Set the fields of engine from response
- self.statusText = statusMessage || "";
- self.response = self.responseText = responseText;
- self._response = response;
- self._changeReadyState(4);
- self._call("onload");
- }
- self._call("onloadend");
- });
- } else {
- console.error("Ajax require adapter");
- }
- }
- }, {
- key: "setRequestHeader",
- value: function setRequestHeader(key, value) {
- this.requestHeaders[util.trim(key)] = value;
- }
- }, {
- key: "getResponseHeader",
- value: function getResponseHeader(key) {
- return (this.responseHeaders[key.toLowerCase()] || "").toString() || null;
- }
- }, {
- key: "getAllResponseHeaders",
- value: function getAllResponseHeaders() {
- var str = "";
- for (var key in this.responseHeaders) {
- str += key + ":" + this.getResponseHeader(key) + "\r\n";
- }
- return str || null;
- }
- }, {
- key: "abort",
- value: function abort(msg) {
- this._changeReadyState(0);
- this._call("onerror", { msg: msg });
- this._call("onloadend");
- }
- }], [{
- key: "setAdapter",
- value: function setAdapter(requestAdapter) {
- adapter = requestAdapter;
- }
- }]);
- return AjaxEngine;
- }();
- return AjaxEngine;
- }
- // learn more about keep-loader: https://github.com/wendux/keep-loader
- KEEP("cdn||cdn-min", function () {
- // This code block will be removed besides the "CDN" and "cdn-min" build environment
- window.EngineWrapper = EngineWrapper;
- });
- module.exports = EngineWrapper;
- /***/ })
- /******/ ]);
|