{"version":3,"sources":["webpack:///scripts/ajax-submit--a6554f912bd969579822.js","webpack:///./client/src/core/components/ajax-submit/ajax-submit.js"],"names":["webpackJsonpHairCare","D:\\a\\1\\s\\node_modules\\babel-loader\\lib\\index.js??ref--12-0!D:\\a\\1\\s\\node_modules\\eslint-loader\\index.js??ref--12-1!D:\\a\\1\\s\\client\\src\\core\\components\\ajax-submit\\ajax-submit.js","module","exports","__webpack_require__","_classCallCheck","instance","Constructor","TypeError","getJSONValue","stringValue","JSON","parse","error","getFormData","form","formData","FormData","result","entries","field","Object","defineProperty","value","_createClass","defineProperties","target","props","i","length","descriptor","enumerable","configurable","writable","key","protoProps","staticProps","prototype","_debug2","obj","__esModule","default","_debug","log","AjaxSubmit","element","options","this","querySelector","ajaxSlotElement","ajaxSlotSelector","document","ajaxSlot","ajaxError","ajaxErrorSelector","submitButton","submitSelector","watch","addEventListener","onSubmit","bind","event","preventDefault","urlParams","URLSearchParams","url","endpoint","action","toString","fetch","then","response","ok","text","Promise","reject","html","parser","DOMParser","freshContent","parseFromString","hidden","replaceWith","body","firstChild","catch","dispatchEvent","Event","bubbles","DEFAULTS"],"mappings":"AAAAA,sBAAsB,gBAEhBC,0MACA,SAAUC,EAAQC,EAASC,GAEjC,YAeA,SAASC,GAAgBC,EAAUC,GAAe,KAAMD,YAAoBC,IAAgB,KAAM,IAAIC,WAAU,qCCjBhH,QAASC,GAAaC,GACrB,IACC,MAAOC,MAAKC,MAAMF,GACjB,MAAOG,GACR,MAAOH,IAIT,QAASI,GAAYC,GACpB,GAAMC,GAAW,GAAIC,UAASF,GACxBG,KAFoB,uBAI1B,YAAkBF,EAASG,UAA3B,+CAAsC,IAA7BC,GAA6B,OACrCF,GAAOE,EAAM,IAAMX,EAAaW,EAAM,KALb,6EAO1B,MAAOF,GDVRG,OAAOC,eAAenB,EAAS,cAC9BoB,OAAO,GAGR,IAAIC,GAAe,WAAc,QAASC,GAAiBC,EAAQC,GAAS,IAAK,GAAIC,GAAI,EAAGA,E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OAEVC,QAAQC,OAAOJ,KAEtBD,KAAK,SAACM,GACN,GAAMC,GAAS,GAAIC,WACbC,EAAeF,EAAOG,gBAAgBJ,EAAM,YAClD,GAAKvB,UAAU4B,QAAS,EACxB,EAAK7B,SAAS8B,YAAYH,EAAaI,KAAKC,cAE5CC,MAAM,WACN1C,EAAI,SACJ,EAAK5B,KAAKuE,cACT,GAAIC,OAAM,gBAAkBC,SAAS,KAEtC,EAAKnC,UAAU4B,QAAS,QDgDpBrC,IC1CRA,GAAW6C,UACVjC,eAAgB,mBDgDjBrD,EAAQsC,QC7COG","file":"scripts/ajax-submit--a6554f912bd969579822.js","sourcesContent":["webpackJsonpHairCare([\"ajax-submit\"],{\n\n/***/ \"D:\\\\a\\\\1\\\\s\\\\node_modules\\\\babel-loader\\\\lib\\\\index.js??ref--12-0!D:\\\\a\\\\1\\\\s\\\\node_modules\\\\eslint-loader\\\\index.js??ref--12-1!D:\\\\a\\\\1\\\\s\\\\client\\\\src\\\\core\\\\components\\\\ajax-submit\\\\ajax-submit.js\":\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\n\nObject.defineProperty(exports, \"__esModule\", {\n\tvalue: true\n});\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nvar _debug = __webpack_require__(\"D:\\\\a\\\\1\\\\s\\\\node_modules\\\\babel-loader\\\\lib\\\\index.js??ref--12-0!D:\\\\a\\\\1\\\\s\\\\node_modules\\\\eslint-loader\\\\index.js??ref--12-1!D:\\\\a\\\\1\\\\s\\\\node_modules\\\\debug\\\\src\\\\browser.js\");\n\nvar _debug2 = _interopRequireDefault(_debug);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar log = (0, _debug2.default)(\"ajax-submit\");\n\nfunction getJSONValue(stringValue) {\n\ttry {\n\t\treturn JSON.parse(stringValue);\n\t} catch (error) {\n\t\treturn stringValue;\n\t}\n}\n\nfunction getFormData(form) {\n\tvar formData = new FormData(form);\n\tvar result = {};\n\n\tvar _iteratorNormalCompletion = true;\n\tvar _didIteratorError = false;\n\tvar _iteratorError = undefined;\n\n\ttry {\n\t\tfor (var _iterator = formData.entries()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {\n\t\t\tvar field = _step.value;\n\n\t\t\tresult[field[0]] = getJSONValue(field[1]);\n\t\t}\n\t} catch (err) {\n\t\t_didIteratorError = true;\n\t\t_iteratorError = err;\n\t} finally {\n\t\ttry {\n\t\t\tif (!_iteratorNormalCompletion && _iterator.return) {\n\t\t\t\t_iterator.return();\n\t\t\t}\n\t\t} finally {\n\t\t\tif (_didIteratorError) {\n\t\t\t\tthrow _iteratorError;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn result;\n}\n\nfunction emptyElement(element) {\n\twhile (element.hasChildNodes()) {\n\t\telement.removeChild(element.lastChild);\n\t}\n}\n\nvar AjaxSubmit = function () {\n\tfunction AjaxSubmit(element, options) {\n\t\t_classCallCheck(this, AjaxSubmit);\n\n\t\tlog(\"element\", element);\n\t\tlog(\"options\", options);\n\n\t\tthis.options = options;\n\t\tthis.element = element;\n\t\tthis.form = element.querySelector(\"form\");\n\n\t\tvar ajaxSlotElement = options.ajaxSlotSelector && document.querySelector(options.ajaxSlotSelector);\n\t\tthis.ajaxSlot = ajaxSlotElement || element;\n\n\t\tthis.ajaxError = document.querySelector(options.ajaxErrorSelector);\n\t\tthis.submitButton = element.querySelector(this.options.submitSelector);\n\n\t\tlog(\"ready\", this, element);\n\t\tthis.watch();\n\t}\n\n\t_createClass(AjaxSubmit, [{\n\t\tkey: \"watch\",\n\t\tvalue: function watch() {\n\t\t\tlog(\"watching\");\n\t\t\tthis.element.addEventListener(\"submit\", this.onSubmit.bind(this));\n\t\t}\n\t}, {\n\t\tkey: \"onSubmit\",\n\t\tvalue: function onSubmit(event) {\n\t\t\tvar _this = this;\n\n\t\t\tlog(\"on submit\", event);\n\t\t\tevent.preventDefault();\n\n\t\t\tvar formData = getFormData(this.form);\n\t\t\tvar urlParams = new URLSearchParams(formData);\n\t\t\tvar url = (this.options.endpoint || this.form.action) + \"?\" + urlParams.toString();\n\n\t\t\tfetch(url).then(function (response) {\n\t\t\t\t// log({response});\n\t\t\t\tif (response.ok) {\n\t\t\t\t\treturn response.text();\n\t\t\t\t}\n\t\t\t\treturn Promise.reject(response);\n\t\t\t}).then(function (html) {\n\t\t\t\tvar parser = new DOMParser();\n\t\t\t\tvar freshContent = parser.parseFromString(html, \"text/html\");\n\t\t\t\t_this.ajaxError.hidden = true;\n\t\t\t\t_this.ajaxSlot.replaceWith(freshContent.body.firstChild);\n\t\t\t}).catch(function () {\n\t\t\t\tlog(\"error\");\n\t\t\t\t_this.form.dispatchEvent(new Event(\"submit error\", { bubbles: false }));\n\t\t\t\t_this.ajaxError.hidden = false;\n\t\t\t});\n\t\t}\n\t}]);\n\n\treturn AjaxSubmit;\n}();\n\nAjaxSubmit.DEFAULTS = {\n\tsubmitSelector: '[type=\"submit\"]'\n};\n\nexports.default = AjaxSubmit;\n\n/***/ })\n\n});\n\n\n// WEBPACK FOOTER //\n// scripts/ajax-submit--a6554f912bd969579822.js","import debug from \"debug\";\r\nconst log = debug(\"ajax-submit\");\r\n\r\nfunction getJSONValue(stringValue) {\r\n\ttry {\r\n\t\treturn JSON.parse(stringValue);\r\n\t} catch (error) {\r\n\t\treturn stringValue;\r\n\t}\r\n}\r\n\r\nfunction getFormData(form) {\r\n\tconst formData = new FormData(form);\r\n\tconst result = {};\r\n\r\n\tfor (var field of formData.entries()) {\r\n\t\tresult[field[0]] = getJSONValue(field[1]);\r\n\t}\r\n\treturn result;\r\n}\r\n\r\nfunction emptyElement(element) {\r\n\twhile (element.hasChildNodes()) {\r\n\t element.removeChild(element.lastChild);\r\n\t}\r\n }\r\n\r\nclass AjaxSubmit {\r\n\tconstructor(element, options) {\r\n\t\tlog(\"element\", element);\r\n\t\tlog(\"options\", options);\r\n\r\n\t\tthis.options = options;\r\n\t\tthis.element = element;\r\n\t\tthis.form = element.querySelector(\"form\");\r\n\r\n\t\tconst ajaxSlotElement = options.ajaxSlotSelector && document.querySelector(options.ajaxSlotSelector);\r\n\t\tthis.ajaxSlot = ajaxSlotElement || element;\r\n\r\n\t\tthis.ajaxError = document.querySelector(options.ajaxErrorSelector);\r\n\t\tthis.submitButton = element.querySelector(\r\n\t\t\tthis.options.submitSelector\r\n\t\t);\r\n\r\n\t\tlog(\"ready\", this, element);\r\n\t\tthis.watch();\r\n\t}\r\n\r\n\twatch() {\r\n\t\tlog(\"watching\");\r\n\t\tthis.element.addEventListener(\"submit\", this.onSubmit.bind(this));\r\n\t}\r\n\r\n\tonSubmit(event) {\r\n\t\tlog(\"on submit\", event);\r\n\t\tevent.preventDefault();\r\n\r\n\t\tconst formData = getFormData(this.form);\r\n\t\tconst urlParams = new URLSearchParams(formData);\r\n\t\tconst url = `${this.options.endpoint || this.form.action}?${urlParams.toString()}`;\r\n\r\n\t\tfetch(url)\r\n\t\t\t.then((response) => {\r\n\t\t\t\t// log({response});\r\n\t\t\t\tif (response.ok) {\r\n\t\t\t\t\treturn response.text();\r\n\t\t\t\t}\r\n\t\t\t\treturn Promise.reject(response);\r\n\t\t\t})\r\n\t\t\t.then((html) => {\r\n\t\t\t\tconst parser = new DOMParser();\r\n\t\t\t\tconst freshContent = parser.parseFromString(html, \"text/html\");\r\n\t\t\t\tthis.ajaxError.hidden = true;\r\n\t\t\t\tthis.ajaxSlot.replaceWith(freshContent.body.firstChild);\r\n\t\t\t})\r\n\t\t\t.catch(() => {\r\n\t\t\t\tlog(\"error\");\r\n\t\t\t\tthis.form.dispatchEvent(\r\n\t\t\t\t\tnew Event(\"submit error\", { bubbles: false })\r\n\t\t\t\t);\r\n\t\t\t\tthis.ajaxError.hidden = false;\r\n\t\t\t});\r\n\r\n\t}\r\n}\r\n\r\nAjaxSubmit.DEFAULTS = {\r\n\tsubmitSelector: '[type=\"submit\"]',\r\n};\r\n\r\nexport default AjaxSubmit;\r\n\n\n\n// WEBPACK FOOTER //\n// ./client/src/core/components/ajax-submit/ajax-submit.js"],"sourceRoot":""}