polyfill.js
3 years ago
scripts.js
3 years ago
scripts.js.map
3 years ago
scripts_admin copy.js
4 years ago
scripts_admin.js
4 years ago
scripts_admin_all_pages.js
5 years ago
scripts_es6.js
3 years ago
temp.js
4 years ago
scripts.js
4133 lines
| 1 | /******/ (function(modules) { // webpackBootstrap |
| 2 | /******/ // The module cache |
| 3 | /******/ var installedModules = {}; |
| 4 | /******/ |
| 5 | /******/ // The require function |
| 6 | /******/ function __webpack_require__(moduleId) { |
| 7 | /******/ |
| 8 | /******/ // Check if module is in cache |
| 9 | /******/ if(installedModules[moduleId]) { |
| 10 | /******/ return installedModules[moduleId].exports; |
| 11 | /******/ } |
| 12 | /******/ // Create a new module (and put it into the cache) |
| 13 | /******/ var module = installedModules[moduleId] = { |
| 14 | /******/ i: moduleId, |
| 15 | /******/ l: false, |
| 16 | /******/ exports: {} |
| 17 | /******/ }; |
| 18 | /******/ |
| 19 | /******/ // Execute the module function |
| 20 | /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); |
| 21 | /******/ |
| 22 | /******/ // Flag the module as loaded |
| 23 | /******/ module.l = true; |
| 24 | /******/ |
| 25 | /******/ // Return the exports of the module |
| 26 | /******/ return module.exports; |
| 27 | /******/ } |
| 28 | /******/ |
| 29 | /******/ |
| 30 | /******/ // expose the modules object (__webpack_modules__) |
| 31 | /******/ __webpack_require__.m = modules; |
| 32 | /******/ |
| 33 | /******/ // expose the module cache |
| 34 | /******/ __webpack_require__.c = installedModules; |
| 35 | /******/ |
| 36 | /******/ // define getter function for harmony exports |
| 37 | /******/ __webpack_require__.d = function(exports, name, getter) { |
| 38 | /******/ if(!__webpack_require__.o(exports, name)) { |
| 39 | /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); |
| 40 | /******/ } |
| 41 | /******/ }; |
| 42 | /******/ |
| 43 | /******/ // define __esModule on exports |
| 44 | /******/ __webpack_require__.r = function(exports) { |
| 45 | /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { |
| 46 | /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); |
| 47 | /******/ } |
| 48 | /******/ Object.defineProperty(exports, '__esModule', { value: true }); |
| 49 | /******/ }; |
| 50 | /******/ |
| 51 | /******/ // create a fake namespace object |
| 52 | /******/ // mode & 1: value is a module id, require it |
| 53 | /******/ // mode & 2: merge all properties of value into the ns |
| 54 | /******/ // mode & 4: return value when already ns object |
| 55 | /******/ // mode & 8|1: behave like require |
| 56 | /******/ __webpack_require__.t = function(value, mode) { |
| 57 | /******/ if(mode & 1) value = __webpack_require__(value); |
| 58 | /******/ if(mode & 8) return value; |
| 59 | /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; |
| 60 | /******/ var ns = Object.create(null); |
| 61 | /******/ __webpack_require__.r(ns); |
| 62 | /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); |
| 63 | /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); |
| 64 | /******/ return ns; |
| 65 | /******/ }; |
| 66 | /******/ |
| 67 | /******/ // getDefaultExport function for compatibility with non-harmony modules |
| 68 | /******/ __webpack_require__.n = function(module) { |
| 69 | /******/ var getter = module && module.__esModule ? |
| 70 | /******/ function getDefault() { return module['default']; } : |
| 71 | /******/ function getModuleExports() { return module; }; |
| 72 | /******/ __webpack_require__.d(getter, 'a', getter); |
| 73 | /******/ return getter; |
| 74 | /******/ }; |
| 75 | /******/ |
| 76 | /******/ // Object.prototype.hasOwnProperty.call |
| 77 | /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; |
| 78 | /******/ |
| 79 | /******/ // __webpack_public_path__ |
| 80 | /******/ __webpack_require__.p = ""; |
| 81 | /******/ |
| 82 | /******/ |
| 83 | /******/ // Load entry module and return exports |
| 84 | /******/ return __webpack_require__(__webpack_require__.s = 0); |
| 85 | /******/ }) |
| 86 | /************************************************************************/ |
| 87 | /******/ ({ |
| 88 | |
| 89 | /***/ "./js/polyfill.js": |
| 90 | /*!************************!*\ |
| 91 | !*** ./js/polyfill.js ***! |
| 92 | \************************/ |
| 93 | /*! no static exports found */ |
| 94 | /***/ (function(module, exports) { |
| 95 | |
| 96 | // endsWith polyfill |
| 97 | if (!String.prototype.endsWith) { |
| 98 | String.prototype.endsWith = function (search, thisLength) { |
| 99 | if (thisLength === undefined || thisLength > this.length) { |
| 100 | thisLength = this.length; |
| 101 | } |
| 102 | |
| 103 | return this.substring(thisLength - search.length, thisLength) === search; |
| 104 | }; |
| 105 | } // Object.values polyfill |
| 106 | |
| 107 | |
| 108 | if (!Object.values) Object.values = function (o) { |
| 109 | return Object.keys(o).map(function (k) { |
| 110 | return o[k]; |
| 111 | }); |
| 112 | }; // Array.from polyfill |
| 113 | |
| 114 | if (!Array.from) { |
| 115 | Array.from = function () { |
| 116 | var toStr = Object.prototype.toString; |
| 117 | |
| 118 | var isCallable = function isCallable(fn) { |
| 119 | return typeof fn === 'function' || toStr.call(fn) === '[object Function]'; |
| 120 | }; |
| 121 | |
| 122 | var toInteger = function toInteger(value) { |
| 123 | var number = Number(value); |
| 124 | |
| 125 | if (isNaN(number)) { |
| 126 | return 0; |
| 127 | } |
| 128 | |
| 129 | if (number === 0 || !isFinite(number)) { |
| 130 | return number; |
| 131 | } |
| 132 | |
| 133 | return (number > 0 ? 1 : -1) * Math.floor(Math.abs(number)); |
| 134 | }; |
| 135 | |
| 136 | var maxSafeInteger = Math.pow(2, 53) - 1; |
| 137 | |
| 138 | var toLength = function toLength(value) { |
| 139 | var len = toInteger(value); |
| 140 | return Math.min(Math.max(len, 0), maxSafeInteger); |
| 141 | }; // The length property of the from method is 1. |
| 142 | |
| 143 | |
| 144 | return function from(arrayLike |
| 145 | /*, mapFn, thisArg */ |
| 146 | ) { |
| 147 | // 1. Let C be the this value. |
| 148 | var C = this; // 2. Let items be ToObject(arrayLike). |
| 149 | |
| 150 | var items = Object(arrayLike); // 3. ReturnIfAbrupt(items). |
| 151 | |
| 152 | if (arrayLike == null) { |
| 153 | throw new TypeError("Array.from requires an array-like object - not null or undefined"); |
| 154 | } // 4. If mapfn is undefined, then let mapping be false. |
| 155 | |
| 156 | |
| 157 | var mapFn = arguments.length > 1 ? arguments[1] : void undefined; |
| 158 | var T; |
| 159 | |
| 160 | if (typeof mapFn !== 'undefined') { |
| 161 | // 5. else |
| 162 | // 5. a If IsCallable(mapfn) is false, throw a TypeError exception. |
| 163 | if (!isCallable(mapFn)) { |
| 164 | throw new TypeError('Array.from: when provided, the second argument must be a function'); |
| 165 | } // 5. b. If thisArg was supplied, let T be thisArg; else let T be undefined. |
| 166 | |
| 167 | |
| 168 | if (arguments.length > 2) { |
| 169 | T = arguments[2]; |
| 170 | } |
| 171 | } // 10. Let lenValue be Get(items, "length"). |
| 172 | // 11. Let len be ToLength(lenValue). |
| 173 | |
| 174 | |
| 175 | var len = toLength(items.length); // 13. If IsConstructor(C) is true, then |
| 176 | // 13. a. Let A be the result of calling the [[Construct]] internal method of C with an argument list containing the single item len. |
| 177 | // 14. a. Else, Let A be ArrayCreate(len). |
| 178 | |
| 179 | var A = isCallable(C) ? Object(new C(len)) : new Array(len); // 16. Let k be 0. |
| 180 | |
| 181 | var k = 0; // 17. Repeat, while k < len… (also steps a - h) |
| 182 | |
| 183 | var kValue; |
| 184 | |
| 185 | while (k < len) { |
| 186 | kValue = items[k]; |
| 187 | |
| 188 | if (mapFn) { |
| 189 | A[k] = typeof T === 'undefined' ? mapFn(kValue, k) : mapFn.call(T, kValue, k); |
| 190 | } else { |
| 191 | A[k] = kValue; |
| 192 | } |
| 193 | |
| 194 | k += 1; |
| 195 | } // 18. Let putStatus be Put(A, "length", len, true). |
| 196 | |
| 197 | |
| 198 | A.length = len; // 20. Return A. |
| 199 | |
| 200 | return A; |
| 201 | }; |
| 202 | }(); |
| 203 | } |
| 204 | |
| 205 | /***/ }), |
| 206 | |
| 207 | /***/ "./js/scripts_es6.js": |
| 208 | /*!***************************!*\ |
| 209 | !*** ./js/scripts_es6.js ***! |
| 210 | \***************************/ |
| 211 | /*! no exports provided */ |
| 212 | /***/ (function(module, __webpack_exports__, __webpack_require__) { |
| 213 | |
| 214 | "use strict"; |
| 215 | __webpack_require__.r(__webpack_exports__); |
| 216 | /* harmony import */ var _babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/slicedToArray */ "./node_modules/@babel/runtime/helpers/slicedToArray.js"); |
| 217 | /* harmony import */ var _babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_0__); |
| 218 | /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js"); |
| 219 | /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_1__); |
| 220 | /* harmony import */ var _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @babel/runtime/regenerator */ "./node_modules/@babel/runtime/regenerator/index.js"); |
| 221 | /* harmony import */ var _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2__); |
| 222 | /* harmony import */ var _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @babel/runtime/helpers/asyncToGenerator */ "./node_modules/@babel/runtime/helpers/asyncToGenerator.js"); |
| 223 | /* harmony import */ var _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_3__); |
| 224 | /* harmony import */ var _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @babel/runtime/helpers/toConsumableArray */ "./node_modules/@babel/runtime/helpers/toConsumableArray.js"); |
| 225 | /* harmony import */ var _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_4__); |
| 226 | // disable client side validation introduced in CF7 5.6 for now |
| 227 | |
| 228 | |
| 229 | |
| 230 | |
| 231 | |
| 232 | |
| 233 | |
| 234 | function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } |
| 235 | |
| 236 | function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_1___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } |
| 237 | |
| 238 | if (typeof wpcf7 !== 'undefined') { |
| 239 | wpcf7.validate = function (a, b) { |
| 240 | return null; |
| 241 | }; |
| 242 | } |
| 243 | |
| 244 | var cf7signature_resized = 0; // for compatibility with contact-form-7-signature-addon |
| 245 | |
| 246 | var wpcf7cf_timeout; |
| 247 | var wpcf7cf_change_time_ms = 100; // the timeout after a change in the form is detected |
| 248 | |
| 249 | if (window.wpcf7 && !wpcf7.setStatus) { |
| 250 | wpcf7.setStatus = function (form, status) { |
| 251 | form = form.length ? form[0] : form; // if form is a jQuery object, only grab te html-element |
| 252 | |
| 253 | var defaultStatuses = new Map([// 0: Status in API response, 1: Status in HTML class |
| 254 | ['init', 'init'], ['validation_failed', 'invalid'], ['acceptance_missing', 'unaccepted'], ['spam', 'spam'], ['aborted', 'aborted'], ['mail_sent', 'sent'], ['mail_failed', 'failed'], ['submitting', 'submitting'], ['resetting', 'resetting']]); |
| 255 | |
| 256 | if (defaultStatuses.has(status)) { |
| 257 | status = defaultStatuses.get(status); |
| 258 | } |
| 259 | |
| 260 | if (!Array.from(defaultStatuses.values()).includes(status)) { |
| 261 | status = status.replace(/[^0-9a-z]+/i, ' ').trim(); |
| 262 | status = status.replace(/\s+/, '-'); |
| 263 | status = "custom-".concat(status); |
| 264 | } |
| 265 | |
| 266 | var prevStatus = form.getAttribute('data-status'); |
| 267 | form.wpcf7.status = status; |
| 268 | form.setAttribute('data-status', status); |
| 269 | form.classList.add(status); |
| 270 | |
| 271 | if (prevStatus && prevStatus !== status) { |
| 272 | form.classList.remove(prevStatus); |
| 273 | } |
| 274 | |
| 275 | return status; |
| 276 | }; |
| 277 | } |
| 278 | |
| 279 | if (window.wpcf7cf_running_tests) { |
| 280 | jQuery('input[name="_wpcf7cf_options"]').each(function (e) { |
| 281 | var $input = jQuery(this); |
| 282 | var opt = JSON.parse($input.val()); |
| 283 | opt.settings.animation_intime = 0; |
| 284 | opt.settings.animation_outtime = 0; |
| 285 | $input.val(JSON.stringify(opt)); |
| 286 | }); |
| 287 | wpcf7cf_change_time_ms = 0; |
| 288 | } |
| 289 | |
| 290 | var wpcf7cf_show_animation = { |
| 291 | "height": "show", |
| 292 | "marginTop": "show", |
| 293 | "marginBottom": "show", |
| 294 | "paddingTop": "show", |
| 295 | "paddingBottom": "show" |
| 296 | }; |
| 297 | var wpcf7cf_hide_animation = { |
| 298 | "height": "hide", |
| 299 | "marginTop": "hide", |
| 300 | "marginBottom": "hide", |
| 301 | "paddingTop": "hide", |
| 302 | "paddingBottom": "hide" |
| 303 | }; |
| 304 | var wpcf7cf_show_step_animation = { |
| 305 | "opacity": "show" |
| 306 | }; |
| 307 | var wpcf7cf_hide_step_animation = { |
| 308 | "opacity": "hide" |
| 309 | }; |
| 310 | var wpcf7cf_change_events = 'input.wpcf7cf paste.wpcf7cf change.wpcf7cf click.wpcf7cf propertychange.wpcf7cf changedisabledprop.wpcf7cf'; |
| 311 | var wpcf7cf_forms = []; |
| 312 | |
| 313 | var Wpcf7cfForm = function Wpcf7cfForm($form) { |
| 314 | var options_element = $form.find('input[name="_wpcf7cf_options"]').eq(0); |
| 315 | |
| 316 | if (!options_element.length || !options_element.val()) { |
| 317 | // doesn't look like a CF7 form created with conditional fields plugin enabled. |
| 318 | return false; |
| 319 | } |
| 320 | |
| 321 | var form = this; |
| 322 | var form_options = JSON.parse(options_element.val()); |
| 323 | form.$form = $form; |
| 324 | form.$input_hidden_group_fields = $form.find('[name="_wpcf7cf_hidden_group_fields"]'); |
| 325 | form.$input_hidden_groups = $form.find('[name="_wpcf7cf_hidden_groups"]'); |
| 326 | form.$input_visible_groups = $form.find('[name="_wpcf7cf_visible_groups"]'); |
| 327 | form.$input_repeaters = $form.find('[name="_wpcf7cf_repeaters"]'); |
| 328 | form.$input_steps = $form.find('[name="_wpcf7cf_steps"]'); |
| 329 | form.unit_tag = $form.closest('.wpcf7').attr('id'); |
| 330 | form.conditions = form_options['conditions']; |
| 331 | form.simpleDom = null; |
| 332 | |
| 333 | form.reloadSimpleDom = function () { |
| 334 | form.simpleDom = wpcf7cf.get_simplified_dom_model(form.$form[0]); |
| 335 | }; // quicker than reloading the simpleDom completely with reloadSimpleDom |
| 336 | |
| 337 | |
| 338 | form.updateSimpleDom = function () { |
| 339 | if (!form.simpleDom) { |
| 340 | form.reloadSimpleDom(); |
| 341 | } |
| 342 | |
| 343 | var inputs = Object.values(form.simpleDom).filter(function (item) { |
| 344 | return item.type === 'input'; |
| 345 | }); |
| 346 | var formdata = new FormData(form.$form[0]); |
| 347 | |
| 348 | var formdataEntries = _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_4___default()(formdata.entries()).map(function (entry) { |
| 349 | var _entry$1$name; |
| 350 | |
| 351 | return [entry[0], (_entry$1$name = entry[1].name) !== null && _entry$1$name !== void 0 ? _entry$1$name : entry[1]]; |
| 352 | }); // const changedInputs = inputs.filter(item => !form.isDomMatch(item, formdataEntries)); |
| 353 | |
| 354 | |
| 355 | inputs.forEach(function (simpleDomItem) { |
| 356 | var newValue = form.getNewDomValueIfChanged(simpleDomItem, formdataEntries); |
| 357 | |
| 358 | if (newValue !== null) { |
| 359 | form.simpleDom[simpleDomItem.name].val = newValue; |
| 360 | } |
| 361 | }); |
| 362 | }; |
| 363 | |
| 364 | form.isDomMatch = function (simpleDomItem, formDataEntries) { |
| 365 | var simpleDomItemName = simpleDomItem.name; |
| 366 | var simpleDomItemValues = simpleDomItem.val; |
| 367 | var currentValues = formDataEntries.filter(function (entry) { |
| 368 | return entry[0] === simpleDomItemName; |
| 369 | }).map(function (entry) { |
| 370 | return entry[1]; |
| 371 | }); |
| 372 | return currentValues.join('|') === simpleDomItemValues.join('|'); |
| 373 | }; |
| 374 | /** |
| 375 | * |
| 376 | * @param {*} simpleDomItem |
| 377 | * @param {*} formDataEntries |
| 378 | * @returns the new value, or NULL if no change |
| 379 | */ |
| 380 | |
| 381 | |
| 382 | form.getNewDomValueIfChanged = function (simpleDomItem, formDataEntries) { |
| 383 | var simpleDomItemName = simpleDomItem.name; |
| 384 | var simpleDomItemValues = simpleDomItem.val; |
| 385 | var currentValues = formDataEntries.filter(function (entry) { |
| 386 | return entry[0] === simpleDomItemName; |
| 387 | }).map(function (entry) { |
| 388 | return entry[1]; |
| 389 | }); |
| 390 | return currentValues.join('|') === simpleDomItemValues.join('|') ? null : currentValues; |
| 391 | }; // Wrapper around jQuery(selector, form.$form) |
| 392 | |
| 393 | |
| 394 | form.get = function (selector) { |
| 395 | // TODO: implement some caching here. |
| 396 | return jQuery(selector, form.$form); |
| 397 | }; |
| 398 | |
| 399 | form.getFieldByName = function (name) { |
| 400 | return form.simpleDom[name] || form.simpleDom[name + '[]']; |
| 401 | }; // compatibility with conditional forms created with older versions of the plugin ( < 1.4 ) |
| 402 | |
| 403 | |
| 404 | for (var i = 0; i < form.conditions.length; i++) { |
| 405 | var condition = form.conditions[i]; |
| 406 | |
| 407 | if (!('and_rules' in condition)) { |
| 408 | condition.and_rules = [{ |
| 409 | 'if_field': condition.if_field, |
| 410 | 'if_value': condition.if_value, |
| 411 | 'operator': condition.operator |
| 412 | }]; |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | form.initial_conditions = form.conditions; |
| 417 | form.settings = form_options['settings']; |
| 418 | form.$groups = jQuery(); // empty jQuery set |
| 419 | |
| 420 | form.repeaters = []; |
| 421 | form.multistep = null; |
| 422 | form.fields = []; |
| 423 | form.settings.animation_intime = parseInt(form.settings.animation_intime); |
| 424 | form.settings.animation_outtime = parseInt(form.settings.animation_outtime); |
| 425 | |
| 426 | if (form.settings.animation === 'no') { |
| 427 | form.settings.animation_intime = 0; |
| 428 | form.settings.animation_outtime = 0; |
| 429 | } |
| 430 | |
| 431 | form.updateGroups(); |
| 432 | form.updateEventListeners(); |
| 433 | form.displayFields(); // bring form in initial state if the reset event is fired on it. |
| 434 | // (CF7 triggers the 'reset' event by default on each successfully submitted form) |
| 435 | |
| 436 | form.$form.on('reset.wpcf7cf', form, function (e) { |
| 437 | var form = e.data; |
| 438 | setTimeout(function () { |
| 439 | form.reloadSimpleDom(); |
| 440 | form.displayFields(); |
| 441 | form.resetRepeaters(); |
| 442 | |
| 443 | if (form.multistep != null) { |
| 444 | form.multistep.moveToStep(1, false); |
| 445 | } |
| 446 | |
| 447 | setTimeout(function () { |
| 448 | if (form.$form.hasClass('sent')) { |
| 449 | jQuery('.wpcf7-response-output', form.$form)[0].scrollIntoView({ |
| 450 | behavior: "smooth", |
| 451 | block: "nearest", |
| 452 | inline: "nearest" |
| 453 | }); |
| 454 | } |
| 455 | }, 400); |
| 456 | }, 200); |
| 457 | }); // PRO ONLY |
| 458 | |
| 459 | form.get('.wpcf7cf_repeater:not(.wpcf7cf_repeater .wpcf7cf_repeater)').each(function () { |
| 460 | form.repeaters.push(new Wpcf7cfRepeater(jQuery(this), form)); |
| 461 | }); |
| 462 | form.$input_repeaters.val(JSON.stringify(form.repeaters.map(function (item) { |
| 463 | return item.params.$repeater.id; |
| 464 | }))); |
| 465 | var $multistep = form.get('.wpcf7cf_multistep'); |
| 466 | |
| 467 | if ($multistep.length) { |
| 468 | form.multistep = new Wpcf7cfMultistep($multistep, form); // window.wpcf7cf.updateMultistepState(form.multistep); |
| 469 | } // END PRO ONLY |
| 470 | |
| 471 | }; |
| 472 | /** |
| 473 | * reset initial number of subs for each repeater. |
| 474 | * (does not clear values) |
| 475 | */ |
| 476 | |
| 477 | |
| 478 | Wpcf7cfForm.prototype.resetRepeaters = function () { |
| 479 | var form = this; |
| 480 | form.repeaters.forEach(function (repeater) { |
| 481 | repeater.updateSubs(repeater.params.$repeater.initial_subs); |
| 482 | }); |
| 483 | }; |
| 484 | |
| 485 | Wpcf7cfForm.prototype.displayFields = function () { |
| 486 | var form = this; |
| 487 | var wpcf7cf_conditions = this.conditions; |
| 488 | var wpcf7cf_settings = this.settings; //for compatibility with contact-form-7-signature-addon |
| 489 | |
| 490 | if (cf7signature_resized === 0 && typeof signatures !== 'undefined' && signatures.constructor === Array && signatures.length > 0) { |
| 491 | for (var i = 0; i < signatures.length; i++) { |
| 492 | if (signatures[i].canvas.width === 0) { |
| 493 | var $sig_canvas = jQuery(".wpcf7-form-control-signature-body>canvas"); |
| 494 | var $sig_wrap = jQuery(".wpcf7-form-control-signature-wrap"); |
| 495 | $sig_canvas.eq(i).attr('width', $sig_wrap.width()); |
| 496 | $sig_canvas.eq(i).attr('height', $sig_wrap.height()); |
| 497 | cf7signature_resized = 1; |
| 498 | } |
| 499 | } |
| 500 | } |
| 501 | |
| 502 | form.$groups.addClass('wpcf7cf-hidden'); |
| 503 | |
| 504 | for (var _i = 0; _i < wpcf7cf_conditions.length; _i++) { |
| 505 | var condition = wpcf7cf_conditions[_i]; |
| 506 | var show_group = window.wpcf7cf.should_group_be_shown(condition, form); |
| 507 | |
| 508 | if (show_group) { |
| 509 | form.get('[data-id="' + condition.then_field + '"]').removeClass('wpcf7cf-hidden'); |
| 510 | } |
| 511 | } |
| 512 | |
| 513 | var animation_intime = wpcf7cf_settings.animation_intime; |
| 514 | var animation_outtime = wpcf7cf_settings.animation_outtime; |
| 515 | form.$groups.each(function (index) { |
| 516 | var $group = jQuery(this); |
| 517 | |
| 518 | if ($group.is(':animated')) { |
| 519 | $group.finish(); // stop any current animations on the group |
| 520 | } |
| 521 | |
| 522 | if ($group.css('display') === 'none' && !$group.hasClass('wpcf7cf-hidden')) { |
| 523 | if ($group.prop('tagName') === 'SPAN') { |
| 524 | $group.show().trigger('wpcf7cf_show_group'); // show instantly |
| 525 | } else { |
| 526 | $group.animate(wpcf7cf_show_animation, animation_intime).trigger('wpcf7cf_show_group'); // show with animation |
| 527 | } |
| 528 | |
| 529 | if ($group.attr('data-disable_on_hide') !== undefined) { |
| 530 | $group.find(':input').prop('disabled', false).trigger('changedisabledprop.wpcf7cf'); |
| 531 | $group.find('.wpcf7-form-control-wrap').removeClass('wpcf7cf-disabled'); |
| 532 | } |
| 533 | } else if ($group.css('display') !== 'none' && $group.hasClass('wpcf7cf-hidden')) { |
| 534 | if ($group.attr('data-clear_on_hide') !== undefined) { |
| 535 | var $inputs = jQuery(':input', $group).not(':button, :submit, :reset, :hidden'); |
| 536 | $inputs.each(function () { |
| 537 | var $this = jQuery(this); |
| 538 | $this.val(this.defaultValue); |
| 539 | $this.prop('checked', this.defaultChecked); |
| 540 | }); |
| 541 | jQuery('option', $group).each(function () { |
| 542 | this.selected = this.defaultSelected; |
| 543 | }); |
| 544 | jQuery('select', $group).each(function () { |
| 545 | var $select = jQuery(this); |
| 546 | |
| 547 | if ($select.val() === null) { |
| 548 | $select.val(jQuery("option:first", $select).val()); |
| 549 | } |
| 550 | }); |
| 551 | $inputs.each(function () { |
| 552 | this.dispatchEvent(new Event("change", { |
| 553 | "bubbles": true |
| 554 | })); |
| 555 | }); |
| 556 | } |
| 557 | |
| 558 | if ($group.prop('tagName') === 'SPAN') { |
| 559 | $group.hide().trigger('wpcf7cf_hide_group'); |
| 560 | } else { |
| 561 | $group.animate(wpcf7cf_hide_animation, animation_outtime).trigger('wpcf7cf_hide_group'); // hide |
| 562 | } |
| 563 | } |
| 564 | }); |
| 565 | form.updateHiddenFields(); |
| 566 | form.updateSummaryFields(); |
| 567 | }; |
| 568 | |
| 569 | Wpcf7cfForm.prototype.updateSummaryFields = function () { |
| 570 | var form = this; |
| 571 | var $summary = form.get('.wpcf7cf-summary'); |
| 572 | |
| 573 | if ($summary.length == 0 || !$summary.is(':visible')) { |
| 574 | return; |
| 575 | } |
| 576 | |
| 577 | var fd = new FormData(); |
| 578 | var formdata = form.$form.serializeArray(); |
| 579 | jQuery.each(formdata, function (key, input) { |
| 580 | fd.append(input.name, input.value); |
| 581 | }); // Make sure to add file fields to FormData |
| 582 | |
| 583 | jQuery.each(form.$form.find('input[type="file"]'), function (index, el) { |
| 584 | if (!el.files.length) return true; // continue |
| 585 | |
| 586 | var fieldName = el.name; |
| 587 | fd.append(fieldName, new Blob(), Array.from(el.files).map(function (file) { |
| 588 | return file.name; |
| 589 | }).join(', ')); |
| 590 | }); // add file fields to form-data |
| 591 | |
| 592 | jQuery.ajax({ |
| 593 | url: wpcf7cf_global_settings.ajaxurl + '?action=wpcf7cf_get_summary', |
| 594 | type: 'POST', |
| 595 | data: fd, |
| 596 | processData: false, |
| 597 | contentType: false, |
| 598 | dataType: 'json', |
| 599 | success: function success(json) { |
| 600 | $summary.html(json.summaryHtml); |
| 601 | } |
| 602 | }); |
| 603 | }; |
| 604 | |
| 605 | Wpcf7cfForm.prototype.updateHiddenFields = function () { |
| 606 | var form = this; |
| 607 | var hidden_fields = []; |
| 608 | var hidden_groups = []; |
| 609 | var visible_groups = []; |
| 610 | form.$groups.each(function () { |
| 611 | var $group = jQuery(this); |
| 612 | |
| 613 | if ($group.hasClass('wpcf7cf-hidden')) { |
| 614 | hidden_groups.push($group.attr('data-id')); |
| 615 | |
| 616 | if ($group.attr('data-disable_on_hide') !== undefined) { |
| 617 | // fields inside hidden disable_on_hide group |
| 618 | $group.find('input,select,textarea').each(function () { |
| 619 | var $this = jQuery(this); |
| 620 | |
| 621 | if (!$this.prop('disabled')) { |
| 622 | $this.prop('disabled', true).trigger('changedisabledprop.wpcf7cf'); |
| 623 | } // if there's no other field with the same name visible in the form |
| 624 | // then push this field to hidden_fields |
| 625 | |
| 626 | |
| 627 | if (form.$form.find("[data-class=\"wpcf7cf_group\"]:not(.wpcf7cf-hidden) [name='".concat($this.attr('name'), "']")).length === 0) { |
| 628 | hidden_fields.push($this.attr('name')); |
| 629 | } |
| 630 | }); |
| 631 | $group.find('.wpcf7-form-control-wrap').addClass('wpcf7cf-disabled'); |
| 632 | } else { |
| 633 | // fields inside regular hidden group are all pushed to hidden_fields |
| 634 | $group.find('input,select,textarea').each(function () { |
| 635 | hidden_fields.push(jQuery(this).attr('name')); |
| 636 | }); |
| 637 | } |
| 638 | } else { |
| 639 | visible_groups.push($group.attr('data-id')); |
| 640 | } |
| 641 | }); |
| 642 | form.hidden_fields = hidden_fields; |
| 643 | form.hidden_groups = hidden_groups; |
| 644 | form.visible_groups = visible_groups; |
| 645 | form.$input_hidden_group_fields.val(JSON.stringify(hidden_fields)); |
| 646 | form.$input_hidden_groups.val(JSON.stringify(hidden_groups)); |
| 647 | form.$input_visible_groups.val(JSON.stringify(visible_groups)); |
| 648 | return true; |
| 649 | }; |
| 650 | |
| 651 | Wpcf7cfForm.prototype.updateGroups = function () { |
| 652 | var form = this; |
| 653 | form.$groups = form.$form.find('[data-class="wpcf7cf_group"]'); |
| 654 | form.$groups.height('auto'); |
| 655 | form.conditions = window.wpcf7cf.get_nested_conditions(form); |
| 656 | }; |
| 657 | |
| 658 | Wpcf7cfForm.prototype.updateEventListeners = function () { |
| 659 | var form = this; // monitor input changes, and call displayFields() if something has changed |
| 660 | |
| 661 | form.get('input, select, textarea, button').not('.wpcf7cf_add, .wpcf7cf_remove').off(wpcf7cf_change_events).on(wpcf7cf_change_events, form, function (e) { |
| 662 | var form = e.data; |
| 663 | clearTimeout(wpcf7cf_timeout); |
| 664 | wpcf7cf_timeout = setTimeout(function () { |
| 665 | window.wpcf7cf.updateMultistepState(form.multistep); |
| 666 | form.updateSimpleDom(); |
| 667 | form.displayFields(); |
| 668 | }, wpcf7cf_change_time_ms); |
| 669 | }); // PRO ONLY |
| 670 | |
| 671 | form.get('.wpcf7cf-togglebutton').off('click.toggle_wpcf7cf').on('click.toggle_wpcf7cf', function () { |
| 672 | var $this = jQuery(this); |
| 673 | |
| 674 | if ($this.text() === $this.attr('data-val-1')) { |
| 675 | $this.text($this.attr('data-val-2')); |
| 676 | $this.val($this.attr('data-val-2')); |
| 677 | } else { |
| 678 | $this.text($this.attr('data-val-1')); |
| 679 | $this.val($this.attr('data-val-1')); |
| 680 | } |
| 681 | }); // END PRO ONLY |
| 682 | }; // PRO ONLY |
| 683 | |
| 684 | |
| 685 | function Wpcf7cfRepeater($repeater, form) { |
| 686 | var $ = jQuery; |
| 687 | var thisRepeater = this; |
| 688 | var wpcf7cf_settings = form.settings; |
| 689 | thisRepeater.form = form; |
| 690 | $repeater.parentRepeaters = Array.from($repeater.parents('.wpcf7cf_repeater').map(function () { |
| 691 | return this.getAttribute('data-id'); |
| 692 | })).reverse(); |
| 693 | $repeater.num_subs = 0; |
| 694 | $repeater.id = $repeater.attr('data-id'); |
| 695 | $repeater.orig_id = $repeater.attr('data-orig_data_id'); |
| 696 | $repeater.min = typeof $repeater.attr('data-min') !== 'undefined' ? parseInt($repeater.attr('data-min')) : 1; |
| 697 | $repeater.max = typeof $repeater.attr('data-max') !== 'undefined' ? parseInt($repeater.attr('data-max')) : 200; |
| 698 | $repeater.initial_subs = typeof $repeater.attr('data-initial') !== 'undefined' ? parseInt($repeater.attr('data-initial')) : $repeater.min; |
| 699 | |
| 700 | if ($repeater.initial_subs > $repeater.max) { |
| 701 | $repeater.initial_subs = $repeater.max; |
| 702 | } |
| 703 | |
| 704 | var $repeater_sub = $repeater.children('.wpcf7cf_repeater_sub').eq(0); |
| 705 | var $repeater_controls = $repeater.children('.wpcf7cf_repeater_controls').eq(0); |
| 706 | var $repeater_sub_clone = $repeater_sub.clone(); |
| 707 | $repeater_sub_clone.find('.wpcf7cf_repeater_sub').addBack('.wpcf7cf_repeater_sub').each(function () { |
| 708 | var $this = jQuery(this); |
| 709 | var prev_suffix = $this.attr('data-repeater_sub_suffix'); |
| 710 | var new_suffix = prev_suffix + '__{{repeater_sub_suffix}}'; |
| 711 | $this.attr('data-repeater_sub_suffix', new_suffix); |
| 712 | }); |
| 713 | $repeater_sub_clone.find('[name]').each(function () { |
| 714 | var $this = jQuery(this); |
| 715 | var prev_name = $this.attr('name'); |
| 716 | var new_name = thisRepeater.getNewName(prev_name); |
| 717 | var orig_name = $this.attr('data-orig_name') != null ? $this.attr('data-orig_name') : prev_name; |
| 718 | $this.attr('name', new_name); |
| 719 | $this.attr('data-orig_name', orig_name); |
| 720 | $this.closest('.wpcf7-form-control-wrap').attr('data-name', new_name.replace('[]', '')); |
| 721 | }); |
| 722 | $repeater_sub_clone.find('.wpcf7cf_repeater,[data-class="wpcf7cf_group"]').each(function () { |
| 723 | var $this = jQuery(this); |
| 724 | var prev_data_id = $this.attr('data-id'); |
| 725 | var orig_data_id = $this.attr('data-orig_data_id') != null ? $this.attr('data-orig_data_id') : prev_data_id; |
| 726 | var new_data_id = thisRepeater.getNewName(prev_data_id); |
| 727 | |
| 728 | if (prev_data_id.endsWith('_count')) { |
| 729 | new_data_id = prev_data_id.replace('_count', '__{{repeater_sub_suffix}}_count'); |
| 730 | } |
| 731 | |
| 732 | $this.attr('data-id', new_data_id); |
| 733 | $this.attr('data-orig_data_id', orig_data_id); |
| 734 | }); |
| 735 | $repeater_sub_clone.find('[id]').each(function () { |
| 736 | var $this = jQuery(this); |
| 737 | var prev_id = $this.attr('id'); |
| 738 | var orig_id = $this.attr('data-orig_id') != null ? $this.attr('data-orig_id') : prev_id; |
| 739 | var new_id = thisRepeater.getNewName(prev_id); |
| 740 | $this.attr('id', new_id); |
| 741 | $this.attr('data-orig_id', orig_id); |
| 742 | }); |
| 743 | $repeater_sub_clone.find('[for]').each(function () { |
| 744 | var $this = jQuery(this); |
| 745 | var prev_for = $this.attr('for'); |
| 746 | var orig_for = $this.attr('data-orig_for') != null ? $this.attr('data-orig_for') : prev_for; |
| 747 | var new_for = thisRepeater.getNewName(prev_for); |
| 748 | $this.attr('for', new_for); |
| 749 | $this.attr('data-orig_for', orig_for); |
| 750 | }); |
| 751 | var repeater_sub_html = $repeater_sub_clone[0].outerHTML; |
| 752 | var $repeater_count_field = $repeater.find('[name=' + $repeater.id + '_count]').eq(0); |
| 753 | var $button_add = $repeater_controls.find('.wpcf7cf_add').eq(0); |
| 754 | var $button_remove = $repeater_controls.find('.wpcf7cf_remove').eq(0); |
| 755 | var params = { |
| 756 | $repeater: $repeater, |
| 757 | $repeater_count_field: $repeater_count_field, |
| 758 | repeater_sub_html: repeater_sub_html, |
| 759 | $repeater_controls: $repeater_controls, |
| 760 | $button_add: $button_add, |
| 761 | $button_remove: $button_remove, |
| 762 | wpcf7cf_settings: wpcf7cf_settings |
| 763 | }; |
| 764 | thisRepeater.params = params; |
| 765 | $button_add.on('click', null, thisRepeater, function (e) { |
| 766 | thisRepeater = e.data; |
| 767 | thisRepeater.updateSubs(params.$repeater.num_subs + 1); |
| 768 | }); |
| 769 | $button_remove.on('click', null, thisRepeater, function (e) { |
| 770 | thisRepeater = e.data; |
| 771 | thisRepeater.updateSubs(params.$repeater.num_subs - 1); |
| 772 | }); |
| 773 | jQuery('> .wpcf7cf_repeater_sub', params.$repeater).eq(0).remove(); // remove the first sub, it's just a template. |
| 774 | |
| 775 | thisRepeater.updateSubs($repeater.initial_subs); |
| 776 | thisRepeater.updateButtons(); |
| 777 | } |
| 778 | |
| 779 | Wpcf7cfRepeater.prototype.getNewName = function (previousName) { |
| 780 | var prev_parts = previousName.split('['); |
| 781 | previousName = prev_parts[0]; |
| 782 | var prev_suff = prev_parts.length > 1 ? '[' + prev_parts.splice(1).join('[') : ''; |
| 783 | var newName = previousName + '__{{repeater_sub_suffix}}' + prev_suff; |
| 784 | |
| 785 | if (previousName.endsWith('_count')) { |
| 786 | newName = previousName.replace('_count', '__{{repeater_sub_suffix}}_count'); |
| 787 | } |
| 788 | |
| 789 | return newName; |
| 790 | }; |
| 791 | |
| 792 | Wpcf7cfRepeater.prototype.updateButtons = function () { |
| 793 | var repeater = this; |
| 794 | var params = repeater.params; |
| 795 | var num_subs = params.$repeater.num_subs; |
| 796 | var showButtonRemove = false; |
| 797 | var showButtonAdd = false; |
| 798 | |
| 799 | if (params.$repeater.num_subs < params.$repeater.max) { |
| 800 | showButtonAdd = true; |
| 801 | } |
| 802 | |
| 803 | if (params.$repeater.num_subs > params.$repeater.min) { |
| 804 | showButtonRemove = true; |
| 805 | } |
| 806 | |
| 807 | if (showButtonAdd) { |
| 808 | params.$button_add.show(); |
| 809 | } else { |
| 810 | params.$button_add.hide(); |
| 811 | } |
| 812 | |
| 813 | if (showButtonRemove) { |
| 814 | params.$button_remove.show(); |
| 815 | } else { |
| 816 | params.$button_remove.hide(); |
| 817 | } |
| 818 | |
| 819 | params.$repeater_count_field.val(num_subs); |
| 820 | }; |
| 821 | |
| 822 | Wpcf7cfRepeater.prototype.updateSubs = function (subs_to_show) { |
| 823 | var repeater = this; |
| 824 | var params = repeater.params; // make sure subs_to_show is a valid number |
| 825 | |
| 826 | subs_to_show = subs_to_show < params.$repeater.min ? params.$repeater.min : subs_to_show; |
| 827 | subs_to_show = subs_to_show > params.$repeater.max ? params.$repeater.max : subs_to_show; |
| 828 | var subs_to_add = subs_to_show - params.$repeater.num_subs; |
| 829 | |
| 830 | if (subs_to_add < 0) { |
| 831 | repeater.removeSubs(-subs_to_add); |
| 832 | } else if (subs_to_add > 0) { |
| 833 | repeater.addSubs(subs_to_add); |
| 834 | } |
| 835 | }; |
| 836 | /** |
| 837 | * add Subs to repeater |
| 838 | * @param {Number} subs_to_add |
| 839 | * @param {Number} index - zero-based. leave blank (or null) to append at the end |
| 840 | */ |
| 841 | |
| 842 | |
| 843 | Wpcf7cfRepeater.prototype.addSubs = function (subs_to_add) { |
| 844 | var index = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; |
| 845 | var $ = jQuery; |
| 846 | var params = this.params; |
| 847 | var repeater = this; |
| 848 | var form = repeater.form; |
| 849 | var $repeater = params.$repeater; |
| 850 | var $repeater_controls = params.$repeater_controls; |
| 851 | |
| 852 | if (subs_to_add + $repeater.num_subs > $repeater.max) { |
| 853 | subs_to_add = $repeater.max - $repeater.num_subs; |
| 854 | } |
| 855 | |
| 856 | var html_str = ''; |
| 857 | |
| 858 | for (var i = 1; i <= subs_to_add; i++) { |
| 859 | var sub_suffix = $repeater.num_subs + i; |
| 860 | html_str += params.repeater_sub_html.replace(/\{\{repeater_sub_suffix\}\}/g, sub_suffix).replace(new RegExp('\{\{' + $repeater.orig_id + '_index\}\}', 'g'), '<span class="wpcf7cf-index wpcf7cf__' + $repeater.orig_id + '">' + sub_suffix + '</span>'); |
| 861 | } |
| 862 | |
| 863 | var $html = $(html_str); |
| 864 | $('> .wpcf7cf_repeater_sub', $repeater).finish(); // finish any currently running animations immediately. |
| 865 | // Add the newly created fields to the form |
| 866 | |
| 867 | if (index === null) { |
| 868 | $html.hide().insertBefore($repeater_controls).animate(wpcf7cf_show_animation, params.wpcf7cf_settings.animation_intime).trigger('wpcf7cf_repeater_added'); |
| 869 | } else { |
| 870 | $html.hide().insertBefore($('> .wpcf7cf_repeater_sub', $repeater).eq(index)).animate(wpcf7cf_show_animation, params.wpcf7cf_settings.animation_intime).trigger('wpcf7cf_repeater_added'); |
| 871 | } // enable all new fields |
| 872 | |
| 873 | |
| 874 | $html.find('.wpcf7cf-disabled :input').prop('disabled', false).trigger('changedisabledprop.wpcf7cf'); |
| 875 | $html.find('.wpcf7-form-control-wrap').removeClass('wpcf7cf-disabled'); |
| 876 | $('.wpcf7cf_repeater', $html).each(function () { |
| 877 | form.repeaters.push(new Wpcf7cfRepeater($(this), form)); |
| 878 | }); |
| 879 | form.$input_repeaters.val(JSON.stringify(form.repeaters.map(function (item) { |
| 880 | return item.params.$repeater.id; |
| 881 | }))); |
| 882 | $repeater.num_subs += subs_to_add; |
| 883 | |
| 884 | if (index !== null) { |
| 885 | repeater.updateSuffixes(); |
| 886 | } |
| 887 | |
| 888 | window.wpcf7cf.updateMultistepState(form.multistep); |
| 889 | form.updateGroups(); |
| 890 | form.updateEventListeners(); |
| 891 | form.displayFields(); |
| 892 | repeater.updateButtons(); // Exclusive Checkbox |
| 893 | |
| 894 | $html.on('click', '.wpcf7-exclusive-checkbox input:checkbox', function () { |
| 895 | var name = $(this).attr('name'); |
| 896 | $html.find('input:checkbox[name="' + name + '"]').not(this).prop('checked', false); |
| 897 | }); //basic compatibility with material-design-for-contact-form-7 |
| 898 | |
| 899 | if (typeof window.cf7mdInit === "function") { |
| 900 | window.cf7mdInit(); |
| 901 | } |
| 902 | |
| 903 | return false; |
| 904 | }; |
| 905 | |
| 906 | Wpcf7cfRepeater.prototype.updateSuffixes = function () { |
| 907 | // Loop trough all subs |
| 908 | // -- 1. update all fields, groups and repeaters names, id's, for's, ... |
| 909 | // -- 2. loop trough all repeaters |
| 910 | // -- update sub_html template for nested repeater |
| 911 | // -- call updateSuffixes() for nested repeater |
| 912 | var $repeater = this.params.$repeater; |
| 913 | var num_subs = this.params.$repeater.num_subs; |
| 914 | var form = this.form; |
| 915 | var orig_id = $repeater.attr('data-orig_data_id'); |
| 916 | var repeater_id = $repeater.attr('data-id'); |
| 917 | var repeater_suffix = repeater_id.replace(orig_id, ''); |
| 918 | var simplifiedDomArray = Object.values(wpcf7cf.get_simplified_dom_model(form.$form[0])); |
| 919 | |
| 920 | var _loop = function _loop(i) { |
| 921 | var $sub = jQuery('> .wpcf7cf_repeater_sub', $repeater).eq(i); |
| 922 | var newIndex = i + 1; |
| 923 | var currentSuffix = $sub.attr('data-repeater_sub_suffix'); |
| 924 | var newSuffix = repeater_suffix + '__' + newIndex; |
| 925 | $sub.attr('data-repeater_sub_suffix', newSuffix); // update sub attr |
| 926 | |
| 927 | $sub.find('.wpcf7cf__' + orig_id).html(newIndex); // update {{r_index}} parts |
| 928 | |
| 929 | simplifiedDomArray.forEach(function (el) { |
| 930 | if (el.suffix !== currentSuffix) return; // TODO: may need an extra check to verify that the element is inside the current repeater |
| 931 | // (orig_id) . Otherwise problems may occur if there are repeaters on the same level. |
| 932 | |
| 933 | var newName = el.name.replace(currentSuffix, newSuffix); |
| 934 | var pureElName = el.name.replace('[]', ''); |
| 935 | var pureNewName = newName.replace('[]', ''); |
| 936 | jQuery('[name="' + el.name + '"]', $sub).attr('name', newName); |
| 937 | jQuery('[id="' + el.name + '"]', $sub).attr('id', newName); |
| 938 | jQuery('label[for="' + el.name + '"]', $sub).attr('for', newName); |
| 939 | var $nested_repeater = jQuery('[data-id="' + el.name + '"]', $sub); |
| 940 | $nested_repeater.attr('data-id', newName); |
| 941 | jQuery(".wpcf7-form-control-wrap[data-name=\"".concat(pureElName, "\"]"), $sub).attr('data-name', pureNewName); |
| 942 | |
| 943 | if (el.type === 'repeater') { |
| 944 | var nested_repeater = form.repeaters.find(function (repeater) { |
| 945 | return repeater.params.$repeater.get(0) === $nested_repeater.get(0); |
| 946 | }); |
| 947 | if (!nested_repeater) return; |
| 948 | nested_repeater.params.repeater_sub_html = wpcf7cf.updateRepeaterSubHTML(nested_repeater.params.repeater_sub_html, currentSuffix, newSuffix, nested_repeater.params.$repeater.parentRepeaters); |
| 949 | nested_repeater.updateSuffixes(); |
| 950 | } |
| 951 | }); |
| 952 | }; |
| 953 | |
| 954 | for (var i = 0; i < num_subs; i++) { |
| 955 | _loop(i); |
| 956 | } |
| 957 | }; |
| 958 | /** |
| 959 | * Return the parent repeaters, order is not guaranteed. |
| 960 | */ |
| 961 | |
| 962 | |
| 963 | Wpcf7cfRepeater.prototype.getParentRepeaters = function () { |
| 964 | var simplifiedDomArray = Object.values(wpcf7cf.get_simplified_dom_model(form.$form[0])); |
| 965 | form.repeaters.map(function (repeater) {}); |
| 966 | }; |
| 967 | |
| 968 | Wpcf7cfRepeater.prototype.removeSubs = function (subs_to_remove) { |
| 969 | var index = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; |
| 970 | var $ = jQuery; |
| 971 | var repeater = this; |
| 972 | var params = repeater.params; |
| 973 | var form = repeater.form; |
| 974 | var $repeater = params.$repeater; |
| 975 | |
| 976 | if ($repeater.num_subs - subs_to_remove < $repeater.min) { |
| 977 | subs_to_remove = $repeater.num_subs - $repeater.min; |
| 978 | } |
| 979 | |
| 980 | if (index === null) { |
| 981 | index = $repeater.num_subs - subs_to_remove; |
| 982 | } |
| 983 | |
| 984 | $repeater.num_subs -= subs_to_remove; |
| 985 | jQuery('> .wpcf7cf_repeater_sub', $repeater).finish(); // finish any currently running animations immediately. |
| 986 | |
| 987 | jQuery('> .wpcf7cf_repeater_sub', $repeater).slice(index, index + subs_to_remove).animate(wpcf7cf_hide_animation, { |
| 988 | duration: params.wpcf7cf_settings.animation_intime, |
| 989 | done: function done() { |
| 990 | var $this = jQuery(this); //remove the actual fields from the form |
| 991 | |
| 992 | $this.remove(); |
| 993 | params.$repeater.trigger('wpcf7cf_repeater_removed'); |
| 994 | window.wpcf7cf.updateMultistepState(form.multistep); |
| 995 | form.updateGroups(); |
| 996 | form.updateEventListeners(); |
| 997 | form.displayFields(); |
| 998 | repeater.updateButtons(); |
| 999 | |
| 1000 | if (index !== null) { |
| 1001 | repeater.updateSuffixes(); |
| 1002 | } |
| 1003 | } |
| 1004 | }); |
| 1005 | return false; |
| 1006 | }; |
| 1007 | |
| 1008 | function Wpcf7cfMultistep($multistep, form) { |
| 1009 | var multistep = this; |
| 1010 | multistep.$multistep = $multistep; |
| 1011 | multistep.form = form; |
| 1012 | multistep.$steps = $multistep.find('.wpcf7cf_step'); |
| 1013 | multistep.$btn_next = $multistep.find('.wpcf7cf_next'); |
| 1014 | multistep.$btn_prev = $multistep.find('.wpcf7cf_prev'); |
| 1015 | multistep.$dots = $multistep.find('.wpcf7cf_steps-dots'); |
| 1016 | multistep.currentStep = 0; |
| 1017 | multistep.numSteps = multistep.$steps.length; |
| 1018 | multistep.$dots.html(''); |
| 1019 | |
| 1020 | for (var i = 1; i <= multistep.numSteps; i++) { |
| 1021 | multistep.$dots.append("\n <div class=\"dot\" data-step=\"".concat(i, "\">\n <div class=\"step-index\">").concat(i, "</div>\n <div class=\"step-title\">").concat(multistep.$steps.eq(i - 1).attr('data-title'), "</div>\n </div>\n ")); |
| 1022 | } |
| 1023 | |
| 1024 | multistep.$btn_next.on('click.wpcf7cf_step', /*#__PURE__*/_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_3___default()( /*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default.a.mark(function _callee() { |
| 1025 | var result; |
| 1026 | return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default.a.wrap(function _callee$(_context) { |
| 1027 | while (1) { |
| 1028 | switch (_context.prev = _context.next) { |
| 1029 | case 0: |
| 1030 | multistep.$btn_next.addClass('disabled').attr('disabled', true); |
| 1031 | multistep.form.$form.addClass('submitting'); |
| 1032 | _context.next = 4; |
| 1033 | return multistep.validateStep(multistep.currentStep); |
| 1034 | |
| 1035 | case 4: |
| 1036 | result = _context.sent; |
| 1037 | multistep.form.$form.removeClass('submitting'); |
| 1038 | |
| 1039 | if (result === 'success') { |
| 1040 | multistep.moveToStep(multistep.currentStep + 1); |
| 1041 | } |
| 1042 | |
| 1043 | case 7: |
| 1044 | case "end": |
| 1045 | return _context.stop(); |
| 1046 | } |
| 1047 | } |
| 1048 | }, _callee); |
| 1049 | }))); // If form is submitted (by pressing Enter for example), and if we are not on the last step, |
| 1050 | // then trigger click event on the $btn_next button instead. |
| 1051 | |
| 1052 | multistep.form.$form.on('submit.wpcf7cf_step', function (e) { |
| 1053 | if (multistep.currentStep !== multistep.numSteps) { |
| 1054 | multistep.$btn_next.trigger('click.wpcf7cf_step'); |
| 1055 | e.stopImmediatePropagation(); |
| 1056 | return false; |
| 1057 | } |
| 1058 | }); |
| 1059 | multistep.$btn_prev.on('click', function () { |
| 1060 | multistep.moveToStep(multistep.currentStep - 1); |
| 1061 | }); |
| 1062 | multistep.moveToStep(1); |
| 1063 | } |
| 1064 | |
| 1065 | Wpcf7cfMultistep.prototype.validateStep = function (step_index) { |
| 1066 | var multistep = this; |
| 1067 | var $multistep = multistep.$multistep; |
| 1068 | var $form = multistep.form.$form; |
| 1069 | var form = multistep.form; |
| 1070 | $form.find('.wpcf7-response-output').addClass('wpcf7-display-none'); |
| 1071 | return new Promise(function (resolve) { |
| 1072 | var fd = new FormData(); // Make sure to add file fields to FormData |
| 1073 | |
| 1074 | jQuery.each($form.find('[data-id="step-' + step_index + '"] input[type="file"]'), function (index, el) { |
| 1075 | if (!el.files.length) return true; // = continue |
| 1076 | |
| 1077 | var file = el.files[0]; |
| 1078 | var fieldName = el.name; |
| 1079 | fd.append(fieldName, file); |
| 1080 | }); |
| 1081 | var formdata = $form.serializeArray(); |
| 1082 | jQuery.each(formdata, function (key, input) { |
| 1083 | fd.append(input.name, input.value); |
| 1084 | }); |
| 1085 | jQuery.ajax({ |
| 1086 | url: wpcf7cf_global_settings.ajaxurl + '?action=wpcf7cf_validate_step', |
| 1087 | type: 'POST', |
| 1088 | data: fd, |
| 1089 | processData: false, |
| 1090 | contentType: false, |
| 1091 | dataType: 'json' |
| 1092 | }).done(function (json) { |
| 1093 | $multistep.find('.wpcf7-form-control-wrap .wpcf7-not-valid-tip').remove(); |
| 1094 | $multistep.find('.wpcf7-not-valid').removeClass('wpcf7-not-valid'); |
| 1095 | $multistep.find('.wpcf7-response-output').remove(); |
| 1096 | $multistep.find('.wpcf7-response-output.wpcf7-validation-errors').removeClass('wpcf7-validation-errors'); |
| 1097 | multistep.$btn_next.removeClass('disabled').attr('disabled', false); |
| 1098 | |
| 1099 | if (!json.success) { |
| 1100 | var checkError = 0; |
| 1101 | jQuery.each(json.invalid_fields, function (index, el) { |
| 1102 | if ($multistep.find('input[name="' + index + '"]').length || $multistep.find('input[name="' + index + '[]"]').length || $multistep.find('select[name="' + index + '"]').length || $multistep.find('select[name="' + index + '[]"]').length || $multistep.find('textarea[name="' + index + '"]').length || $multistep.find('textarea[name="' + index + '[]"]').length) { |
| 1103 | checkError = checkError + 1; |
| 1104 | var controlWrap = form.get(".wpcf7-form-control-wrap[data-name=\"".concat(index, "\"]")); |
| 1105 | controlWrap.find('.wpcf7-form-control').addClass('wpcf7-not-valid'); |
| 1106 | controlWrap.find('span.wpcf7-not-valid-tip').remove(); |
| 1107 | controlWrap.append('<span role="alert" class="wpcf7-not-valid-tip">' + el.reason + '</span>'); |
| 1108 | } |
| 1109 | }); |
| 1110 | resolve('failed'); |
| 1111 | $multistep.parent().find('.wpcf7-response-output').removeClass('wpcf7-display-none').html(json.message); |
| 1112 | wpcf7.setStatus($form, 'invalid'); |
| 1113 | multistep.$steps.trigger('wpcf7cf_step_invalid'); // wpcf7.triggerEvent( data.into, 'invalid', detail ); |
| 1114 | } else if (json.success) { |
| 1115 | wpcf7.setStatus($form, 'init'); |
| 1116 | resolve('success'); |
| 1117 | return false; |
| 1118 | } |
| 1119 | }).fail(function () { |
| 1120 | resolve('error'); |
| 1121 | }).always(function () {// do nothing |
| 1122 | }); |
| 1123 | }); |
| 1124 | }; |
| 1125 | |
| 1126 | Wpcf7cfMultistep.prototype.moveToStep = function (step_index) { |
| 1127 | var scrollToTop = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; |
| 1128 | var multistep = this; |
| 1129 | var previousStep = multistep.currentStep; |
| 1130 | multistep.currentStep = step_index > multistep.numSteps ? multistep.numSteps : step_index < 1 ? 1 : step_index; // ANIMATION DISABLED FOR NOW cause it's ugly |
| 1131 | // multistep.$steps.animate(wpcf7cf_hide_step_animation, multistep.form.settings.animation_outtime); |
| 1132 | // multistep.$steps.eq(multistep.currentStep-1).animate(wpcf7cf_show_step_animation, multistep.form.settings.animation_intime); |
| 1133 | |
| 1134 | multistep.$multistep.attr('data-current_step', multistep.currentStep); |
| 1135 | multistep.$steps.hide(); |
| 1136 | multistep.$steps.eq(multistep.currentStep - 1).show().trigger('wpcf7cf_change_step', [previousStep, multistep.currentStep]); |
| 1137 | |
| 1138 | if (scrollToTop) { |
| 1139 | var formEl = multistep.form.$form[0]; |
| 1140 | var topOffset = formEl.getBoundingClientRect().top; |
| 1141 | |
| 1142 | if (topOffset < 0 && previousStep > 0) { |
| 1143 | formEl.scrollIntoView({ |
| 1144 | behavior: "smooth" |
| 1145 | }); |
| 1146 | } |
| 1147 | } |
| 1148 | |
| 1149 | multistep.form.updateSummaryFields(); |
| 1150 | window.wpcf7cf.updateMultistepState(multistep); |
| 1151 | }; |
| 1152 | |
| 1153 | Wpcf7cfMultistep.prototype.getFieldsInStep = function (step_index) { |
| 1154 | this.form.reloadSimpleDom(); |
| 1155 | var inStep = false; |
| 1156 | return Object.values(this.form.simpleDom).filter(function (item, i) { |
| 1157 | if (item.type == 'step') { |
| 1158 | inStep = item.val == step_index + ''; |
| 1159 | } |
| 1160 | |
| 1161 | return inStep && item.type == 'input'; |
| 1162 | }).map(function (item) { |
| 1163 | return item.name; |
| 1164 | }); |
| 1165 | }; // END PRO ONLY |
| 1166 | |
| 1167 | /** |
| 1168 | * @global |
| 1169 | * @namespace wpcf7cf |
| 1170 | */ |
| 1171 | |
| 1172 | |
| 1173 | window.wpcf7cf = { |
| 1174 | hideGroup: function hideGroup($group, animate) {}, |
| 1175 | showGroup: function showGroup($group, animate) {}, |
| 1176 | updateRepeaterSubHTML: function updateRepeaterSubHTML(html, oldSuffix, newSuffix, parentRepeaters) { |
| 1177 | var oldIndexes = oldSuffix.split('__'); |
| 1178 | oldIndexes.shift(); // remove first empty element |
| 1179 | |
| 1180 | var newIndexes = newSuffix.split('__'); |
| 1181 | newIndexes.shift(); // remove first empty element |
| 1182 | |
| 1183 | var returnHtml = html; |
| 1184 | |
| 1185 | if (oldIndexes && newIndexes && oldIndexes.length === parentRepeaters.length && newIndexes.length === parentRepeaters.length) { |
| 1186 | var parentRepeatersInfo = parentRepeaters.map(function (repeaterId, i) { |
| 1187 | return _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_1___default()({}, repeaterId.split('__')[0], [oldIndexes[i], newIndexes[i]]); |
| 1188 | }); |
| 1189 | var length = parentRepeatersInfo.length; |
| 1190 | var replacements = oldIndexes.map(function (oldIndex, i) { |
| 1191 | return ['__' + oldIndexes.slice(0, length - i).join('__'), '__' + newIndexes.slice(0, length - i).join('__')]; |
| 1192 | }); |
| 1193 | |
| 1194 | for (var i = 0; i < length; i++) { |
| 1195 | var id = Object.keys(parentRepeatersInfo[i])[0]; |
| 1196 | var find = parentRepeatersInfo[i][id][0]; |
| 1197 | var repl = parentRepeatersInfo[i][id][1]; |
| 1198 | replacements.push(["<span class=\"wpcf7cf-index wpcf7cf__".concat(id, "\">").concat(find, "<\\/span>"), "<span class=\"wpcf7cf-index wpcf7cf__".concat(id, "\">").concat(repl, "</span>")]); |
| 1199 | } |
| 1200 | |
| 1201 | replacements.forEach(function (_ref3) { |
| 1202 | var _ref4 = _babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_0___default()(_ref3, 2), |
| 1203 | oldSuffix = _ref4[0], |
| 1204 | newSuffix = _ref4[1]; |
| 1205 | |
| 1206 | returnHtml = returnHtml.replace(new RegExp(oldSuffix, 'g'), newSuffix); |
| 1207 | }); |
| 1208 | } |
| 1209 | |
| 1210 | return returnHtml; |
| 1211 | }, |
| 1212 | // keep this for backwards compatibility |
| 1213 | initForm: function initForm($forms) { |
| 1214 | $forms.each(function () { |
| 1215 | var $form = jQuery(this); // only add form is its class is "wpcf7-form" and if the form was not previously added |
| 1216 | |
| 1217 | if ($form.hasClass('wpcf7-form') && !wpcf7cf_forms.some(function (form) { |
| 1218 | return form.$form.get(0) === $form.get(0); |
| 1219 | })) { |
| 1220 | wpcf7cf_forms.push(new Wpcf7cfForm($form)); |
| 1221 | } |
| 1222 | }); |
| 1223 | }, |
| 1224 | getWpcf7cfForm: function getWpcf7cfForm($form) { |
| 1225 | var matched_forms = wpcf7cf_forms.filter(function (form) { |
| 1226 | return form.$form.get(0) === $form.get(0); |
| 1227 | }); |
| 1228 | |
| 1229 | if (matched_forms.length) { |
| 1230 | return matched_forms[0]; |
| 1231 | } |
| 1232 | |
| 1233 | return false; |
| 1234 | }, |
| 1235 | get_nested_conditions: function get_nested_conditions(form) { |
| 1236 | var conditions = form.initial_conditions; //loop trough conditions. Then loop trough the dom, and each repeater we pass we should update all sub_values we encounter with __index |
| 1237 | |
| 1238 | form.reloadSimpleDom(); |
| 1239 | var groups = Object.values(form.simpleDom).filter(function (item, i) { |
| 1240 | return item.type === 'group'; |
| 1241 | }); |
| 1242 | var sub_conditions = []; |
| 1243 | |
| 1244 | var _loop2 = function _loop2(i) { |
| 1245 | var g = groups[i]; |
| 1246 | var relevant_conditions = conditions.filter(function (condition, i) { |
| 1247 | return condition.then_field === g.original_name; |
| 1248 | }); |
| 1249 | relevant_conditions = relevant_conditions.map(function (item, i) { |
| 1250 | return { |
| 1251 | then_field: g.name, |
| 1252 | and_rules: item.and_rules.map(function (and_rule, i) { |
| 1253 | return { |
| 1254 | if_field: and_rule.if_field + g.suffix, |
| 1255 | if_value: and_rule.if_value, |
| 1256 | operator: and_rule.operator |
| 1257 | }; |
| 1258 | }) |
| 1259 | }; |
| 1260 | }); |
| 1261 | sub_conditions = sub_conditions.concat(relevant_conditions); |
| 1262 | }; |
| 1263 | |
| 1264 | for (var i = 0; i < groups.length; i++) { |
| 1265 | _loop2(i); |
| 1266 | } |
| 1267 | |
| 1268 | return sub_conditions; |
| 1269 | }, |
| 1270 | get_simplified_dom_model: function get_simplified_dom_model(currentNode) { |
| 1271 | var simplified_dom = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; |
| 1272 | var parentGroups = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : []; |
| 1273 | var parentRepeaters = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : []; |
| 1274 | var type = currentNode.classList && currentNode.classList.contains('wpcf7cf_repeater') ? 'repeater' : currentNode.dataset["class"] == 'wpcf7cf_group' ? 'group' : currentNode.className == 'wpcf7cf_step' ? 'step' : currentNode.hasAttribute('name') && !currentNode.disabled ? 'input' : false; |
| 1275 | |
| 1276 | var newParentRepeaters = _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_4___default()(parentRepeaters); |
| 1277 | |
| 1278 | var newParentGroups = _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_4___default()(parentGroups); |
| 1279 | |
| 1280 | if (type) { |
| 1281 | var name = type === 'input' ? currentNode.getAttribute('name') : currentNode.dataset.id; |
| 1282 | |
| 1283 | if (type === 'repeater') { |
| 1284 | newParentRepeaters.push(name); |
| 1285 | } |
| 1286 | |
| 1287 | if (type === 'group') { |
| 1288 | newParentGroups.push(name); |
| 1289 | } // skip _wpcf7 hidden fields |
| 1290 | |
| 1291 | |
| 1292 | if (name.substring(0, 6) === '_wpcf7') return {}; |
| 1293 | var original_name = type === 'repeater' || type === 'group' ? currentNode.dataset.orig_data_id : type === 'input' ? currentNode.getAttribute('data-orig_name') || name : name; |
| 1294 | var nameWithoutBrackets = name.replace('[]', ''); |
| 1295 | var originalNameWithoutBrackets = original_name.replace('[]', ''); |
| 1296 | var val = type === 'step' ? [currentNode.dataset.id.substring(5)] : []; |
| 1297 | var suffix = nameWithoutBrackets.replace(originalNameWithoutBrackets, ''); |
| 1298 | |
| 1299 | if (!simplified_dom[name]) { |
| 1300 | // init entry |
| 1301 | simplified_dom[name] = { |
| 1302 | name: name, |
| 1303 | type: type, |
| 1304 | original_name: original_name, |
| 1305 | suffix: suffix, |
| 1306 | val: val, |
| 1307 | parentGroups: parentGroups, |
| 1308 | parentRepeaters: parentRepeaters |
| 1309 | }; |
| 1310 | } |
| 1311 | |
| 1312 | if (type === 'input') { |
| 1313 | // skip unchecked checkboxes and radiobuttons |
| 1314 | if ((currentNode.type === 'checkbox' || currentNode.type === 'radio') && !currentNode.checked) return {}; // if multiselect, make sure to add all the values |
| 1315 | |
| 1316 | if (currentNode.multiple && currentNode.options) { |
| 1317 | simplified_dom[name].val = Object.values(currentNode.options).filter(function (o) { |
| 1318 | return o.selected; |
| 1319 | }).map(function (o) { |
| 1320 | return o.value; |
| 1321 | }); |
| 1322 | } else { |
| 1323 | simplified_dom[name].val.push(currentNode.value); |
| 1324 | } |
| 1325 | } |
| 1326 | } // can't use currentNode.children (because then field name cannot be "children") |
| 1327 | |
| 1328 | |
| 1329 | var getter = Object.getOwnPropertyDescriptor(Element.prototype, "children").get; |
| 1330 | var children = getter.call(currentNode); |
| 1331 | Array.from(children).forEach(function (childNode) { |
| 1332 | var dom = wpcf7cf.get_simplified_dom_model(childNode, simplified_dom, newParentGroups, newParentRepeaters); |
| 1333 | simplified_dom = _objectSpread(_objectSpread({}, dom), simplified_dom); |
| 1334 | }); |
| 1335 | return simplified_dom; |
| 1336 | }, |
| 1337 | updateMultistepState: function updateMultistepState(multistep) { |
| 1338 | if (multistep == null) return; // update hidden input field |
| 1339 | |
| 1340 | var stepsData = { |
| 1341 | currentStep: multistep.currentStep, |
| 1342 | numSteps: multistep.numSteps, |
| 1343 | fieldsInCurrentStep: multistep.getFieldsInStep(multistep.currentStep) |
| 1344 | }; |
| 1345 | multistep.form.$input_steps.val(JSON.stringify(stepsData)); // update Buttons |
| 1346 | |
| 1347 | multistep.$btn_prev.removeClass('disabled').attr('disabled', false); |
| 1348 | multistep.$btn_next.removeClass('disabled').attr('disabled', false); |
| 1349 | |
| 1350 | if (multistep.currentStep == multistep.numSteps) { |
| 1351 | multistep.$btn_next.addClass('disabled').attr('disabled', true); |
| 1352 | } |
| 1353 | |
| 1354 | if (multistep.currentStep == 1) { |
| 1355 | multistep.$btn_prev.addClass('disabled').attr('disabled', true); |
| 1356 | } // replace next button with submit button on last step. |
| 1357 | // TODO: make this depend on a setting |
| 1358 | |
| 1359 | |
| 1360 | var $submit_button = multistep.form.$form.find('input[type="submit"]:last').eq(0); |
| 1361 | var $ajax_loader = multistep.form.$form.find('.wpcf7-spinner').eq(0); |
| 1362 | $submit_button.detach().prependTo(multistep.$btn_next.parent()); |
| 1363 | $ajax_loader.detach().prependTo(multistep.$btn_next.parent()); |
| 1364 | |
| 1365 | if (multistep.currentStep == multistep.numSteps) { |
| 1366 | multistep.$btn_next.hide(); |
| 1367 | $submit_button.show(); |
| 1368 | } else { |
| 1369 | $submit_button.hide(); |
| 1370 | multistep.$btn_next.show(); |
| 1371 | } // update dots |
| 1372 | |
| 1373 | |
| 1374 | var $dots = multistep.$dots.find('.dot'); |
| 1375 | $dots.removeClass('active').removeClass('completed'); |
| 1376 | |
| 1377 | for (var step = 1; step <= multistep.numSteps; step++) { |
| 1378 | if (step < multistep.currentStep) { |
| 1379 | $dots.eq(step - 1).addClass('completed'); |
| 1380 | } else if (step == multistep.currentStep) { |
| 1381 | $dots.eq(step - 1).addClass('active'); |
| 1382 | } |
| 1383 | } |
| 1384 | }, |
| 1385 | should_group_be_shown: function should_group_be_shown(condition, form) { |
| 1386 | var show_group = true; |
| 1387 | |
| 1388 | for (var and_rule_i = 0; and_rule_i < condition.and_rules.length; and_rule_i++) { |
| 1389 | var condition_ok = false; |
| 1390 | var condition_and_rule = condition.and_rules[and_rule_i]; |
| 1391 | var inputField = form.getFieldByName(condition_and_rule.if_field); |
| 1392 | if (!inputField) continue; // field not found |
| 1393 | |
| 1394 | var if_val = condition_and_rule.if_value; |
| 1395 | var operator = condition_and_rule.operator; //backwards compat |
| 1396 | |
| 1397 | operator = operator === '≤' ? 'less than or equals' : operator; |
| 1398 | operator = operator === '≥' ? 'greater than or equals' : operator; |
| 1399 | operator = operator === '>' ? 'greater than' : operator; |
| 1400 | operator = operator === '<' ? 'less than' : operator; |
| 1401 | var $field = operator === 'function' && jQuery("[name=\"".concat(inputField.name, "\"]")).eq(0); |
| 1402 | condition_ok = this.isConditionTrue(inputField.val, operator, if_val, $field); |
| 1403 | show_group = show_group && condition_ok; |
| 1404 | } |
| 1405 | |
| 1406 | return show_group; |
| 1407 | }, |
| 1408 | isConditionTrue: function isConditionTrue(values, operator) { |
| 1409 | var testValue = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ''; |
| 1410 | var $field = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : jQuery(); |
| 1411 | |
| 1412 | if (!Array.isArray(values)) { |
| 1413 | values = [values]; |
| 1414 | } |
| 1415 | |
| 1416 | var condition_ok = false; // start by assuming that the condition is not met |
| 1417 | // Considered EMPTY: [] [''] [null] ['',null] [,,''] |
| 1418 | // Considered NOT EMPTY: [0] ['ab','c'] ['',0,null] |
| 1419 | |
| 1420 | var valuesAreEmpty = values.length === 0 || values.every(function (v) { |
| 1421 | return !v && v !== 0; |
| 1422 | }); // 0 is not considered empty |
| 1423 | // special cases: [] equals '' => TRUE; [] not equals '' => FALSE |
| 1424 | |
| 1425 | if (operator === 'equals' && testValue === '' && valuesAreEmpty) { |
| 1426 | return true; |
| 1427 | } |
| 1428 | |
| 1429 | if (operator === 'not equals' && testValue === '' && valuesAreEmpty) { |
| 1430 | return false; |
| 1431 | } |
| 1432 | |
| 1433 | if (valuesAreEmpty) { |
| 1434 | if (operator === 'is empty') { |
| 1435 | condition_ok = true; |
| 1436 | } |
| 1437 | } else { |
| 1438 | if (operator === 'not empty') { |
| 1439 | condition_ok = true; |
| 1440 | } |
| 1441 | } |
| 1442 | |
| 1443 | var testValueNumber = isFinite(parseFloat(testValue)) ? parseFloat(testValue) : NaN; |
| 1444 | |
| 1445 | if (operator === 'not equals' || operator === 'not equals (regex)') { |
| 1446 | // start by assuming that the condition is met |
| 1447 | condition_ok = true; |
| 1448 | } |
| 1449 | |
| 1450 | if (operator === 'function' && typeof window[testValue] == 'function' && window[testValue]($field) // here we call the actual user defined function |
| 1451 | ) { |
| 1452 | condition_ok = true; |
| 1453 | } |
| 1454 | |
| 1455 | var regex_patt = /.*/i; // fallback regex pattern |
| 1456 | |
| 1457 | var isValidRegex = true; |
| 1458 | |
| 1459 | if (operator === 'equals (regex)' || operator === 'not equals (regex)') { |
| 1460 | try { |
| 1461 | regex_patt = new RegExp(testValue, 'i'); |
| 1462 | } catch (e) { |
| 1463 | isValidRegex = false; |
| 1464 | } |
| 1465 | } |
| 1466 | |
| 1467 | for (var i = 0; i < values.length; i++) { |
| 1468 | var value = values[i]; |
| 1469 | var valueNumber = isFinite(parseFloat(value)) ? parseFloat(value) : NaN; |
| 1470 | var valsAreNumbers = !isNaN(valueNumber) && !isNaN(testValueNumber); |
| 1471 | |
| 1472 | if (operator === 'equals' && value === testValue || operator === 'equals (regex)' && regex_patt.test(value) || operator === 'greater than' && valsAreNumbers && valueNumber > testValueNumber || operator === 'less than' && valsAreNumbers && valueNumber < testValueNumber || operator === 'greater than or equals' && valsAreNumbers && valueNumber >= testValueNumber || operator === 'less than or equals' && valsAreNumbers && valueNumber <= testValueNumber) { |
| 1473 | condition_ok = true; |
| 1474 | break; |
| 1475 | } else if (operator === 'not equals' && value === testValue || operator === 'not equals (regex)' && regex_patt.test(value)) { |
| 1476 | condition_ok = false; |
| 1477 | break; |
| 1478 | } |
| 1479 | } |
| 1480 | |
| 1481 | return condition_ok; |
| 1482 | }, |
| 1483 | getFormObj: function getFormObj($form) { |
| 1484 | if (typeof $form === 'string') { |
| 1485 | $form = jQuery($form).eq(0); |
| 1486 | } |
| 1487 | |
| 1488 | return wpcf7cf.getWpcf7cfForm($form); |
| 1489 | }, |
| 1490 | getRepeaterObj: function getRepeaterObj($form, repeaterDataId) { |
| 1491 | var form = wpcf7cf.getFormObj($form); |
| 1492 | var repeater = form.repeaters.find(function (repeater) { |
| 1493 | return repeater.params.$repeater.attr('data-id') === repeaterDataId; |
| 1494 | }); |
| 1495 | return repeater; |
| 1496 | }, |
| 1497 | getMultiStepObj: function getMultiStepObj($form) { |
| 1498 | var form = wpcf7cf.getFormObj($form); |
| 1499 | return form.multistep; |
| 1500 | }, |
| 1501 | |
| 1502 | /** |
| 1503 | * Append a new sub-entry to the repeater with the name `repeaterDataId` inside the form `$form` |
| 1504 | * @memberof wpcf7cf |
| 1505 | * @function wpcf7cf.repeaterAddSub |
| 1506 | * @link |
| 1507 | * @param {String|JQuery} $form - JQuery object or css-selector representing the form |
| 1508 | * @param {String} repeaterDataId - *data-id* attribute of the repeater. Normally this is simply the name of the repeater. However, in case of a nested repeater you need to append the name with the correct suffix. For example `my-nested-repeater__1__3`. Hint (check the `data-id` attribute in the HTML code to find the correct suffix) |
| 1509 | */ |
| 1510 | repeaterAddSub: function repeaterAddSub($form, repeaterDataId) { |
| 1511 | var repeater = wpcf7cf.getRepeaterObj($form, repeaterDataId); |
| 1512 | repeater.updateSubs(repeater.params.$repeater.num_subs + 1); |
| 1513 | }, |
| 1514 | |
| 1515 | /** |
| 1516 | * Insert a new sub-entry at the given `index` of the repeater with the name `repeaterDataId` inside the form `$form` |
| 1517 | * @memberof wpcf7cf |
| 1518 | * @param {String|JQuery} $form - JQuery object or css-selector representing the form |
| 1519 | * @param {String} repeaterDataId - *data-id* attribute of the repeater. |
| 1520 | * @param {Number} index - position where to insert the new sub-entry within the repeater |
| 1521 | */ |
| 1522 | repeaterAddSubAtIndex: function repeaterAddSubAtIndex($form, repeaterDataId, index) { |
| 1523 | var repeater = wpcf7cf.getRepeaterObj($form, repeaterDataId); |
| 1524 | repeater.addSubs(1, index); |
| 1525 | }, |
| 1526 | |
| 1527 | /** |
| 1528 | * Remove the sub-entry at the given `index` of the repeater with the *data-id* attribute of `repeaterDataId` inside the form `$form` |
| 1529 | * @memberof wpcf7cf |
| 1530 | * @param {String|JQuery} $form - JQuery object or css-selector representing the form |
| 1531 | * @param {String} repeaterDataId - *data-id* attribute of the repeater. |
| 1532 | * @param {Number} index - position where to insert the new sub-entry within the repeater |
| 1533 | */ |
| 1534 | repeaterRemoveSubAtIndex: function repeaterRemoveSubAtIndex($form, repeaterDataId, index) { |
| 1535 | var repeater = wpcf7cf.getRepeaterObj($form, repeaterDataId); |
| 1536 | repeater.removeSubs(1, index); |
| 1537 | }, |
| 1538 | |
| 1539 | /** |
| 1540 | * Remove the last sub-entry from the repeater with the *data-id* attribute of `repeaterDataId` inside the form `$form` |
| 1541 | * @memberof wpcf7cf |
| 1542 | * @param {String|JQuery} $form - JQuery object or css-selector representing the form |
| 1543 | * @param {String} repeaterDataId - *data-id* attribute of the repeater. |
| 1544 | * @param {Number} index - position where to insert the new sub-entry within the repeater |
| 1545 | */ |
| 1546 | repeaterRemoveSub: function repeaterRemoveSub($form, repeaterDataId) { |
| 1547 | var repeater = wpcf7cf.getRepeaterObj($form, repeaterDataId); |
| 1548 | repeater.updateSubs(repeater.params.$repeater.num_subs - 1); |
| 1549 | }, |
| 1550 | |
| 1551 | /** |
| 1552 | * Set the number of subs for the repeater with the *data-id* attribute of `repeaterDataId` inside the form `$form`. |
| 1553 | * Subs are either appended to or removed from the end of the repeater. |
| 1554 | * @memberof wpcf7cf |
| 1555 | * @param {String|JQuery} $form - JQuery object or css-selector representing the form |
| 1556 | * @param {String} repeaterDataId - *data-id* attribute of the repeater. |
| 1557 | * @param {Number} numberOfSubs - position where to insert the new sub-entry within the repeater |
| 1558 | */ |
| 1559 | repeaterSetNumberOfSubs: function repeaterSetNumberOfSubs($form, repeaterDataId, numberOfSubs) { |
| 1560 | var repeater = wpcf7cf.getRepeaterObj($form, repeaterDataId); |
| 1561 | repeater.updateSubs(numberOfSubs); |
| 1562 | }, |
| 1563 | |
| 1564 | /** |
| 1565 | * Move to step number `step`, ignoring any validation. |
| 1566 | * @memberof wpcf7cf |
| 1567 | * @param {String|JQuery} $form - JQuery object or css-selector representing the form |
| 1568 | * @param {*} step |
| 1569 | */ |
| 1570 | multistepMoveToStep: function multistepMoveToStep($form, step) { |
| 1571 | var multistep = wpcf7cf.getMultiStepObj($form); |
| 1572 | multistep.moveToStep(step); |
| 1573 | }, |
| 1574 | |
| 1575 | /** |
| 1576 | * Validate the current step, and move to step number `step` if validation passes. |
| 1577 | * @memberof wpcf7cf |
| 1578 | * @param {String|JQuery} $form - JQuery object or css-selector representing the form |
| 1579 | * @param {Number} step |
| 1580 | */ |
| 1581 | multistepMoveToStepWithValidation: function multistepMoveToStepWithValidation($form, step) { |
| 1582 | return _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_3___default()( /*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default.a.mark(function _callee2() { |
| 1583 | var multistep, result; |
| 1584 | return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_2___default.a.wrap(function _callee2$(_context2) { |
| 1585 | while (1) { |
| 1586 | switch (_context2.prev = _context2.next) { |
| 1587 | case 0: |
| 1588 | multistep = wpcf7cf.getMultiStepObj($form); |
| 1589 | _context2.next = 3; |
| 1590 | return multistep.validateStep(multistep.currentStep); |
| 1591 | |
| 1592 | case 3: |
| 1593 | result = _context2.sent; |
| 1594 | |
| 1595 | if (result === 'success') { |
| 1596 | multistep.moveToStep(step); |
| 1597 | } |
| 1598 | |
| 1599 | case 5: |
| 1600 | case "end": |
| 1601 | return _context2.stop(); |
| 1602 | } |
| 1603 | } |
| 1604 | }, _callee2); |
| 1605 | }))(); |
| 1606 | } |
| 1607 | }; |
| 1608 | jQuery('.wpcf7-form').each(function () { |
| 1609 | wpcf7cf_forms.push(new Wpcf7cfForm(jQuery(this))); |
| 1610 | }); // Call displayFields again on all forms |
| 1611 | // Necessary in case some theme or plugin changed a form value by the time the entire page is fully loaded. |
| 1612 | |
| 1613 | jQuery('document').on('ready', function () { |
| 1614 | wpcf7cf_forms.forEach(function (f) { |
| 1615 | f.displayFields(); |
| 1616 | }); |
| 1617 | }); // fix for exclusive checkboxes in IE (this will call the change-event again after all other checkboxes are unchecked, triggering the display_fields() function) |
| 1618 | |
| 1619 | var old_wpcf7ExclusiveCheckbox = jQuery.fn.wpcf7ExclusiveCheckbox; |
| 1620 | |
| 1621 | jQuery.fn.wpcf7ExclusiveCheckbox = function () { |
| 1622 | return this.find('input:checkbox').on('click', function () { |
| 1623 | var name = jQuery(this).attr('name'); |
| 1624 | jQuery(this).closest('form').find('input:checkbox[name="' + name + '"]').not(this).prop('checked', false).eq(0).change(); |
| 1625 | }); |
| 1626 | }; |
| 1627 | |
| 1628 | /***/ }), |
| 1629 | |
| 1630 | /***/ "./node_modules/@babel/runtime/helpers/arrayLikeToArray.js": |
| 1631 | /*!*****************************************************************!*\ |
| 1632 | !*** ./node_modules/@babel/runtime/helpers/arrayLikeToArray.js ***! |
| 1633 | \*****************************************************************/ |
| 1634 | /*! no static exports found */ |
| 1635 | /***/ (function(module, exports) { |
| 1636 | |
| 1637 | function _arrayLikeToArray(arr, len) { |
| 1638 | if (len == null || len > arr.length) len = arr.length; |
| 1639 | |
| 1640 | for (var i = 0, arr2 = new Array(len); i < len; i++) { |
| 1641 | arr2[i] = arr[i]; |
| 1642 | } |
| 1643 | |
| 1644 | return arr2; |
| 1645 | } |
| 1646 | |
| 1647 | module.exports = _arrayLikeToArray; |
| 1648 | |
| 1649 | /***/ }), |
| 1650 | |
| 1651 | /***/ "./node_modules/@babel/runtime/helpers/arrayWithHoles.js": |
| 1652 | /*!***************************************************************!*\ |
| 1653 | !*** ./node_modules/@babel/runtime/helpers/arrayWithHoles.js ***! |
| 1654 | \***************************************************************/ |
| 1655 | /*! no static exports found */ |
| 1656 | /***/ (function(module, exports) { |
| 1657 | |
| 1658 | function _arrayWithHoles(arr) { |
| 1659 | if (Array.isArray(arr)) return arr; |
| 1660 | } |
| 1661 | |
| 1662 | module.exports = _arrayWithHoles; |
| 1663 | |
| 1664 | /***/ }), |
| 1665 | |
| 1666 | /***/ "./node_modules/@babel/runtime/helpers/arrayWithoutHoles.js": |
| 1667 | /*!******************************************************************!*\ |
| 1668 | !*** ./node_modules/@babel/runtime/helpers/arrayWithoutHoles.js ***! |
| 1669 | \******************************************************************/ |
| 1670 | /*! no static exports found */ |
| 1671 | /***/ (function(module, exports, __webpack_require__) { |
| 1672 | |
| 1673 | var arrayLikeToArray = __webpack_require__(/*! ./arrayLikeToArray */ "./node_modules/@babel/runtime/helpers/arrayLikeToArray.js"); |
| 1674 | |
| 1675 | function _arrayWithoutHoles(arr) { |
| 1676 | if (Array.isArray(arr)) return arrayLikeToArray(arr); |
| 1677 | } |
| 1678 | |
| 1679 | module.exports = _arrayWithoutHoles; |
| 1680 | |
| 1681 | /***/ }), |
| 1682 | |
| 1683 | /***/ "./node_modules/@babel/runtime/helpers/asyncToGenerator.js": |
| 1684 | /*!*****************************************************************!*\ |
| 1685 | !*** ./node_modules/@babel/runtime/helpers/asyncToGenerator.js ***! |
| 1686 | \*****************************************************************/ |
| 1687 | /*! no static exports found */ |
| 1688 | /***/ (function(module, exports) { |
| 1689 | |
| 1690 | function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { |
| 1691 | try { |
| 1692 | var info = gen[key](arg); |
| 1693 | var value = info.value; |
| 1694 | } catch (error) { |
| 1695 | reject(error); |
| 1696 | return; |
| 1697 | } |
| 1698 | |
| 1699 | if (info.done) { |
| 1700 | resolve(value); |
| 1701 | } else { |
| 1702 | Promise.resolve(value).then(_next, _throw); |
| 1703 | } |
| 1704 | } |
| 1705 | |
| 1706 | function _asyncToGenerator(fn) { |
| 1707 | return function () { |
| 1708 | var self = this, |
| 1709 | args = arguments; |
| 1710 | return new Promise(function (resolve, reject) { |
| 1711 | var gen = fn.apply(self, args); |
| 1712 | |
| 1713 | function _next(value) { |
| 1714 | asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); |
| 1715 | } |
| 1716 | |
| 1717 | function _throw(err) { |
| 1718 | asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); |
| 1719 | } |
| 1720 | |
| 1721 | _next(undefined); |
| 1722 | }); |
| 1723 | }; |
| 1724 | } |
| 1725 | |
| 1726 | module.exports = _asyncToGenerator; |
| 1727 | |
| 1728 | /***/ }), |
| 1729 | |
| 1730 | /***/ "./node_modules/@babel/runtime/helpers/defineProperty.js": |
| 1731 | /*!***************************************************************!*\ |
| 1732 | !*** ./node_modules/@babel/runtime/helpers/defineProperty.js ***! |
| 1733 | \***************************************************************/ |
| 1734 | /*! no static exports found */ |
| 1735 | /***/ (function(module, exports) { |
| 1736 | |
| 1737 | function _defineProperty(obj, key, value) { |
| 1738 | if (key in obj) { |
| 1739 | Object.defineProperty(obj, key, { |
| 1740 | value: value, |
| 1741 | enumerable: true, |
| 1742 | configurable: true, |
| 1743 | writable: true |
| 1744 | }); |
| 1745 | } else { |
| 1746 | obj[key] = value; |
| 1747 | } |
| 1748 | |
| 1749 | return obj; |
| 1750 | } |
| 1751 | |
| 1752 | module.exports = _defineProperty; |
| 1753 | |
| 1754 | /***/ }), |
| 1755 | |
| 1756 | /***/ "./node_modules/@babel/runtime/helpers/iterableToArray.js": |
| 1757 | /*!****************************************************************!*\ |
| 1758 | !*** ./node_modules/@babel/runtime/helpers/iterableToArray.js ***! |
| 1759 | \****************************************************************/ |
| 1760 | /*! no static exports found */ |
| 1761 | /***/ (function(module, exports) { |
| 1762 | |
| 1763 | function _iterableToArray(iter) { |
| 1764 | if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); |
| 1765 | } |
| 1766 | |
| 1767 | module.exports = _iterableToArray; |
| 1768 | |
| 1769 | /***/ }), |
| 1770 | |
| 1771 | /***/ "./node_modules/@babel/runtime/helpers/iterableToArrayLimit.js": |
| 1772 | /*!*********************************************************************!*\ |
| 1773 | !*** ./node_modules/@babel/runtime/helpers/iterableToArrayLimit.js ***! |
| 1774 | \*********************************************************************/ |
| 1775 | /*! no static exports found */ |
| 1776 | /***/ (function(module, exports) { |
| 1777 | |
| 1778 | function _iterableToArrayLimit(arr, i) { |
| 1779 | if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; |
| 1780 | var _arr = []; |
| 1781 | var _n = true; |
| 1782 | var _d = false; |
| 1783 | var _e = undefined; |
| 1784 | |
| 1785 | try { |
| 1786 | for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { |
| 1787 | _arr.push(_s.value); |
| 1788 | |
| 1789 | if (i && _arr.length === i) break; |
| 1790 | } |
| 1791 | } catch (err) { |
| 1792 | _d = true; |
| 1793 | _e = err; |
| 1794 | } finally { |
| 1795 | try { |
| 1796 | if (!_n && _i["return"] != null) _i["return"](); |
| 1797 | } finally { |
| 1798 | if (_d) throw _e; |
| 1799 | } |
| 1800 | } |
| 1801 | |
| 1802 | return _arr; |
| 1803 | } |
| 1804 | |
| 1805 | module.exports = _iterableToArrayLimit; |
| 1806 | |
| 1807 | /***/ }), |
| 1808 | |
| 1809 | /***/ "./node_modules/@babel/runtime/helpers/nonIterableRest.js": |
| 1810 | /*!****************************************************************!*\ |
| 1811 | !*** ./node_modules/@babel/runtime/helpers/nonIterableRest.js ***! |
| 1812 | \****************************************************************/ |
| 1813 | /*! no static exports found */ |
| 1814 | /***/ (function(module, exports) { |
| 1815 | |
| 1816 | function _nonIterableRest() { |
| 1817 | throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); |
| 1818 | } |
| 1819 | |
| 1820 | module.exports = _nonIterableRest; |
| 1821 | |
| 1822 | /***/ }), |
| 1823 | |
| 1824 | /***/ "./node_modules/@babel/runtime/helpers/nonIterableSpread.js": |
| 1825 | /*!******************************************************************!*\ |
| 1826 | !*** ./node_modules/@babel/runtime/helpers/nonIterableSpread.js ***! |
| 1827 | \******************************************************************/ |
| 1828 | /*! no static exports found */ |
| 1829 | /***/ (function(module, exports) { |
| 1830 | |
| 1831 | function _nonIterableSpread() { |
| 1832 | throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); |
| 1833 | } |
| 1834 | |
| 1835 | module.exports = _nonIterableSpread; |
| 1836 | |
| 1837 | /***/ }), |
| 1838 | |
| 1839 | /***/ "./node_modules/@babel/runtime/helpers/slicedToArray.js": |
| 1840 | /*!**************************************************************!*\ |
| 1841 | !*** ./node_modules/@babel/runtime/helpers/slicedToArray.js ***! |
| 1842 | \**************************************************************/ |
| 1843 | /*! no static exports found */ |
| 1844 | /***/ (function(module, exports, __webpack_require__) { |
| 1845 | |
| 1846 | var arrayWithHoles = __webpack_require__(/*! ./arrayWithHoles */ "./node_modules/@babel/runtime/helpers/arrayWithHoles.js"); |
| 1847 | |
| 1848 | var iterableToArrayLimit = __webpack_require__(/*! ./iterableToArrayLimit */ "./node_modules/@babel/runtime/helpers/iterableToArrayLimit.js"); |
| 1849 | |
| 1850 | var unsupportedIterableToArray = __webpack_require__(/*! ./unsupportedIterableToArray */ "./node_modules/@babel/runtime/helpers/unsupportedIterableToArray.js"); |
| 1851 | |
| 1852 | var nonIterableRest = __webpack_require__(/*! ./nonIterableRest */ "./node_modules/@babel/runtime/helpers/nonIterableRest.js"); |
| 1853 | |
| 1854 | function _slicedToArray(arr, i) { |
| 1855 | return arrayWithHoles(arr) || iterableToArrayLimit(arr, i) || unsupportedIterableToArray(arr, i) || nonIterableRest(); |
| 1856 | } |
| 1857 | |
| 1858 | module.exports = _slicedToArray; |
| 1859 | |
| 1860 | /***/ }), |
| 1861 | |
| 1862 | /***/ "./node_modules/@babel/runtime/helpers/toConsumableArray.js": |
| 1863 | /*!******************************************************************!*\ |
| 1864 | !*** ./node_modules/@babel/runtime/helpers/toConsumableArray.js ***! |
| 1865 | \******************************************************************/ |
| 1866 | /*! no static exports found */ |
| 1867 | /***/ (function(module, exports, __webpack_require__) { |
| 1868 | |
| 1869 | var arrayWithoutHoles = __webpack_require__(/*! ./arrayWithoutHoles */ "./node_modules/@babel/runtime/helpers/arrayWithoutHoles.js"); |
| 1870 | |
| 1871 | var iterableToArray = __webpack_require__(/*! ./iterableToArray */ "./node_modules/@babel/runtime/helpers/iterableToArray.js"); |
| 1872 | |
| 1873 | var unsupportedIterableToArray = __webpack_require__(/*! ./unsupportedIterableToArray */ "./node_modules/@babel/runtime/helpers/unsupportedIterableToArray.js"); |
| 1874 | |
| 1875 | var nonIterableSpread = __webpack_require__(/*! ./nonIterableSpread */ "./node_modules/@babel/runtime/helpers/nonIterableSpread.js"); |
| 1876 | |
| 1877 | function _toConsumableArray(arr) { |
| 1878 | return arrayWithoutHoles(arr) || iterableToArray(arr) || unsupportedIterableToArray(arr) || nonIterableSpread(); |
| 1879 | } |
| 1880 | |
| 1881 | module.exports = _toConsumableArray; |
| 1882 | |
| 1883 | /***/ }), |
| 1884 | |
| 1885 | /***/ "./node_modules/@babel/runtime/helpers/unsupportedIterableToArray.js": |
| 1886 | /*!***************************************************************************!*\ |
| 1887 | !*** ./node_modules/@babel/runtime/helpers/unsupportedIterableToArray.js ***! |
| 1888 | \***************************************************************************/ |
| 1889 | /*! no static exports found */ |
| 1890 | /***/ (function(module, exports, __webpack_require__) { |
| 1891 | |
| 1892 | var arrayLikeToArray = __webpack_require__(/*! ./arrayLikeToArray */ "./node_modules/@babel/runtime/helpers/arrayLikeToArray.js"); |
| 1893 | |
| 1894 | function _unsupportedIterableToArray(o, minLen) { |
| 1895 | if (!o) return; |
| 1896 | if (typeof o === "string") return arrayLikeToArray(o, minLen); |
| 1897 | var n = Object.prototype.toString.call(o).slice(8, -1); |
| 1898 | if (n === "Object" && o.constructor) n = o.constructor.name; |
| 1899 | if (n === "Map" || n === "Set") return Array.from(o); |
| 1900 | if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return arrayLikeToArray(o, minLen); |
| 1901 | } |
| 1902 | |
| 1903 | module.exports = _unsupportedIterableToArray; |
| 1904 | |
| 1905 | /***/ }), |
| 1906 | |
| 1907 | /***/ "./node_modules/@babel/runtime/regenerator/index.js": |
| 1908 | /*!**********************************************************!*\ |
| 1909 | !*** ./node_modules/@babel/runtime/regenerator/index.js ***! |
| 1910 | \**********************************************************/ |
| 1911 | /*! no static exports found */ |
| 1912 | /***/ (function(module, exports, __webpack_require__) { |
| 1913 | |
| 1914 | module.exports = __webpack_require__(/*! regenerator-runtime */ "./node_modules/regenerator-runtime/runtime.js"); |
| 1915 | |
| 1916 | /***/ }), |
| 1917 | |
| 1918 | /***/ "./node_modules/es6-promise-promise/index.js": |
| 1919 | /*!***************************************************!*\ |
| 1920 | !*** ./node_modules/es6-promise-promise/index.js ***! |
| 1921 | \***************************************************/ |
| 1922 | /*! no static exports found */ |
| 1923 | /***/ (function(module, exports, __webpack_require__) { |
| 1924 | |
| 1925 | module.exports = __webpack_require__(/*! es6-promise */ "./node_modules/es6-promise/dist/es6-promise.js").Promise; |
| 1926 | |
| 1927 | /***/ }), |
| 1928 | |
| 1929 | /***/ "./node_modules/es6-promise/dist/es6-promise.js": |
| 1930 | /*!******************************************************!*\ |
| 1931 | !*** ./node_modules/es6-promise/dist/es6-promise.js ***! |
| 1932 | \******************************************************/ |
| 1933 | /*! no static exports found */ |
| 1934 | /***/ (function(module, exports, __webpack_require__) { |
| 1935 | |
| 1936 | /* WEBPACK VAR INJECTION */(function(process, global) {var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_RESULT__;var require;function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } |
| 1937 | |
| 1938 | /*! |
| 1939 | * @overview es6-promise - a tiny implementation of Promises/A+. |
| 1940 | * @copyright Copyright (c) 2014 Yehuda Katz, Tom Dale, Stefan Penner and contributors (Conversion to ES6 API by Jake Archibald) |
| 1941 | * @license Licensed under MIT license |
| 1942 | * See https://raw.githubusercontent.com/stefanpenner/es6-promise/master/LICENSE |
| 1943 | * @version 3.3.1 |
| 1944 | */ |
| 1945 | (function (global, factory) { |
| 1946 | ( false ? undefined : _typeof(exports)) === 'object' && typeof module !== 'undefined' ? module.exports = factory() : true ? !(__WEBPACK_AMD_DEFINE_FACTORY__ = (factory), |
| 1947 | __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? |
| 1948 | (__WEBPACK_AMD_DEFINE_FACTORY__.call(exports, __webpack_require__, exports, module)) : |
| 1949 | __WEBPACK_AMD_DEFINE_FACTORY__), |
| 1950 | __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)) : undefined; |
| 1951 | })(this, function () { |
| 1952 | 'use strict'; |
| 1953 | |
| 1954 | function objectOrFunction(x) { |
| 1955 | return typeof x === 'function' || _typeof(x) === 'object' && x !== null; |
| 1956 | } |
| 1957 | |
| 1958 | function isFunction(x) { |
| 1959 | return typeof x === 'function'; |
| 1960 | } |
| 1961 | |
| 1962 | var _isArray = undefined; |
| 1963 | |
| 1964 | if (!Array.isArray) { |
| 1965 | _isArray = function _isArray(x) { |
| 1966 | return Object.prototype.toString.call(x) === '[object Array]'; |
| 1967 | }; |
| 1968 | } else { |
| 1969 | _isArray = Array.isArray; |
| 1970 | } |
| 1971 | |
| 1972 | var isArray = _isArray; |
| 1973 | var len = 0; |
| 1974 | var vertxNext = undefined; |
| 1975 | var customSchedulerFn = undefined; |
| 1976 | |
| 1977 | var asap = function asap(callback, arg) { |
| 1978 | queue[len] = callback; |
| 1979 | queue[len + 1] = arg; |
| 1980 | len += 2; |
| 1981 | |
| 1982 | if (len === 2) { |
| 1983 | // If len is 2, that means that we need to schedule an async flush. |
| 1984 | // If additional callbacks are queued before the queue is flushed, they |
| 1985 | // will be processed by this flush that we are scheduling. |
| 1986 | if (customSchedulerFn) { |
| 1987 | customSchedulerFn(flush); |
| 1988 | } else { |
| 1989 | scheduleFlush(); |
| 1990 | } |
| 1991 | } |
| 1992 | }; |
| 1993 | |
| 1994 | function setScheduler(scheduleFn) { |
| 1995 | customSchedulerFn = scheduleFn; |
| 1996 | } |
| 1997 | |
| 1998 | function setAsap(asapFn) { |
| 1999 | asap = asapFn; |
| 2000 | } |
| 2001 | |
| 2002 | var browserWindow = typeof window !== 'undefined' ? window : undefined; |
| 2003 | var browserGlobal = browserWindow || {}; |
| 2004 | var BrowserMutationObserver = browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver; |
| 2005 | var isNode = typeof self === 'undefined' && typeof process !== 'undefined' && {}.toString.call(process) === '[object process]'; // test for web worker but not in IE10 |
| 2006 | |
| 2007 | var isWorker = typeof Uint8ClampedArray !== 'undefined' && typeof importScripts !== 'undefined' && typeof MessageChannel !== 'undefined'; // node |
| 2008 | |
| 2009 | function useNextTick() { |
| 2010 | // node version 0.10.x displays a deprecation warning when nextTick is used recursively |
| 2011 | // see https://github.com/cujojs/when/issues/410 for details |
| 2012 | return function () { |
| 2013 | return process.nextTick(flush); |
| 2014 | }; |
| 2015 | } // vertx |
| 2016 | |
| 2017 | |
| 2018 | function useVertxTimer() { |
| 2019 | return function () { |
| 2020 | vertxNext(flush); |
| 2021 | }; |
| 2022 | } |
| 2023 | |
| 2024 | function useMutationObserver() { |
| 2025 | var iterations = 0; |
| 2026 | var observer = new BrowserMutationObserver(flush); |
| 2027 | var node = document.createTextNode(''); |
| 2028 | observer.observe(node, { |
| 2029 | characterData: true |
| 2030 | }); |
| 2031 | return function () { |
| 2032 | node.data = iterations = ++iterations % 2; |
| 2033 | }; |
| 2034 | } // web worker |
| 2035 | |
| 2036 | |
| 2037 | function useMessageChannel() { |
| 2038 | var channel = new MessageChannel(); |
| 2039 | channel.port1.onmessage = flush; |
| 2040 | return function () { |
| 2041 | return channel.port2.postMessage(0); |
| 2042 | }; |
| 2043 | } |
| 2044 | |
| 2045 | function useSetTimeout() { |
| 2046 | // Store setTimeout reference so es6-promise will be unaffected by |
| 2047 | // other code modifying setTimeout (like sinon.useFakeTimers()) |
| 2048 | var globalSetTimeout = setTimeout; |
| 2049 | return function () { |
| 2050 | return globalSetTimeout(flush, 1); |
| 2051 | }; |
| 2052 | } |
| 2053 | |
| 2054 | var queue = new Array(1000); |
| 2055 | |
| 2056 | function flush() { |
| 2057 | for (var i = 0; i < len; i += 2) { |
| 2058 | var callback = queue[i]; |
| 2059 | var arg = queue[i + 1]; |
| 2060 | callback(arg); |
| 2061 | queue[i] = undefined; |
| 2062 | queue[i + 1] = undefined; |
| 2063 | } |
| 2064 | |
| 2065 | len = 0; |
| 2066 | } |
| 2067 | |
| 2068 | function attemptVertx() { |
| 2069 | try { |
| 2070 | var r = require; |
| 2071 | var vertx = __webpack_require__(/*! vertx */ 1); |
| 2072 | vertxNext = vertx.runOnLoop || vertx.runOnContext; |
| 2073 | return useVertxTimer(); |
| 2074 | } catch (e) { |
| 2075 | return useSetTimeout(); |
| 2076 | } |
| 2077 | } |
| 2078 | |
| 2079 | var scheduleFlush = undefined; // Decide what async method to use to triggering processing of queued callbacks: |
| 2080 | |
| 2081 | if (isNode) { |
| 2082 | scheduleFlush = useNextTick(); |
| 2083 | } else if (BrowserMutationObserver) { |
| 2084 | scheduleFlush = useMutationObserver(); |
| 2085 | } else if (isWorker) { |
| 2086 | scheduleFlush = useMessageChannel(); |
| 2087 | } else if (browserWindow === undefined && "function" === 'function') { |
| 2088 | scheduleFlush = attemptVertx(); |
| 2089 | } else { |
| 2090 | scheduleFlush = useSetTimeout(); |
| 2091 | } |
| 2092 | |
| 2093 | function then(onFulfillment, onRejection) { |
| 2094 | var _arguments = arguments; |
| 2095 | var parent = this; |
| 2096 | var child = new this.constructor(noop); |
| 2097 | |
| 2098 | if (child[PROMISE_ID] === undefined) { |
| 2099 | makePromise(child); |
| 2100 | } |
| 2101 | |
| 2102 | var _state = parent._state; |
| 2103 | |
| 2104 | if (_state) { |
| 2105 | (function () { |
| 2106 | var callback = _arguments[_state - 1]; |
| 2107 | asap(function () { |
| 2108 | return invokeCallback(_state, child, callback, parent._result); |
| 2109 | }); |
| 2110 | })(); |
| 2111 | } else { |
| 2112 | subscribe(parent, child, onFulfillment, onRejection); |
| 2113 | } |
| 2114 | |
| 2115 | return child; |
| 2116 | } |
| 2117 | /** |
| 2118 | `Promise.resolve` returns a promise that will become resolved with the |
| 2119 | passed `value`. It is shorthand for the following: |
| 2120 | |
| 2121 | ```javascript |
| 2122 | let promise = new Promise(function(resolve, reject){ |
| 2123 | resolve(1); |
| 2124 | }); |
| 2125 | |
| 2126 | promise.then(function(value){ |
| 2127 | // value === 1 |
| 2128 | }); |
| 2129 | ``` |
| 2130 | |
| 2131 | Instead of writing the above, your code now simply becomes the following: |
| 2132 | |
| 2133 | ```javascript |
| 2134 | let promise = Promise.resolve(1); |
| 2135 | |
| 2136 | promise.then(function(value){ |
| 2137 | // value === 1 |
| 2138 | }); |
| 2139 | ``` |
| 2140 | |
| 2141 | @method resolve |
| 2142 | @static |
| 2143 | @param {Any} value value that the returned promise will be resolved with |
| 2144 | Useful for tooling. |
| 2145 | @return {Promise} a promise that will become fulfilled with the given |
| 2146 | `value` |
| 2147 | */ |
| 2148 | |
| 2149 | |
| 2150 | function resolve(object) { |
| 2151 | /*jshint validthis:true */ |
| 2152 | var Constructor = this; |
| 2153 | |
| 2154 | if (object && _typeof(object) === 'object' && object.constructor === Constructor) { |
| 2155 | return object; |
| 2156 | } |
| 2157 | |
| 2158 | var promise = new Constructor(noop); |
| 2159 | |
| 2160 | _resolve(promise, object); |
| 2161 | |
| 2162 | return promise; |
| 2163 | } |
| 2164 | |
| 2165 | var PROMISE_ID = Math.random().toString(36).substring(16); |
| 2166 | |
| 2167 | function noop() {} |
| 2168 | |
| 2169 | var PENDING = void 0; |
| 2170 | var FULFILLED = 1; |
| 2171 | var REJECTED = 2; |
| 2172 | var GET_THEN_ERROR = new ErrorObject(); |
| 2173 | |
| 2174 | function selfFulfillment() { |
| 2175 | return new TypeError("You cannot resolve a promise with itself"); |
| 2176 | } |
| 2177 | |
| 2178 | function cannotReturnOwn() { |
| 2179 | return new TypeError('A promises callback cannot return that same promise.'); |
| 2180 | } |
| 2181 | |
| 2182 | function getThen(promise) { |
| 2183 | try { |
| 2184 | return promise.then; |
| 2185 | } catch (error) { |
| 2186 | GET_THEN_ERROR.error = error; |
| 2187 | return GET_THEN_ERROR; |
| 2188 | } |
| 2189 | } |
| 2190 | |
| 2191 | function tryThen(then, value, fulfillmentHandler, rejectionHandler) { |
| 2192 | try { |
| 2193 | then.call(value, fulfillmentHandler, rejectionHandler); |
| 2194 | } catch (e) { |
| 2195 | return e; |
| 2196 | } |
| 2197 | } |
| 2198 | |
| 2199 | function handleForeignThenable(promise, thenable, then) { |
| 2200 | asap(function (promise) { |
| 2201 | var sealed = false; |
| 2202 | var error = tryThen(then, thenable, function (value) { |
| 2203 | if (sealed) { |
| 2204 | return; |
| 2205 | } |
| 2206 | |
| 2207 | sealed = true; |
| 2208 | |
| 2209 | if (thenable !== value) { |
| 2210 | _resolve(promise, value); |
| 2211 | } else { |
| 2212 | fulfill(promise, value); |
| 2213 | } |
| 2214 | }, function (reason) { |
| 2215 | if (sealed) { |
| 2216 | return; |
| 2217 | } |
| 2218 | |
| 2219 | sealed = true; |
| 2220 | |
| 2221 | _reject(promise, reason); |
| 2222 | }, 'Settle: ' + (promise._label || ' unknown promise')); |
| 2223 | |
| 2224 | if (!sealed && error) { |
| 2225 | sealed = true; |
| 2226 | |
| 2227 | _reject(promise, error); |
| 2228 | } |
| 2229 | }, promise); |
| 2230 | } |
| 2231 | |
| 2232 | function handleOwnThenable(promise, thenable) { |
| 2233 | if (thenable._state === FULFILLED) { |
| 2234 | fulfill(promise, thenable._result); |
| 2235 | } else if (thenable._state === REJECTED) { |
| 2236 | _reject(promise, thenable._result); |
| 2237 | } else { |
| 2238 | subscribe(thenable, undefined, function (value) { |
| 2239 | return _resolve(promise, value); |
| 2240 | }, function (reason) { |
| 2241 | return _reject(promise, reason); |
| 2242 | }); |
| 2243 | } |
| 2244 | } |
| 2245 | |
| 2246 | function handleMaybeThenable(promise, maybeThenable, then$$) { |
| 2247 | if (maybeThenable.constructor === promise.constructor && then$$ === then && maybeThenable.constructor.resolve === resolve) { |
| 2248 | handleOwnThenable(promise, maybeThenable); |
| 2249 | } else { |
| 2250 | if (then$$ === GET_THEN_ERROR) { |
| 2251 | _reject(promise, GET_THEN_ERROR.error); |
| 2252 | } else if (then$$ === undefined) { |
| 2253 | fulfill(promise, maybeThenable); |
| 2254 | } else if (isFunction(then$$)) { |
| 2255 | handleForeignThenable(promise, maybeThenable, then$$); |
| 2256 | } else { |
| 2257 | fulfill(promise, maybeThenable); |
| 2258 | } |
| 2259 | } |
| 2260 | } |
| 2261 | |
| 2262 | function _resolve(promise, value) { |
| 2263 | if (promise === value) { |
| 2264 | _reject(promise, selfFulfillment()); |
| 2265 | } else if (objectOrFunction(value)) { |
| 2266 | handleMaybeThenable(promise, value, getThen(value)); |
| 2267 | } else { |
| 2268 | fulfill(promise, value); |
| 2269 | } |
| 2270 | } |
| 2271 | |
| 2272 | function publishRejection(promise) { |
| 2273 | if (promise._onerror) { |
| 2274 | promise._onerror(promise._result); |
| 2275 | } |
| 2276 | |
| 2277 | publish(promise); |
| 2278 | } |
| 2279 | |
| 2280 | function fulfill(promise, value) { |
| 2281 | if (promise._state !== PENDING) { |
| 2282 | return; |
| 2283 | } |
| 2284 | |
| 2285 | promise._result = value; |
| 2286 | promise._state = FULFILLED; |
| 2287 | |
| 2288 | if (promise._subscribers.length !== 0) { |
| 2289 | asap(publish, promise); |
| 2290 | } |
| 2291 | } |
| 2292 | |
| 2293 | function _reject(promise, reason) { |
| 2294 | if (promise._state !== PENDING) { |
| 2295 | return; |
| 2296 | } |
| 2297 | |
| 2298 | promise._state = REJECTED; |
| 2299 | promise._result = reason; |
| 2300 | asap(publishRejection, promise); |
| 2301 | } |
| 2302 | |
| 2303 | function subscribe(parent, child, onFulfillment, onRejection) { |
| 2304 | var _subscribers = parent._subscribers; |
| 2305 | var length = _subscribers.length; |
| 2306 | parent._onerror = null; |
| 2307 | _subscribers[length] = child; |
| 2308 | _subscribers[length + FULFILLED] = onFulfillment; |
| 2309 | _subscribers[length + REJECTED] = onRejection; |
| 2310 | |
| 2311 | if (length === 0 && parent._state) { |
| 2312 | asap(publish, parent); |
| 2313 | } |
| 2314 | } |
| 2315 | |
| 2316 | function publish(promise) { |
| 2317 | var subscribers = promise._subscribers; |
| 2318 | var settled = promise._state; |
| 2319 | |
| 2320 | if (subscribers.length === 0) { |
| 2321 | return; |
| 2322 | } |
| 2323 | |
| 2324 | var child = undefined, |
| 2325 | callback = undefined, |
| 2326 | detail = promise._result; |
| 2327 | |
| 2328 | for (var i = 0; i < subscribers.length; i += 3) { |
| 2329 | child = subscribers[i]; |
| 2330 | callback = subscribers[i + settled]; |
| 2331 | |
| 2332 | if (child) { |
| 2333 | invokeCallback(settled, child, callback, detail); |
| 2334 | } else { |
| 2335 | callback(detail); |
| 2336 | } |
| 2337 | } |
| 2338 | |
| 2339 | promise._subscribers.length = 0; |
| 2340 | } |
| 2341 | |
| 2342 | function ErrorObject() { |
| 2343 | this.error = null; |
| 2344 | } |
| 2345 | |
| 2346 | var TRY_CATCH_ERROR = new ErrorObject(); |
| 2347 | |
| 2348 | function tryCatch(callback, detail) { |
| 2349 | try { |
| 2350 | return callback(detail); |
| 2351 | } catch (e) { |
| 2352 | TRY_CATCH_ERROR.error = e; |
| 2353 | return TRY_CATCH_ERROR; |
| 2354 | } |
| 2355 | } |
| 2356 | |
| 2357 | function invokeCallback(settled, promise, callback, detail) { |
| 2358 | var hasCallback = isFunction(callback), |
| 2359 | value = undefined, |
| 2360 | error = undefined, |
| 2361 | succeeded = undefined, |
| 2362 | failed = undefined; |
| 2363 | |
| 2364 | if (hasCallback) { |
| 2365 | value = tryCatch(callback, detail); |
| 2366 | |
| 2367 | if (value === TRY_CATCH_ERROR) { |
| 2368 | failed = true; |
| 2369 | error = value.error; |
| 2370 | value = null; |
| 2371 | } else { |
| 2372 | succeeded = true; |
| 2373 | } |
| 2374 | |
| 2375 | if (promise === value) { |
| 2376 | _reject(promise, cannotReturnOwn()); |
| 2377 | |
| 2378 | return; |
| 2379 | } |
| 2380 | } else { |
| 2381 | value = detail; |
| 2382 | succeeded = true; |
| 2383 | } |
| 2384 | |
| 2385 | if (promise._state !== PENDING) {// noop |
| 2386 | } else if (hasCallback && succeeded) { |
| 2387 | _resolve(promise, value); |
| 2388 | } else if (failed) { |
| 2389 | _reject(promise, error); |
| 2390 | } else if (settled === FULFILLED) { |
| 2391 | fulfill(promise, value); |
| 2392 | } else if (settled === REJECTED) { |
| 2393 | _reject(promise, value); |
| 2394 | } |
| 2395 | } |
| 2396 | |
| 2397 | function initializePromise(promise, resolver) { |
| 2398 | try { |
| 2399 | resolver(function resolvePromise(value) { |
| 2400 | _resolve(promise, value); |
| 2401 | }, function rejectPromise(reason) { |
| 2402 | _reject(promise, reason); |
| 2403 | }); |
| 2404 | } catch (e) { |
| 2405 | _reject(promise, e); |
| 2406 | } |
| 2407 | } |
| 2408 | |
| 2409 | var id = 0; |
| 2410 | |
| 2411 | function nextId() { |
| 2412 | return id++; |
| 2413 | } |
| 2414 | |
| 2415 | function makePromise(promise) { |
| 2416 | promise[PROMISE_ID] = id++; |
| 2417 | promise._state = undefined; |
| 2418 | promise._result = undefined; |
| 2419 | promise._subscribers = []; |
| 2420 | } |
| 2421 | |
| 2422 | function Enumerator(Constructor, input) { |
| 2423 | this._instanceConstructor = Constructor; |
| 2424 | this.promise = new Constructor(noop); |
| 2425 | |
| 2426 | if (!this.promise[PROMISE_ID]) { |
| 2427 | makePromise(this.promise); |
| 2428 | } |
| 2429 | |
| 2430 | if (isArray(input)) { |
| 2431 | this._input = input; |
| 2432 | this.length = input.length; |
| 2433 | this._remaining = input.length; |
| 2434 | this._result = new Array(this.length); |
| 2435 | |
| 2436 | if (this.length === 0) { |
| 2437 | fulfill(this.promise, this._result); |
| 2438 | } else { |
| 2439 | this.length = this.length || 0; |
| 2440 | |
| 2441 | this._enumerate(); |
| 2442 | |
| 2443 | if (this._remaining === 0) { |
| 2444 | fulfill(this.promise, this._result); |
| 2445 | } |
| 2446 | } |
| 2447 | } else { |
| 2448 | _reject(this.promise, validationError()); |
| 2449 | } |
| 2450 | } |
| 2451 | |
| 2452 | function validationError() { |
| 2453 | return new Error('Array Methods must be provided an Array'); |
| 2454 | } |
| 2455 | |
| 2456 | ; |
| 2457 | |
| 2458 | Enumerator.prototype._enumerate = function () { |
| 2459 | var length = this.length; |
| 2460 | var _input = this._input; |
| 2461 | |
| 2462 | for (var i = 0; this._state === PENDING && i < length; i++) { |
| 2463 | this._eachEntry(_input[i], i); |
| 2464 | } |
| 2465 | }; |
| 2466 | |
| 2467 | Enumerator.prototype._eachEntry = function (entry, i) { |
| 2468 | var c = this._instanceConstructor; |
| 2469 | var resolve$$ = c.resolve; |
| 2470 | |
| 2471 | if (resolve$$ === resolve) { |
| 2472 | var _then = getThen(entry); |
| 2473 | |
| 2474 | if (_then === then && entry._state !== PENDING) { |
| 2475 | this._settledAt(entry._state, i, entry._result); |
| 2476 | } else if (typeof _then !== 'function') { |
| 2477 | this._remaining--; |
| 2478 | this._result[i] = entry; |
| 2479 | } else if (c === Promise) { |
| 2480 | var promise = new c(noop); |
| 2481 | handleMaybeThenable(promise, entry, _then); |
| 2482 | |
| 2483 | this._willSettleAt(promise, i); |
| 2484 | } else { |
| 2485 | this._willSettleAt(new c(function (resolve$$) { |
| 2486 | return resolve$$(entry); |
| 2487 | }), i); |
| 2488 | } |
| 2489 | } else { |
| 2490 | this._willSettleAt(resolve$$(entry), i); |
| 2491 | } |
| 2492 | }; |
| 2493 | |
| 2494 | Enumerator.prototype._settledAt = function (state, i, value) { |
| 2495 | var promise = this.promise; |
| 2496 | |
| 2497 | if (promise._state === PENDING) { |
| 2498 | this._remaining--; |
| 2499 | |
| 2500 | if (state === REJECTED) { |
| 2501 | _reject(promise, value); |
| 2502 | } else { |
| 2503 | this._result[i] = value; |
| 2504 | } |
| 2505 | } |
| 2506 | |
| 2507 | if (this._remaining === 0) { |
| 2508 | fulfill(promise, this._result); |
| 2509 | } |
| 2510 | }; |
| 2511 | |
| 2512 | Enumerator.prototype._willSettleAt = function (promise, i) { |
| 2513 | var enumerator = this; |
| 2514 | subscribe(promise, undefined, function (value) { |
| 2515 | return enumerator._settledAt(FULFILLED, i, value); |
| 2516 | }, function (reason) { |
| 2517 | return enumerator._settledAt(REJECTED, i, reason); |
| 2518 | }); |
| 2519 | }; |
| 2520 | /** |
| 2521 | `Promise.all` accepts an array of promises, and returns a new promise which |
| 2522 | is fulfilled with an array of fulfillment values for the passed promises, or |
| 2523 | rejected with the reason of the first passed promise to be rejected. It casts all |
| 2524 | elements of the passed iterable to promises as it runs this algorithm. |
| 2525 | |
| 2526 | Example: |
| 2527 | |
| 2528 | ```javascript |
| 2529 | let promise1 = resolve(1); |
| 2530 | let promise2 = resolve(2); |
| 2531 | let promise3 = resolve(3); |
| 2532 | let promises = [ promise1, promise2, promise3 ]; |
| 2533 | |
| 2534 | Promise.all(promises).then(function(array){ |
| 2535 | // The array here would be [ 1, 2, 3 ]; |
| 2536 | }); |
| 2537 | ``` |
| 2538 | |
| 2539 | If any of the `promises` given to `all` are rejected, the first promise |
| 2540 | that is rejected will be given as an argument to the returned promises's |
| 2541 | rejection handler. For example: |
| 2542 | |
| 2543 | Example: |
| 2544 | |
| 2545 | ```javascript |
| 2546 | let promise1 = resolve(1); |
| 2547 | let promise2 = reject(new Error("2")); |
| 2548 | let promise3 = reject(new Error("3")); |
| 2549 | let promises = [ promise1, promise2, promise3 ]; |
| 2550 | |
| 2551 | Promise.all(promises).then(function(array){ |
| 2552 | // Code here never runs because there are rejected promises! |
| 2553 | }, function(error) { |
| 2554 | // error.message === "2" |
| 2555 | }); |
| 2556 | ``` |
| 2557 | |
| 2558 | @method all |
| 2559 | @static |
| 2560 | @param {Array} entries array of promises |
| 2561 | @param {String} label optional string for labeling the promise. |
| 2562 | Useful for tooling. |
| 2563 | @return {Promise} promise that is fulfilled when all `promises` have been |
| 2564 | fulfilled, or rejected if any of them become rejected. |
| 2565 | @static |
| 2566 | */ |
| 2567 | |
| 2568 | |
| 2569 | function all(entries) { |
| 2570 | return new Enumerator(this, entries).promise; |
| 2571 | } |
| 2572 | /** |
| 2573 | `Promise.race` returns a new promise which is settled in the same way as the |
| 2574 | first passed promise to settle. |
| 2575 | |
| 2576 | Example: |
| 2577 | |
| 2578 | ```javascript |
| 2579 | let promise1 = new Promise(function(resolve, reject){ |
| 2580 | setTimeout(function(){ |
| 2581 | resolve('promise 1'); |
| 2582 | }, 200); |
| 2583 | }); |
| 2584 | |
| 2585 | let promise2 = new Promise(function(resolve, reject){ |
| 2586 | setTimeout(function(){ |
| 2587 | resolve('promise 2'); |
| 2588 | }, 100); |
| 2589 | }); |
| 2590 | |
| 2591 | Promise.race([promise1, promise2]).then(function(result){ |
| 2592 | // result === 'promise 2' because it was resolved before promise1 |
| 2593 | // was resolved. |
| 2594 | }); |
| 2595 | ``` |
| 2596 | |
| 2597 | `Promise.race` is deterministic in that only the state of the first |
| 2598 | settled promise matters. For example, even if other promises given to the |
| 2599 | `promises` array argument are resolved, but the first settled promise has |
| 2600 | become rejected before the other promises became fulfilled, the returned |
| 2601 | promise will become rejected: |
| 2602 | |
| 2603 | ```javascript |
| 2604 | let promise1 = new Promise(function(resolve, reject){ |
| 2605 | setTimeout(function(){ |
| 2606 | resolve('promise 1'); |
| 2607 | }, 200); |
| 2608 | }); |
| 2609 | |
| 2610 | let promise2 = new Promise(function(resolve, reject){ |
| 2611 | setTimeout(function(){ |
| 2612 | reject(new Error('promise 2')); |
| 2613 | }, 100); |
| 2614 | }); |
| 2615 | |
| 2616 | Promise.race([promise1, promise2]).then(function(result){ |
| 2617 | // Code here never runs |
| 2618 | }, function(reason){ |
| 2619 | // reason.message === 'promise 2' because promise 2 became rejected before |
| 2620 | // promise 1 became fulfilled |
| 2621 | }); |
| 2622 | ``` |
| 2623 | |
| 2624 | An example real-world use case is implementing timeouts: |
| 2625 | |
| 2626 | ```javascript |
| 2627 | Promise.race([ajax('foo.json'), timeout(5000)]) |
| 2628 | ``` |
| 2629 | |
| 2630 | @method race |
| 2631 | @static |
| 2632 | @param {Array} promises array of promises to observe |
| 2633 | Useful for tooling. |
| 2634 | @return {Promise} a promise which settles in the same way as the first passed |
| 2635 | promise to settle. |
| 2636 | */ |
| 2637 | |
| 2638 | |
| 2639 | function race(entries) { |
| 2640 | /*jshint validthis:true */ |
| 2641 | var Constructor = this; |
| 2642 | |
| 2643 | if (!isArray(entries)) { |
| 2644 | return new Constructor(function (_, reject) { |
| 2645 | return reject(new TypeError('You must pass an array to race.')); |
| 2646 | }); |
| 2647 | } else { |
| 2648 | return new Constructor(function (resolve, reject) { |
| 2649 | var length = entries.length; |
| 2650 | |
| 2651 | for (var i = 0; i < length; i++) { |
| 2652 | Constructor.resolve(entries[i]).then(resolve, reject); |
| 2653 | } |
| 2654 | }); |
| 2655 | } |
| 2656 | } |
| 2657 | /** |
| 2658 | `Promise.reject` returns a promise rejected with the passed `reason`. |
| 2659 | It is shorthand for the following: |
| 2660 | |
| 2661 | ```javascript |
| 2662 | let promise = new Promise(function(resolve, reject){ |
| 2663 | reject(new Error('WHOOPS')); |
| 2664 | }); |
| 2665 | |
| 2666 | promise.then(function(value){ |
| 2667 | // Code here doesn't run because the promise is rejected! |
| 2668 | }, function(reason){ |
| 2669 | // reason.message === 'WHOOPS' |
| 2670 | }); |
| 2671 | ``` |
| 2672 | |
| 2673 | Instead of writing the above, your code now simply becomes the following: |
| 2674 | |
| 2675 | ```javascript |
| 2676 | let promise = Promise.reject(new Error('WHOOPS')); |
| 2677 | |
| 2678 | promise.then(function(value){ |
| 2679 | // Code here doesn't run because the promise is rejected! |
| 2680 | }, function(reason){ |
| 2681 | // reason.message === 'WHOOPS' |
| 2682 | }); |
| 2683 | ``` |
| 2684 | |
| 2685 | @method reject |
| 2686 | @static |
| 2687 | @param {Any} reason value that the returned promise will be rejected with. |
| 2688 | Useful for tooling. |
| 2689 | @return {Promise} a promise rejected with the given `reason`. |
| 2690 | */ |
| 2691 | |
| 2692 | |
| 2693 | function reject(reason) { |
| 2694 | /*jshint validthis:true */ |
| 2695 | var Constructor = this; |
| 2696 | var promise = new Constructor(noop); |
| 2697 | |
| 2698 | _reject(promise, reason); |
| 2699 | |
| 2700 | return promise; |
| 2701 | } |
| 2702 | |
| 2703 | function needsResolver() { |
| 2704 | throw new TypeError('You must pass a resolver function as the first argument to the promise constructor'); |
| 2705 | } |
| 2706 | |
| 2707 | function needsNew() { |
| 2708 | throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function."); |
| 2709 | } |
| 2710 | /** |
| 2711 | Promise objects represent the eventual result of an asynchronous operation. The |
| 2712 | primary way of interacting with a promise is through its `then` method, which |
| 2713 | registers callbacks to receive either a promise's eventual value or the reason |
| 2714 | why the promise cannot be fulfilled. |
| 2715 | |
| 2716 | Terminology |
| 2717 | ----------- |
| 2718 | |
| 2719 | - `promise` is an object or function with a `then` method whose behavior conforms to this specification. |
| 2720 | - `thenable` is an object or function that defines a `then` method. |
| 2721 | - `value` is any legal JavaScript value (including undefined, a thenable, or a promise). |
| 2722 | - `exception` is a value that is thrown using the throw statement. |
| 2723 | - `reason` is a value that indicates why a promise was rejected. |
| 2724 | - `settled` the final resting state of a promise, fulfilled or rejected. |
| 2725 | |
| 2726 | A promise can be in one of three states: pending, fulfilled, or rejected. |
| 2727 | |
| 2728 | Promises that are fulfilled have a fulfillment value and are in the fulfilled |
| 2729 | state. Promises that are rejected have a rejection reason and are in the |
| 2730 | rejected state. A fulfillment value is never a thenable. |
| 2731 | |
| 2732 | Promises can also be said to *resolve* a value. If this value is also a |
| 2733 | promise, then the original promise's settled state will match the value's |
| 2734 | settled state. So a promise that *resolves* a promise that rejects will |
| 2735 | itself reject, and a promise that *resolves* a promise that fulfills will |
| 2736 | itself fulfill. |
| 2737 | |
| 2738 | |
| 2739 | Basic Usage: |
| 2740 | ------------ |
| 2741 | |
| 2742 | ```js |
| 2743 | let promise = new Promise(function(resolve, reject) { |
| 2744 | // on success |
| 2745 | resolve(value); |
| 2746 | |
| 2747 | // on failure |
| 2748 | reject(reason); |
| 2749 | }); |
| 2750 | |
| 2751 | promise.then(function(value) { |
| 2752 | // on fulfillment |
| 2753 | }, function(reason) { |
| 2754 | // on rejection |
| 2755 | }); |
| 2756 | ``` |
| 2757 | |
| 2758 | Advanced Usage: |
| 2759 | --------------- |
| 2760 | |
| 2761 | Promises shine when abstracting away asynchronous interactions such as |
| 2762 | `XMLHttpRequest`s. |
| 2763 | |
| 2764 | ```js |
| 2765 | function getJSON(url) { |
| 2766 | return new Promise(function(resolve, reject){ |
| 2767 | let xhr = new XMLHttpRequest(); |
| 2768 | |
| 2769 | xhr.open('GET', url); |
| 2770 | xhr.onreadystatechange = handler; |
| 2771 | xhr.responseType = 'json'; |
| 2772 | xhr.setRequestHeader('Accept', 'application/json'); |
| 2773 | xhr.send(); |
| 2774 | |
| 2775 | function handler() { |
| 2776 | if (this.readyState === this.DONE) { |
| 2777 | if (this.status === 200) { |
| 2778 | resolve(this.response); |
| 2779 | } else { |
| 2780 | reject(new Error('getJSON: `' + url + '` failed with status: [' + this.status + ']')); |
| 2781 | } |
| 2782 | } |
| 2783 | }; |
| 2784 | }); |
| 2785 | } |
| 2786 | |
| 2787 | getJSON('/posts.json').then(function(json) { |
| 2788 | // on fulfillment |
| 2789 | }, function(reason) { |
| 2790 | // on rejection |
| 2791 | }); |
| 2792 | ``` |
| 2793 | |
| 2794 | Unlike callbacks, promises are great composable primitives. |
| 2795 | |
| 2796 | ```js |
| 2797 | Promise.all([ |
| 2798 | getJSON('/posts'), |
| 2799 | getJSON('/comments') |
| 2800 | ]).then(function(values){ |
| 2801 | values[0] // => postsJSON |
| 2802 | values[1] // => commentsJSON |
| 2803 | |
| 2804 | return values; |
| 2805 | }); |
| 2806 | ``` |
| 2807 | |
| 2808 | @class Promise |
| 2809 | @param {function} resolver |
| 2810 | Useful for tooling. |
| 2811 | @constructor |
| 2812 | */ |
| 2813 | |
| 2814 | |
| 2815 | function Promise(resolver) { |
| 2816 | this[PROMISE_ID] = nextId(); |
| 2817 | this._result = this._state = undefined; |
| 2818 | this._subscribers = []; |
| 2819 | |
| 2820 | if (noop !== resolver) { |
| 2821 | typeof resolver !== 'function' && needsResolver(); |
| 2822 | this instanceof Promise ? initializePromise(this, resolver) : needsNew(); |
| 2823 | } |
| 2824 | } |
| 2825 | |
| 2826 | Promise.all = all; |
| 2827 | Promise.race = race; |
| 2828 | Promise.resolve = resolve; |
| 2829 | Promise.reject = reject; |
| 2830 | Promise._setScheduler = setScheduler; |
| 2831 | Promise._setAsap = setAsap; |
| 2832 | Promise._asap = asap; |
| 2833 | Promise.prototype = { |
| 2834 | constructor: Promise, |
| 2835 | |
| 2836 | /** |
| 2837 | The primary way of interacting with a promise is through its `then` method, |
| 2838 | which registers callbacks to receive either a promise's eventual value or the |
| 2839 | reason why the promise cannot be fulfilled. |
| 2840 | |
| 2841 | ```js |
| 2842 | findUser().then(function(user){ |
| 2843 | // user is available |
| 2844 | }, function(reason){ |
| 2845 | // user is unavailable, and you are given the reason why |
| 2846 | }); |
| 2847 | ``` |
| 2848 | |
| 2849 | Chaining |
| 2850 | -------- |
| 2851 | |
| 2852 | The return value of `then` is itself a promise. This second, 'downstream' |
| 2853 | promise is resolved with the return value of the first promise's fulfillment |
| 2854 | or rejection handler, or rejected if the handler throws an exception. |
| 2855 | |
| 2856 | ```js |
| 2857 | findUser().then(function (user) { |
| 2858 | return user.name; |
| 2859 | }, function (reason) { |
| 2860 | return 'default name'; |
| 2861 | }).then(function (userName) { |
| 2862 | // If `findUser` fulfilled, `userName` will be the user's name, otherwise it |
| 2863 | // will be `'default name'` |
| 2864 | }); |
| 2865 | |
| 2866 | findUser().then(function (user) { |
| 2867 | throw new Error('Found user, but still unhappy'); |
| 2868 | }, function (reason) { |
| 2869 | throw new Error('`findUser` rejected and we're unhappy'); |
| 2870 | }).then(function (value) { |
| 2871 | // never reached |
| 2872 | }, function (reason) { |
| 2873 | // if `findUser` fulfilled, `reason` will be 'Found user, but still unhappy'. |
| 2874 | // If `findUser` rejected, `reason` will be '`findUser` rejected and we're unhappy'. |
| 2875 | }); |
| 2876 | ``` |
| 2877 | If the downstream promise does not specify a rejection handler, rejection reasons will be propagated further downstream. |
| 2878 | |
| 2879 | ```js |
| 2880 | findUser().then(function (user) { |
| 2881 | throw new PedagogicalException('Upstream error'); |
| 2882 | }).then(function (value) { |
| 2883 | // never reached |
| 2884 | }).then(function (value) { |
| 2885 | // never reached |
| 2886 | }, function (reason) { |
| 2887 | // The `PedgagocialException` is propagated all the way down to here |
| 2888 | }); |
| 2889 | ``` |
| 2890 | |
| 2891 | Assimilation |
| 2892 | ------------ |
| 2893 | |
| 2894 | Sometimes the value you want to propagate to a downstream promise can only be |
| 2895 | retrieved asynchronously. This can be achieved by returning a promise in the |
| 2896 | fulfillment or rejection handler. The downstream promise will then be pending |
| 2897 | until the returned promise is settled. This is called *assimilation*. |
| 2898 | |
| 2899 | ```js |
| 2900 | findUser().then(function (user) { |
| 2901 | return findCommentsByAuthor(user); |
| 2902 | }).then(function (comments) { |
| 2903 | // The user's comments are now available |
| 2904 | }); |
| 2905 | ``` |
| 2906 | |
| 2907 | If the assimliated promise rejects, then the downstream promise will also reject. |
| 2908 | |
| 2909 | ```js |
| 2910 | findUser().then(function (user) { |
| 2911 | return findCommentsByAuthor(user); |
| 2912 | }).then(function (comments) { |
| 2913 | // If `findCommentsByAuthor` fulfills, we'll have the value here |
| 2914 | }, function (reason) { |
| 2915 | // If `findCommentsByAuthor` rejects, we'll have the reason here |
| 2916 | }); |
| 2917 | ``` |
| 2918 | |
| 2919 | Simple Example |
| 2920 | -------------- |
| 2921 | |
| 2922 | Synchronous Example |
| 2923 | |
| 2924 | ```javascript |
| 2925 | let result; |
| 2926 | |
| 2927 | try { |
| 2928 | result = findResult(); |
| 2929 | // success |
| 2930 | } catch(reason) { |
| 2931 | // failure |
| 2932 | } |
| 2933 | ``` |
| 2934 | |
| 2935 | Errback Example |
| 2936 | |
| 2937 | ```js |
| 2938 | findResult(function(result, err){ |
| 2939 | if (err) { |
| 2940 | // failure |
| 2941 | } else { |
| 2942 | // success |
| 2943 | } |
| 2944 | }); |
| 2945 | ``` |
| 2946 | |
| 2947 | Promise Example; |
| 2948 | |
| 2949 | ```javascript |
| 2950 | findResult().then(function(result){ |
| 2951 | // success |
| 2952 | }, function(reason){ |
| 2953 | // failure |
| 2954 | }); |
| 2955 | ``` |
| 2956 | |
| 2957 | Advanced Example |
| 2958 | -------------- |
| 2959 | |
| 2960 | Synchronous Example |
| 2961 | |
| 2962 | ```javascript |
| 2963 | let author, books; |
| 2964 | |
| 2965 | try { |
| 2966 | author = findAuthor(); |
| 2967 | books = findBooksByAuthor(author); |
| 2968 | // success |
| 2969 | } catch(reason) { |
| 2970 | // failure |
| 2971 | } |
| 2972 | ``` |
| 2973 | |
| 2974 | Errback Example |
| 2975 | |
| 2976 | ```js |
| 2977 | |
| 2978 | function foundBooks(books) { |
| 2979 | |
| 2980 | } |
| 2981 | |
| 2982 | function failure(reason) { |
| 2983 | |
| 2984 | } |
| 2985 | |
| 2986 | findAuthor(function(author, err){ |
| 2987 | if (err) { |
| 2988 | failure(err); |
| 2989 | // failure |
| 2990 | } else { |
| 2991 | try { |
| 2992 | findBoooksByAuthor(author, function(books, err) { |
| 2993 | if (err) { |
| 2994 | failure(err); |
| 2995 | } else { |
| 2996 | try { |
| 2997 | foundBooks(books); |
| 2998 | } catch(reason) { |
| 2999 | failure(reason); |
| 3000 | } |
| 3001 | } |
| 3002 | }); |
| 3003 | } catch(error) { |
| 3004 | failure(err); |
| 3005 | } |
| 3006 | // success |
| 3007 | } |
| 3008 | }); |
| 3009 | ``` |
| 3010 | |
| 3011 | Promise Example; |
| 3012 | |
| 3013 | ```javascript |
| 3014 | findAuthor(). |
| 3015 | then(findBooksByAuthor). |
| 3016 | then(function(books){ |
| 3017 | // found books |
| 3018 | }).catch(function(reason){ |
| 3019 | // something went wrong |
| 3020 | }); |
| 3021 | ``` |
| 3022 | |
| 3023 | @method then |
| 3024 | @param {Function} onFulfilled |
| 3025 | @param {Function} onRejected |
| 3026 | Useful for tooling. |
| 3027 | @return {Promise} |
| 3028 | */ |
| 3029 | then: then, |
| 3030 | |
| 3031 | /** |
| 3032 | `catch` is simply sugar for `then(undefined, onRejection)` which makes it the same |
| 3033 | as the catch block of a try/catch statement. |
| 3034 | |
| 3035 | ```js |
| 3036 | function findAuthor(){ |
| 3037 | throw new Error('couldn't find that author'); |
| 3038 | } |
| 3039 | |
| 3040 | // synchronous |
| 3041 | try { |
| 3042 | findAuthor(); |
| 3043 | } catch(reason) { |
| 3044 | // something went wrong |
| 3045 | } |
| 3046 | |
| 3047 | // async with promises |
| 3048 | findAuthor().catch(function(reason){ |
| 3049 | // something went wrong |
| 3050 | }); |
| 3051 | ``` |
| 3052 | |
| 3053 | @method catch |
| 3054 | @param {Function} onRejection |
| 3055 | Useful for tooling. |
| 3056 | @return {Promise} |
| 3057 | */ |
| 3058 | 'catch': function _catch(onRejection) { |
| 3059 | return this.then(null, onRejection); |
| 3060 | } |
| 3061 | }; |
| 3062 | |
| 3063 | function polyfill() { |
| 3064 | var local = undefined; |
| 3065 | |
| 3066 | if (typeof global !== 'undefined') { |
| 3067 | local = global; |
| 3068 | } else if (typeof self !== 'undefined') { |
| 3069 | local = self; |
| 3070 | } else { |
| 3071 | try { |
| 3072 | local = Function('return this')(); |
| 3073 | } catch (e) { |
| 3074 | throw new Error('polyfill failed because global object is unavailable in this environment'); |
| 3075 | } |
| 3076 | } |
| 3077 | |
| 3078 | var P = local.Promise; |
| 3079 | |
| 3080 | if (P) { |
| 3081 | var promiseToString = null; |
| 3082 | |
| 3083 | try { |
| 3084 | promiseToString = Object.prototype.toString.call(P.resolve()); |
| 3085 | } catch (e) {// silently ignored |
| 3086 | } |
| 3087 | |
| 3088 | if (promiseToString === '[object Promise]' && !P.cast) { |
| 3089 | return; |
| 3090 | } |
| 3091 | } |
| 3092 | |
| 3093 | local.Promise = Promise; |
| 3094 | } |
| 3095 | |
| 3096 | polyfill(); // Strange compat.. |
| 3097 | |
| 3098 | Promise.polyfill = polyfill; |
| 3099 | Promise.Promise = Promise; |
| 3100 | return Promise; |
| 3101 | }); |
| 3102 | /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../process/browser.js */ "./node_modules/process/browser.js"), __webpack_require__(/*! ./../../webpack/buildin/global.js */ "./node_modules/webpack/buildin/global.js"))) |
| 3103 | |
| 3104 | /***/ }), |
| 3105 | |
| 3106 | /***/ "./node_modules/process/browser.js": |
| 3107 | /*!*****************************************!*\ |
| 3108 | !*** ./node_modules/process/browser.js ***! |
| 3109 | \*****************************************/ |
| 3110 | /*! no static exports found */ |
| 3111 | /***/ (function(module, exports) { |
| 3112 | |
| 3113 | // shim for using process in browser |
| 3114 | var process = module.exports = {}; // cached from whatever global is present so that test runners that stub it |
| 3115 | // don't break things. But we need to wrap it in a try catch in case it is |
| 3116 | // wrapped in strict mode code which doesn't define any globals. It's inside a |
| 3117 | // function because try/catches deoptimize in certain engines. |
| 3118 | |
| 3119 | var cachedSetTimeout; |
| 3120 | var cachedClearTimeout; |
| 3121 | |
| 3122 | function defaultSetTimout() { |
| 3123 | throw new Error('setTimeout has not been defined'); |
| 3124 | } |
| 3125 | |
| 3126 | function defaultClearTimeout() { |
| 3127 | throw new Error('clearTimeout has not been defined'); |
| 3128 | } |
| 3129 | |
| 3130 | (function () { |
| 3131 | try { |
| 3132 | if (typeof setTimeout === 'function') { |
| 3133 | cachedSetTimeout = setTimeout; |
| 3134 | } else { |
| 3135 | cachedSetTimeout = defaultSetTimout; |
| 3136 | } |
| 3137 | } catch (e) { |
| 3138 | cachedSetTimeout = defaultSetTimout; |
| 3139 | } |
| 3140 | |
| 3141 | try { |
| 3142 | if (typeof clearTimeout === 'function') { |
| 3143 | cachedClearTimeout = clearTimeout; |
| 3144 | } else { |
| 3145 | cachedClearTimeout = defaultClearTimeout; |
| 3146 | } |
| 3147 | } catch (e) { |
| 3148 | cachedClearTimeout = defaultClearTimeout; |
| 3149 | } |
| 3150 | })(); |
| 3151 | |
| 3152 | function runTimeout(fun) { |
| 3153 | if (cachedSetTimeout === setTimeout) { |
| 3154 | //normal enviroments in sane situations |
| 3155 | return setTimeout(fun, 0); |
| 3156 | } // if setTimeout wasn't available but was latter defined |
| 3157 | |
| 3158 | |
| 3159 | if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) { |
| 3160 | cachedSetTimeout = setTimeout; |
| 3161 | return setTimeout(fun, 0); |
| 3162 | } |
| 3163 | |
| 3164 | try { |
| 3165 | // when when somebody has screwed with setTimeout but no I.E. maddness |
| 3166 | return cachedSetTimeout(fun, 0); |
| 3167 | } catch (e) { |
| 3168 | try { |
| 3169 | // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally |
| 3170 | return cachedSetTimeout.call(null, fun, 0); |
| 3171 | } catch (e) { |
| 3172 | // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error |
| 3173 | return cachedSetTimeout.call(this, fun, 0); |
| 3174 | } |
| 3175 | } |
| 3176 | } |
| 3177 | |
| 3178 | function runClearTimeout(marker) { |
| 3179 | if (cachedClearTimeout === clearTimeout) { |
| 3180 | //normal enviroments in sane situations |
| 3181 | return clearTimeout(marker); |
| 3182 | } // if clearTimeout wasn't available but was latter defined |
| 3183 | |
| 3184 | |
| 3185 | if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) { |
| 3186 | cachedClearTimeout = clearTimeout; |
| 3187 | return clearTimeout(marker); |
| 3188 | } |
| 3189 | |
| 3190 | try { |
| 3191 | // when when somebody has screwed with setTimeout but no I.E. maddness |
| 3192 | return cachedClearTimeout(marker); |
| 3193 | } catch (e) { |
| 3194 | try { |
| 3195 | // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally |
| 3196 | return cachedClearTimeout.call(null, marker); |
| 3197 | } catch (e) { |
| 3198 | // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error. |
| 3199 | // Some versions of I.E. have different rules for clearTimeout vs setTimeout |
| 3200 | return cachedClearTimeout.call(this, marker); |
| 3201 | } |
| 3202 | } |
| 3203 | } |
| 3204 | |
| 3205 | var queue = []; |
| 3206 | var draining = false; |
| 3207 | var currentQueue; |
| 3208 | var queueIndex = -1; |
| 3209 | |
| 3210 | function cleanUpNextTick() { |
| 3211 | if (!draining || !currentQueue) { |
| 3212 | return; |
| 3213 | } |
| 3214 | |
| 3215 | draining = false; |
| 3216 | |
| 3217 | if (currentQueue.length) { |
| 3218 | queue = currentQueue.concat(queue); |
| 3219 | } else { |
| 3220 | queueIndex = -1; |
| 3221 | } |
| 3222 | |
| 3223 | if (queue.length) { |
| 3224 | drainQueue(); |
| 3225 | } |
| 3226 | } |
| 3227 | |
| 3228 | function drainQueue() { |
| 3229 | if (draining) { |
| 3230 | return; |
| 3231 | } |
| 3232 | |
| 3233 | var timeout = runTimeout(cleanUpNextTick); |
| 3234 | draining = true; |
| 3235 | var len = queue.length; |
| 3236 | |
| 3237 | while (len) { |
| 3238 | currentQueue = queue; |
| 3239 | queue = []; |
| 3240 | |
| 3241 | while (++queueIndex < len) { |
| 3242 | if (currentQueue) { |
| 3243 | currentQueue[queueIndex].run(); |
| 3244 | } |
| 3245 | } |
| 3246 | |
| 3247 | queueIndex = -1; |
| 3248 | len = queue.length; |
| 3249 | } |
| 3250 | |
| 3251 | currentQueue = null; |
| 3252 | draining = false; |
| 3253 | runClearTimeout(timeout); |
| 3254 | } |
| 3255 | |
| 3256 | process.nextTick = function (fun) { |
| 3257 | var args = new Array(arguments.length - 1); |
| 3258 | |
| 3259 | if (arguments.length > 1) { |
| 3260 | for (var i = 1; i < arguments.length; i++) { |
| 3261 | args[i - 1] = arguments[i]; |
| 3262 | } |
| 3263 | } |
| 3264 | |
| 3265 | queue.push(new Item(fun, args)); |
| 3266 | |
| 3267 | if (queue.length === 1 && !draining) { |
| 3268 | runTimeout(drainQueue); |
| 3269 | } |
| 3270 | }; // v8 likes predictible objects |
| 3271 | |
| 3272 | |
| 3273 | function Item(fun, array) { |
| 3274 | this.fun = fun; |
| 3275 | this.array = array; |
| 3276 | } |
| 3277 | |
| 3278 | Item.prototype.run = function () { |
| 3279 | this.fun.apply(null, this.array); |
| 3280 | }; |
| 3281 | |
| 3282 | process.title = 'browser'; |
| 3283 | process.browser = true; |
| 3284 | process.env = {}; |
| 3285 | process.argv = []; |
| 3286 | process.version = ''; // empty string to avoid regexp issues |
| 3287 | |
| 3288 | process.versions = {}; |
| 3289 | |
| 3290 | function noop() {} |
| 3291 | |
| 3292 | process.on = noop; |
| 3293 | process.addListener = noop; |
| 3294 | process.once = noop; |
| 3295 | process.off = noop; |
| 3296 | process.removeListener = noop; |
| 3297 | process.removeAllListeners = noop; |
| 3298 | process.emit = noop; |
| 3299 | process.prependListener = noop; |
| 3300 | process.prependOnceListener = noop; |
| 3301 | |
| 3302 | process.listeners = function (name) { |
| 3303 | return []; |
| 3304 | }; |
| 3305 | |
| 3306 | process.binding = function (name) { |
| 3307 | throw new Error('process.binding is not supported'); |
| 3308 | }; |
| 3309 | |
| 3310 | process.cwd = function () { |
| 3311 | return '/'; |
| 3312 | }; |
| 3313 | |
| 3314 | process.chdir = function (dir) { |
| 3315 | throw new Error('process.chdir is not supported'); |
| 3316 | }; |
| 3317 | |
| 3318 | process.umask = function () { |
| 3319 | return 0; |
| 3320 | }; |
| 3321 | |
| 3322 | /***/ }), |
| 3323 | |
| 3324 | /***/ "./node_modules/regenerator-runtime/runtime.js": |
| 3325 | /*!*****************************************************!*\ |
| 3326 | !*** ./node_modules/regenerator-runtime/runtime.js ***! |
| 3327 | \*****************************************************/ |
| 3328 | /*! no static exports found */ |
| 3329 | /***/ (function(module, exports, __webpack_require__) { |
| 3330 | |
| 3331 | /* WEBPACK VAR INJECTION */(function(module) {function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } |
| 3332 | |
| 3333 | /** |
| 3334 | * Copyright (c) 2014-present, Facebook, Inc. |
| 3335 | * |
| 3336 | * This source code is licensed under the MIT license found in the |
| 3337 | * LICENSE file in the root directory of this source tree. |
| 3338 | */ |
| 3339 | var runtime = function (exports) { |
| 3340 | "use strict"; |
| 3341 | |
| 3342 | var Op = Object.prototype; |
| 3343 | var hasOwn = Op.hasOwnProperty; |
| 3344 | var undefined; // More compressible than void 0. |
| 3345 | |
| 3346 | var $Symbol = typeof Symbol === "function" ? Symbol : {}; |
| 3347 | var iteratorSymbol = $Symbol.iterator || "@@iterator"; |
| 3348 | var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator"; |
| 3349 | var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; |
| 3350 | |
| 3351 | function wrap(innerFn, outerFn, self, tryLocsList) { |
| 3352 | // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator. |
| 3353 | var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator; |
| 3354 | var generator = Object.create(protoGenerator.prototype); |
| 3355 | var context = new Context(tryLocsList || []); // The ._invoke method unifies the implementations of the .next, |
| 3356 | // .throw, and .return methods. |
| 3357 | |
| 3358 | generator._invoke = makeInvokeMethod(innerFn, self, context); |
| 3359 | return generator; |
| 3360 | } |
| 3361 | |
| 3362 | exports.wrap = wrap; // Try/catch helper to minimize deoptimizations. Returns a completion |
| 3363 | // record like context.tryEntries[i].completion. This interface could |
| 3364 | // have been (and was previously) designed to take a closure to be |
| 3365 | // invoked without arguments, but in all the cases we care about we |
| 3366 | // already have an existing method we want to call, so there's no need |
| 3367 | // to create a new function object. We can even get away with assuming |
| 3368 | // the method takes exactly one argument, since that happens to be true |
| 3369 | // in every case, so we don't have to touch the arguments object. The |
| 3370 | // only additional allocation required is the completion record, which |
| 3371 | // has a stable shape and so hopefully should be cheap to allocate. |
| 3372 | |
| 3373 | function tryCatch(fn, obj, arg) { |
| 3374 | try { |
| 3375 | return { |
| 3376 | type: "normal", |
| 3377 | arg: fn.call(obj, arg) |
| 3378 | }; |
| 3379 | } catch (err) { |
| 3380 | return { |
| 3381 | type: "throw", |
| 3382 | arg: err |
| 3383 | }; |
| 3384 | } |
| 3385 | } |
| 3386 | |
| 3387 | var GenStateSuspendedStart = "suspendedStart"; |
| 3388 | var GenStateSuspendedYield = "suspendedYield"; |
| 3389 | var GenStateExecuting = "executing"; |
| 3390 | var GenStateCompleted = "completed"; // Returning this object from the innerFn has the same effect as |
| 3391 | // breaking out of the dispatch switch statement. |
| 3392 | |
| 3393 | var ContinueSentinel = {}; // Dummy constructor functions that we use as the .constructor and |
| 3394 | // .constructor.prototype properties for functions that return Generator |
| 3395 | // objects. For full spec compliance, you may wish to configure your |
| 3396 | // minifier not to mangle the names of these two functions. |
| 3397 | |
| 3398 | function Generator() {} |
| 3399 | |
| 3400 | function GeneratorFunction() {} |
| 3401 | |
| 3402 | function GeneratorFunctionPrototype() {} // This is a polyfill for %IteratorPrototype% for environments that |
| 3403 | // don't natively support it. |
| 3404 | |
| 3405 | |
| 3406 | var IteratorPrototype = {}; |
| 3407 | |
| 3408 | IteratorPrototype[iteratorSymbol] = function () { |
| 3409 | return this; |
| 3410 | }; |
| 3411 | |
| 3412 | var getProto = Object.getPrototypeOf; |
| 3413 | var NativeIteratorPrototype = getProto && getProto(getProto(values([]))); |
| 3414 | |
| 3415 | if (NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) { |
| 3416 | // This environment has a native %IteratorPrototype%; use it instead |
| 3417 | // of the polyfill. |
| 3418 | IteratorPrototype = NativeIteratorPrototype; |
| 3419 | } |
| 3420 | |
| 3421 | var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); |
| 3422 | GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype; |
| 3423 | GeneratorFunctionPrototype.constructor = GeneratorFunction; |
| 3424 | GeneratorFunctionPrototype[toStringTagSymbol] = GeneratorFunction.displayName = "GeneratorFunction"; // Helper for defining the .next, .throw, and .return methods of the |
| 3425 | // Iterator interface in terms of a single ._invoke method. |
| 3426 | |
| 3427 | function defineIteratorMethods(prototype) { |
| 3428 | ["next", "throw", "return"].forEach(function (method) { |
| 3429 | prototype[method] = function (arg) { |
| 3430 | return this._invoke(method, arg); |
| 3431 | }; |
| 3432 | }); |
| 3433 | } |
| 3434 | |
| 3435 | exports.isGeneratorFunction = function (genFun) { |
| 3436 | var ctor = typeof genFun === "function" && genFun.constructor; |
| 3437 | return ctor ? ctor === GeneratorFunction || // For the native GeneratorFunction constructor, the best we can |
| 3438 | // do is to check its .name property. |
| 3439 | (ctor.displayName || ctor.name) === "GeneratorFunction" : false; |
| 3440 | }; |
| 3441 | |
| 3442 | exports.mark = function (genFun) { |
| 3443 | if (Object.setPrototypeOf) { |
| 3444 | Object.setPrototypeOf(genFun, GeneratorFunctionPrototype); |
| 3445 | } else { |
| 3446 | genFun.__proto__ = GeneratorFunctionPrototype; |
| 3447 | |
| 3448 | if (!(toStringTagSymbol in genFun)) { |
| 3449 | genFun[toStringTagSymbol] = "GeneratorFunction"; |
| 3450 | } |
| 3451 | } |
| 3452 | |
| 3453 | genFun.prototype = Object.create(Gp); |
| 3454 | return genFun; |
| 3455 | }; // Within the body of any async function, `await x` is transformed to |
| 3456 | // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test |
| 3457 | // `hasOwn.call(value, "__await")` to determine if the yielded value is |
| 3458 | // meant to be awaited. |
| 3459 | |
| 3460 | |
| 3461 | exports.awrap = function (arg) { |
| 3462 | return { |
| 3463 | __await: arg |
| 3464 | }; |
| 3465 | }; |
| 3466 | |
| 3467 | function AsyncIterator(generator, PromiseImpl) { |
| 3468 | function invoke(method, arg, resolve, reject) { |
| 3469 | var record = tryCatch(generator[method], generator, arg); |
| 3470 | |
| 3471 | if (record.type === "throw") { |
| 3472 | reject(record.arg); |
| 3473 | } else { |
| 3474 | var result = record.arg; |
| 3475 | var value = result.value; |
| 3476 | |
| 3477 | if (value && _typeof(value) === "object" && hasOwn.call(value, "__await")) { |
| 3478 | return PromiseImpl.resolve(value.__await).then(function (value) { |
| 3479 | invoke("next", value, resolve, reject); |
| 3480 | }, function (err) { |
| 3481 | invoke("throw", err, resolve, reject); |
| 3482 | }); |
| 3483 | } |
| 3484 | |
| 3485 | return PromiseImpl.resolve(value).then(function (unwrapped) { |
| 3486 | // When a yielded Promise is resolved, its final value becomes |
| 3487 | // the .value of the Promise<{value,done}> result for the |
| 3488 | // current iteration. |
| 3489 | result.value = unwrapped; |
| 3490 | resolve(result); |
| 3491 | }, function (error) { |
| 3492 | // If a rejected Promise was yielded, throw the rejection back |
| 3493 | // into the async generator function so it can be handled there. |
| 3494 | return invoke("throw", error, resolve, reject); |
| 3495 | }); |
| 3496 | } |
| 3497 | } |
| 3498 | |
| 3499 | var previousPromise; |
| 3500 | |
| 3501 | function enqueue(method, arg) { |
| 3502 | function callInvokeWithMethodAndArg() { |
| 3503 | return new PromiseImpl(function (resolve, reject) { |
| 3504 | invoke(method, arg, resolve, reject); |
| 3505 | }); |
| 3506 | } |
| 3507 | |
| 3508 | return previousPromise = // If enqueue has been called before, then we want to wait until |
| 3509 | // all previous Promises have been resolved before calling invoke, |
| 3510 | // so that results are always delivered in the correct order. If |
| 3511 | // enqueue has not been called before, then it is important to |
| 3512 | // call invoke immediately, without waiting on a callback to fire, |
| 3513 | // so that the async generator function has the opportunity to do |
| 3514 | // any necessary setup in a predictable way. This predictability |
| 3515 | // is why the Promise constructor synchronously invokes its |
| 3516 | // executor callback, and why async functions synchronously |
| 3517 | // execute code before the first await. Since we implement simple |
| 3518 | // async functions in terms of async generators, it is especially |
| 3519 | // important to get this right, even though it requires care. |
| 3520 | previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, // Avoid propagating failures to Promises returned by later |
| 3521 | // invocations of the iterator. |
| 3522 | callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); |
| 3523 | } // Define the unified helper method that is used to implement .next, |
| 3524 | // .throw, and .return (see defineIteratorMethods). |
| 3525 | |
| 3526 | |
| 3527 | this._invoke = enqueue; |
| 3528 | } |
| 3529 | |
| 3530 | defineIteratorMethods(AsyncIterator.prototype); |
| 3531 | |
| 3532 | AsyncIterator.prototype[asyncIteratorSymbol] = function () { |
| 3533 | return this; |
| 3534 | }; |
| 3535 | |
| 3536 | exports.AsyncIterator = AsyncIterator; // Note that simple async functions are implemented on top of |
| 3537 | // AsyncIterator objects; they just return a Promise for the value of |
| 3538 | // the final result produced by the iterator. |
| 3539 | |
| 3540 | exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { |
| 3541 | if (PromiseImpl === void 0) PromiseImpl = Promise; |
| 3542 | var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); |
| 3543 | return exports.isGeneratorFunction(outerFn) ? iter // If outerFn is a generator, return the full iterator. |
| 3544 | : iter.next().then(function (result) { |
| 3545 | return result.done ? result.value : iter.next(); |
| 3546 | }); |
| 3547 | }; |
| 3548 | |
| 3549 | function makeInvokeMethod(innerFn, self, context) { |
| 3550 | var state = GenStateSuspendedStart; |
| 3551 | return function invoke(method, arg) { |
| 3552 | if (state === GenStateExecuting) { |
| 3553 | throw new Error("Generator is already running"); |
| 3554 | } |
| 3555 | |
| 3556 | if (state === GenStateCompleted) { |
| 3557 | if (method === "throw") { |
| 3558 | throw arg; |
| 3559 | } // Be forgiving, per 25.3.3.3.3 of the spec: |
| 3560 | // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume |
| 3561 | |
| 3562 | |
| 3563 | return doneResult(); |
| 3564 | } |
| 3565 | |
| 3566 | context.method = method; |
| 3567 | context.arg = arg; |
| 3568 | |
| 3569 | while (true) { |
| 3570 | var delegate = context.delegate; |
| 3571 | |
| 3572 | if (delegate) { |
| 3573 | var delegateResult = maybeInvokeDelegate(delegate, context); |
| 3574 | |
| 3575 | if (delegateResult) { |
| 3576 | if (delegateResult === ContinueSentinel) continue; |
| 3577 | return delegateResult; |
| 3578 | } |
| 3579 | } |
| 3580 | |
| 3581 | if (context.method === "next") { |
| 3582 | // Setting context._sent for legacy support of Babel's |
| 3583 | // function.sent implementation. |
| 3584 | context.sent = context._sent = context.arg; |
| 3585 | } else if (context.method === "throw") { |
| 3586 | if (state === GenStateSuspendedStart) { |
| 3587 | state = GenStateCompleted; |
| 3588 | throw context.arg; |
| 3589 | } |
| 3590 | |
| 3591 | context.dispatchException(context.arg); |
| 3592 | } else if (context.method === "return") { |
| 3593 | context.abrupt("return", context.arg); |
| 3594 | } |
| 3595 | |
| 3596 | state = GenStateExecuting; |
| 3597 | var record = tryCatch(innerFn, self, context); |
| 3598 | |
| 3599 | if (record.type === "normal") { |
| 3600 | // If an exception is thrown from innerFn, we leave state === |
| 3601 | // GenStateExecuting and loop back for another invocation. |
| 3602 | state = context.done ? GenStateCompleted : GenStateSuspendedYield; |
| 3603 | |
| 3604 | if (record.arg === ContinueSentinel) { |
| 3605 | continue; |
| 3606 | } |
| 3607 | |
| 3608 | return { |
| 3609 | value: record.arg, |
| 3610 | done: context.done |
| 3611 | }; |
| 3612 | } else if (record.type === "throw") { |
| 3613 | state = GenStateCompleted; // Dispatch the exception by looping back around to the |
| 3614 | // context.dispatchException(context.arg) call above. |
| 3615 | |
| 3616 | context.method = "throw"; |
| 3617 | context.arg = record.arg; |
| 3618 | } |
| 3619 | } |
| 3620 | }; |
| 3621 | } // Call delegate.iterator[context.method](context.arg) and handle the |
| 3622 | // result, either by returning a { value, done } result from the |
| 3623 | // delegate iterator, or by modifying context.method and context.arg, |
| 3624 | // setting context.delegate to null, and returning the ContinueSentinel. |
| 3625 | |
| 3626 | |
| 3627 | function maybeInvokeDelegate(delegate, context) { |
| 3628 | var method = delegate.iterator[context.method]; |
| 3629 | |
| 3630 | if (method === undefined) { |
| 3631 | // A .throw or .return when the delegate iterator has no .throw |
| 3632 | // method always terminates the yield* loop. |
| 3633 | context.delegate = null; |
| 3634 | |
| 3635 | if (context.method === "throw") { |
| 3636 | // Note: ["return"] must be used for ES3 parsing compatibility. |
| 3637 | if (delegate.iterator["return"]) { |
| 3638 | // If the delegate iterator has a return method, give it a |
| 3639 | // chance to clean up. |
| 3640 | context.method = "return"; |
| 3641 | context.arg = undefined; |
| 3642 | maybeInvokeDelegate(delegate, context); |
| 3643 | |
| 3644 | if (context.method === "throw") { |
| 3645 | // If maybeInvokeDelegate(context) changed context.method from |
| 3646 | // "return" to "throw", let that override the TypeError below. |
| 3647 | return ContinueSentinel; |
| 3648 | } |
| 3649 | } |
| 3650 | |
| 3651 | context.method = "throw"; |
| 3652 | context.arg = new TypeError("The iterator does not provide a 'throw' method"); |
| 3653 | } |
| 3654 | |
| 3655 | return ContinueSentinel; |
| 3656 | } |
| 3657 | |
| 3658 | var record = tryCatch(method, delegate.iterator, context.arg); |
| 3659 | |
| 3660 | if (record.type === "throw") { |
| 3661 | context.method = "throw"; |
| 3662 | context.arg = record.arg; |
| 3663 | context.delegate = null; |
| 3664 | return ContinueSentinel; |
| 3665 | } |
| 3666 | |
| 3667 | var info = record.arg; |
| 3668 | |
| 3669 | if (!info) { |
| 3670 | context.method = "throw"; |
| 3671 | context.arg = new TypeError("iterator result is not an object"); |
| 3672 | context.delegate = null; |
| 3673 | return ContinueSentinel; |
| 3674 | } |
| 3675 | |
| 3676 | if (info.done) { |
| 3677 | // Assign the result of the finished delegate to the temporary |
| 3678 | // variable specified by delegate.resultName (see delegateYield). |
| 3679 | context[delegate.resultName] = info.value; // Resume execution at the desired location (see delegateYield). |
| 3680 | |
| 3681 | context.next = delegate.nextLoc; // If context.method was "throw" but the delegate handled the |
| 3682 | // exception, let the outer generator proceed normally. If |
| 3683 | // context.method was "next", forget context.arg since it has been |
| 3684 | // "consumed" by the delegate iterator. If context.method was |
| 3685 | // "return", allow the original .return call to continue in the |
| 3686 | // outer generator. |
| 3687 | |
| 3688 | if (context.method !== "return") { |
| 3689 | context.method = "next"; |
| 3690 | context.arg = undefined; |
| 3691 | } |
| 3692 | } else { |
| 3693 | // Re-yield the result returned by the delegate method. |
| 3694 | return info; |
| 3695 | } // The delegate iterator is finished, so forget it and continue with |
| 3696 | // the outer generator. |
| 3697 | |
| 3698 | |
| 3699 | context.delegate = null; |
| 3700 | return ContinueSentinel; |
| 3701 | } // Define Generator.prototype.{next,throw,return} in terms of the |
| 3702 | // unified ._invoke helper method. |
| 3703 | |
| 3704 | |
| 3705 | defineIteratorMethods(Gp); |
| 3706 | Gp[toStringTagSymbol] = "Generator"; // A Generator should always return itself as the iterator object when the |
| 3707 | // @@iterator function is called on it. Some browsers' implementations of the |
| 3708 | // iterator prototype chain incorrectly implement this, causing the Generator |
| 3709 | // object to not be returned from this call. This ensures that doesn't happen. |
| 3710 | // See https://github.com/facebook/regenerator/issues/274 for more details. |
| 3711 | |
| 3712 | Gp[iteratorSymbol] = function () { |
| 3713 | return this; |
| 3714 | }; |
| 3715 | |
| 3716 | Gp.toString = function () { |
| 3717 | return "[object Generator]"; |
| 3718 | }; |
| 3719 | |
| 3720 | function pushTryEntry(locs) { |
| 3721 | var entry = { |
| 3722 | tryLoc: locs[0] |
| 3723 | }; |
| 3724 | |
| 3725 | if (1 in locs) { |
| 3726 | entry.catchLoc = locs[1]; |
| 3727 | } |
| 3728 | |
| 3729 | if (2 in locs) { |
| 3730 | entry.finallyLoc = locs[2]; |
| 3731 | entry.afterLoc = locs[3]; |
| 3732 | } |
| 3733 | |
| 3734 | this.tryEntries.push(entry); |
| 3735 | } |
| 3736 | |
| 3737 | function resetTryEntry(entry) { |
| 3738 | var record = entry.completion || {}; |
| 3739 | record.type = "normal"; |
| 3740 | delete record.arg; |
| 3741 | entry.completion = record; |
| 3742 | } |
| 3743 | |
| 3744 | function Context(tryLocsList) { |
| 3745 | // The root entry object (effectively a try statement without a catch |
| 3746 | // or a finally block) gives us a place to store values thrown from |
| 3747 | // locations where there is no enclosing try statement. |
| 3748 | this.tryEntries = [{ |
| 3749 | tryLoc: "root" |
| 3750 | }]; |
| 3751 | tryLocsList.forEach(pushTryEntry, this); |
| 3752 | this.reset(true); |
| 3753 | } |
| 3754 | |
| 3755 | exports.keys = function (object) { |
| 3756 | var keys = []; |
| 3757 | |
| 3758 | for (var key in object) { |
| 3759 | keys.push(key); |
| 3760 | } |
| 3761 | |
| 3762 | keys.reverse(); // Rather than returning an object with a next method, we keep |
| 3763 | // things simple and return the next function itself. |
| 3764 | |
| 3765 | return function next() { |
| 3766 | while (keys.length) { |
| 3767 | var key = keys.pop(); |
| 3768 | |
| 3769 | if (key in object) { |
| 3770 | next.value = key; |
| 3771 | next.done = false; |
| 3772 | return next; |
| 3773 | } |
| 3774 | } // To avoid creating an additional object, we just hang the .value |
| 3775 | // and .done properties off the next function object itself. This |
| 3776 | // also ensures that the minifier will not anonymize the function. |
| 3777 | |
| 3778 | |
| 3779 | next.done = true; |
| 3780 | return next; |
| 3781 | }; |
| 3782 | }; |
| 3783 | |
| 3784 | function values(iterable) { |
| 3785 | if (iterable) { |
| 3786 | var iteratorMethod = iterable[iteratorSymbol]; |
| 3787 | |
| 3788 | if (iteratorMethod) { |
| 3789 | return iteratorMethod.call(iterable); |
| 3790 | } |
| 3791 | |
| 3792 | if (typeof iterable.next === "function") { |
| 3793 | return iterable; |
| 3794 | } |
| 3795 | |
| 3796 | if (!isNaN(iterable.length)) { |
| 3797 | var i = -1, |
| 3798 | next = function next() { |
| 3799 | while (++i < iterable.length) { |
| 3800 | if (hasOwn.call(iterable, i)) { |
| 3801 | next.value = iterable[i]; |
| 3802 | next.done = false; |
| 3803 | return next; |
| 3804 | } |
| 3805 | } |
| 3806 | |
| 3807 | next.value = undefined; |
| 3808 | next.done = true; |
| 3809 | return next; |
| 3810 | }; |
| 3811 | |
| 3812 | return next.next = next; |
| 3813 | } |
| 3814 | } // Return an iterator with no values. |
| 3815 | |
| 3816 | |
| 3817 | return { |
| 3818 | next: doneResult |
| 3819 | }; |
| 3820 | } |
| 3821 | |
| 3822 | exports.values = values; |
| 3823 | |
| 3824 | function doneResult() { |
| 3825 | return { |
| 3826 | value: undefined, |
| 3827 | done: true |
| 3828 | }; |
| 3829 | } |
| 3830 | |
| 3831 | Context.prototype = { |
| 3832 | constructor: Context, |
| 3833 | reset: function reset(skipTempReset) { |
| 3834 | this.prev = 0; |
| 3835 | this.next = 0; // Resetting context._sent for legacy support of Babel's |
| 3836 | // function.sent implementation. |
| 3837 | |
| 3838 | this.sent = this._sent = undefined; |
| 3839 | this.done = false; |
| 3840 | this.delegate = null; |
| 3841 | this.method = "next"; |
| 3842 | this.arg = undefined; |
| 3843 | this.tryEntries.forEach(resetTryEntry); |
| 3844 | |
| 3845 | if (!skipTempReset) { |
| 3846 | for (var name in this) { |
| 3847 | // Not sure about the optimal order of these conditions: |
| 3848 | if (name.charAt(0) === "t" && hasOwn.call(this, name) && !isNaN(+name.slice(1))) { |
| 3849 | this[name] = undefined; |
| 3850 | } |
| 3851 | } |
| 3852 | } |
| 3853 | }, |
| 3854 | stop: function stop() { |
| 3855 | this.done = true; |
| 3856 | var rootEntry = this.tryEntries[0]; |
| 3857 | var rootRecord = rootEntry.completion; |
| 3858 | |
| 3859 | if (rootRecord.type === "throw") { |
| 3860 | throw rootRecord.arg; |
| 3861 | } |
| 3862 | |
| 3863 | return this.rval; |
| 3864 | }, |
| 3865 | dispatchException: function dispatchException(exception) { |
| 3866 | if (this.done) { |
| 3867 | throw exception; |
| 3868 | } |
| 3869 | |
| 3870 | var context = this; |
| 3871 | |
| 3872 | function handle(loc, caught) { |
| 3873 | record.type = "throw"; |
| 3874 | record.arg = exception; |
| 3875 | context.next = loc; |
| 3876 | |
| 3877 | if (caught) { |
| 3878 | // If the dispatched exception was caught by a catch block, |
| 3879 | // then let that catch block handle the exception normally. |
| 3880 | context.method = "next"; |
| 3881 | context.arg = undefined; |
| 3882 | } |
| 3883 | |
| 3884 | return !!caught; |
| 3885 | } |
| 3886 | |
| 3887 | for (var i = this.tryEntries.length - 1; i >= 0; --i) { |
| 3888 | var entry = this.tryEntries[i]; |
| 3889 | var record = entry.completion; |
| 3890 | |
| 3891 | if (entry.tryLoc === "root") { |
| 3892 | // Exception thrown outside of any try block that could handle |
| 3893 | // it, so set the completion value of the entire function to |
| 3894 | // throw the exception. |
| 3895 | return handle("end"); |
| 3896 | } |
| 3897 | |
| 3898 | if (entry.tryLoc <= this.prev) { |
| 3899 | var hasCatch = hasOwn.call(entry, "catchLoc"); |
| 3900 | var hasFinally = hasOwn.call(entry, "finallyLoc"); |
| 3901 | |
| 3902 | if (hasCatch && hasFinally) { |
| 3903 | if (this.prev < entry.catchLoc) { |
| 3904 | return handle(entry.catchLoc, true); |
| 3905 | } else if (this.prev < entry.finallyLoc) { |
| 3906 | return handle(entry.finallyLoc); |
| 3907 | } |
| 3908 | } else if (hasCatch) { |
| 3909 | if (this.prev < entry.catchLoc) { |
| 3910 | return handle(entry.catchLoc, true); |
| 3911 | } |
| 3912 | } else if (hasFinally) { |
| 3913 | if (this.prev < entry.finallyLoc) { |
| 3914 | return handle(entry.finallyLoc); |
| 3915 | } |
| 3916 | } else { |
| 3917 | throw new Error("try statement without catch or finally"); |
| 3918 | } |
| 3919 | } |
| 3920 | } |
| 3921 | }, |
| 3922 | abrupt: function abrupt(type, arg) { |
| 3923 | for (var i = this.tryEntries.length - 1; i >= 0; --i) { |
| 3924 | var entry = this.tryEntries[i]; |
| 3925 | |
| 3926 | if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { |
| 3927 | var finallyEntry = entry; |
| 3928 | break; |
| 3929 | } |
| 3930 | } |
| 3931 | |
| 3932 | if (finallyEntry && (type === "break" || type === "continue") && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc) { |
| 3933 | // Ignore the finally entry if control is not jumping to a |
| 3934 | // location outside the try/catch block. |
| 3935 | finallyEntry = null; |
| 3936 | } |
| 3937 | |
| 3938 | var record = finallyEntry ? finallyEntry.completion : {}; |
| 3939 | record.type = type; |
| 3940 | record.arg = arg; |
| 3941 | |
| 3942 | if (finallyEntry) { |
| 3943 | this.method = "next"; |
| 3944 | this.next = finallyEntry.finallyLoc; |
| 3945 | return ContinueSentinel; |
| 3946 | } |
| 3947 | |
| 3948 | return this.complete(record); |
| 3949 | }, |
| 3950 | complete: function complete(record, afterLoc) { |
| 3951 | if (record.type === "throw") { |
| 3952 | throw record.arg; |
| 3953 | } |
| 3954 | |
| 3955 | if (record.type === "break" || record.type === "continue") { |
| 3956 | this.next = record.arg; |
| 3957 | } else if (record.type === "return") { |
| 3958 | this.rval = this.arg = record.arg; |
| 3959 | this.method = "return"; |
| 3960 | this.next = "end"; |
| 3961 | } else if (record.type === "normal" && afterLoc) { |
| 3962 | this.next = afterLoc; |
| 3963 | } |
| 3964 | |
| 3965 | return ContinueSentinel; |
| 3966 | }, |
| 3967 | finish: function finish(finallyLoc) { |
| 3968 | for (var i = this.tryEntries.length - 1; i >= 0; --i) { |
| 3969 | var entry = this.tryEntries[i]; |
| 3970 | |
| 3971 | if (entry.finallyLoc === finallyLoc) { |
| 3972 | this.complete(entry.completion, entry.afterLoc); |
| 3973 | resetTryEntry(entry); |
| 3974 | return ContinueSentinel; |
| 3975 | } |
| 3976 | } |
| 3977 | }, |
| 3978 | "catch": function _catch(tryLoc) { |
| 3979 | for (var i = this.tryEntries.length - 1; i >= 0; --i) { |
| 3980 | var entry = this.tryEntries[i]; |
| 3981 | |
| 3982 | if (entry.tryLoc === tryLoc) { |
| 3983 | var record = entry.completion; |
| 3984 | |
| 3985 | if (record.type === "throw") { |
| 3986 | var thrown = record.arg; |
| 3987 | resetTryEntry(entry); |
| 3988 | } |
| 3989 | |
| 3990 | return thrown; |
| 3991 | } |
| 3992 | } // The context.catch method must only be called with a location |
| 3993 | // argument that corresponds to a known catch block. |
| 3994 | |
| 3995 | |
| 3996 | throw new Error("illegal catch attempt"); |
| 3997 | }, |
| 3998 | delegateYield: function delegateYield(iterable, resultName, nextLoc) { |
| 3999 | this.delegate = { |
| 4000 | iterator: values(iterable), |
| 4001 | resultName: resultName, |
| 4002 | nextLoc: nextLoc |
| 4003 | }; |
| 4004 | |
| 4005 | if (this.method === "next") { |
| 4006 | // Deliberately forget the last sent value so that we don't |
| 4007 | // accidentally pass it on to the delegate. |
| 4008 | this.arg = undefined; |
| 4009 | } |
| 4010 | |
| 4011 | return ContinueSentinel; |
| 4012 | } |
| 4013 | }; // Regardless of whether this script is executing as a CommonJS module |
| 4014 | // or not, return the runtime object so that we can declare the variable |
| 4015 | // regeneratorRuntime in the outer scope, which allows this module to be |
| 4016 | // injected easily by `bin/regenerator --include-runtime script.js`. |
| 4017 | |
| 4018 | return exports; |
| 4019 | }( // If this script is executing as a CommonJS module, use module.exports |
| 4020 | // as the regeneratorRuntime namespace. Otherwise create a new empty |
| 4021 | // object. Either way, the resulting object will be used to initialize |
| 4022 | // the regeneratorRuntime variable at the top of this file. |
| 4023 | ( false ? undefined : _typeof(module)) === "object" ? module.exports : {}); |
| 4024 | |
| 4025 | try { |
| 4026 | regeneratorRuntime = runtime; |
| 4027 | } catch (accidentalStrictMode) { |
| 4028 | // This module should not be running in strict mode, so the above |
| 4029 | // assignment should always work unless something is misconfigured. Just |
| 4030 | // in case runtime.js accidentally runs in strict mode, we can escape |
| 4031 | // strict mode using a global Function call. This could conceivably fail |
| 4032 | // if a Content Security Policy forbids using Function, but in that case |
| 4033 | // the proper solution is to fix the accidental strict mode problem. If |
| 4034 | // you've misconfigured your bundler to force strict mode and applied a |
| 4035 | // CSP to forbid Function, and you're not willing to fix either of those |
| 4036 | // problems, please detail your unique predicament in a GitHub issue. |
| 4037 | Function("r", "regeneratorRuntime = r")(runtime); |
| 4038 | } |
| 4039 | /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../webpack/buildin/module.js */ "./node_modules/webpack/buildin/module.js")(module))) |
| 4040 | |
| 4041 | /***/ }), |
| 4042 | |
| 4043 | /***/ "./node_modules/webpack/buildin/global.js": |
| 4044 | /*!***********************************!*\ |
| 4045 | !*** (webpack)/buildin/global.js ***! |
| 4046 | \***********************************/ |
| 4047 | /*! no static exports found */ |
| 4048 | /***/ (function(module, exports) { |
| 4049 | |
| 4050 | function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } |
| 4051 | |
| 4052 | var g; // This works in non-strict mode |
| 4053 | |
| 4054 | g = function () { |
| 4055 | return this; |
| 4056 | }(); |
| 4057 | |
| 4058 | try { |
| 4059 | // This works if eval is allowed (see CSP) |
| 4060 | g = g || new Function("return this")(); |
| 4061 | } catch (e) { |
| 4062 | // This works if the window reference is available |
| 4063 | if ((typeof window === "undefined" ? "undefined" : _typeof(window)) === "object") g = window; |
| 4064 | } // g can still be undefined, but nothing to do about it... |
| 4065 | // We return undefined, instead of nothing here, so it's |
| 4066 | // easier to handle this case. if(!global) { ...} |
| 4067 | |
| 4068 | |
| 4069 | module.exports = g; |
| 4070 | |
| 4071 | /***/ }), |
| 4072 | |
| 4073 | /***/ "./node_modules/webpack/buildin/module.js": |
| 4074 | /*!***********************************!*\ |
| 4075 | !*** (webpack)/buildin/module.js ***! |
| 4076 | \***********************************/ |
| 4077 | /*! no static exports found */ |
| 4078 | /***/ (function(module, exports) { |
| 4079 | |
| 4080 | module.exports = function (module) { |
| 4081 | if (!module.webpackPolyfill) { |
| 4082 | module.deprecate = function () {}; |
| 4083 | |
| 4084 | module.paths = []; // module.parent = undefined by default |
| 4085 | |
| 4086 | if (!module.children) module.children = []; |
| 4087 | Object.defineProperty(module, "loaded", { |
| 4088 | enumerable: true, |
| 4089 | get: function get() { |
| 4090 | return module.l; |
| 4091 | } |
| 4092 | }); |
| 4093 | Object.defineProperty(module, "id", { |
| 4094 | enumerable: true, |
| 4095 | get: function get() { |
| 4096 | return module.i; |
| 4097 | } |
| 4098 | }); |
| 4099 | module.webpackPolyfill = 1; |
| 4100 | } |
| 4101 | |
| 4102 | return module; |
| 4103 | }; |
| 4104 | |
| 4105 | /***/ }), |
| 4106 | |
| 4107 | /***/ 0: |
| 4108 | /*!**********************************************************************!*\ |
| 4109 | !*** multi es6-promise-promise ./js/polyfill.js ./js/scripts_es6.js ***! |
| 4110 | \**********************************************************************/ |
| 4111 | /*! no static exports found */ |
| 4112 | /***/ (function(module, exports, __webpack_require__) { |
| 4113 | |
| 4114 | __webpack_require__(/*! es6-promise-promise */"./node_modules/es6-promise-promise/index.js"); |
| 4115 | __webpack_require__(/*! ./js/polyfill.js */"./js/polyfill.js"); |
| 4116 | module.exports = __webpack_require__(/*! ./js/scripts_es6.js */"./js/scripts_es6.js"); |
| 4117 | |
| 4118 | |
| 4119 | /***/ }), |
| 4120 | |
| 4121 | /***/ 1: |
| 4122 | /*!***********************!*\ |
| 4123 | !*** vertx (ignored) ***! |
| 4124 | \***********************/ |
| 4125 | /*! no static exports found */ |
| 4126 | /***/ (function(module, exports) { |
| 4127 | |
| 4128 | /* (ignored) */ |
| 4129 | |
| 4130 | /***/ }) |
| 4131 | |
| 4132 | /******/ }); |
| 4133 | //# sourceMappingURL=scripts.js.map |