{"version":3,"sources":["ajax-forms/assets/js/ajax-forms.js"],"names":["r","e","n","t","o","i","f","c","u","a","Error","code","p","exports","call","length","1","require","module","Config","objectName","this","prototype","get","k","d","undefined","window","set","v","2","getButtonText","button","innerHTML","value","setButtonText","text","Loader","formElement","form","querySelector","loadingInterval","character","originalButton","cloneNode","setCharacter","start","loadingText","getAttribute","styles","getComputedStyle","style","width","setInterval","tick","bind","opacity","classList","add","loadingChar","stop","clearInterval","remove","3","ConfigStore","busy","config","mc4wp","forms","on","event","element","indexOf","document","activeElement","tagName","blur","loader","fire","request","XMLHttpRequest","onreadystatechange","readyState","status","response","JSON","parse","responseText","error","console","log","setResponse","process","open","setRequestHeader","send","getSerializedData","trigger","message","errors","data","getData","hide_fields","display","reset","redirect_to","location","href","args","id","submit","returnValue","preventDefault","./_config.js","./_form-loader.js"],"mappings":"CAA4E,SAASA,EAAEC,EAAEC,EAAEC,GAAG,SAASC,EAAEC,EAAEC,GAAG,IAAIJ,EAAEG,GAAG,CAAC,IAAIJ,EAAEI,GAAG,CAAC,IAAIE,GAAE,EAAoC,IAAID,GAAGC,EAAE,OAAOA,EAAEF,GAAE,GAAI,GAAGG,EAAE,OAAOA,EAAEH,GAAE,GAAI,IAAII,EAAE,IAAIC,MAAM,uBAAuBL,EAAE,KAAK,MAAMI,EAAEE,KAAK,mBAAmBF,EAAE,IAAIG,EAAEV,EAAEG,GAAG,CAACQ,QAAQ,IAAIZ,EAAEI,GAAG,GAAGS,KAAKF,EAAEC,QAAQ,SAASb,GAAoB,OAAOI,EAAlBH,EAAEI,GAAG,GAAGL,IAAeA,IAAIY,EAAEA,EAAEC,QAAQb,EAAEC,EAAEC,EAAEC,GAAG,OAAOD,EAAEG,GAAGQ,QAAQ,IAAI,IAAIL,GAAE,EAAoCH,EAAE,EAAEA,EAAEF,EAAEY,OAAOV,IAAID,EAAED,EAAEE,IAAI,OAAOD,EAA7b,CAA4c,CAACY,EAAE,CAAC,SAASC,EAAQC,EAAOL,GACxiB,a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AwGT9C,EAAOtC,IAAI,SAAS,IAElB,CAACqF,eAAe,EAAEC,oBAAoB,KAAK,GAAG,CAAC","file":"ajax-forms.min.js","sourcesContent":["(function () { var require = undefined; var define = undefined; (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c=\"function\"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error(\"Cannot find module '\"+i+\"'\");throw a.code=\"MODULE_NOT_FOUND\",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u=\"function\"==typeof require&&require,i=0;i= 5 ? loadingChar : text + \" \" + loadingChar);\n};\n\nLoader.prototype.stop = function () {\n if (this.button) {\n this.button.style.width = this.originalButton.style.width;\n var text = getButtonText(this.originalButton);\n setButtonText(this.button, text);\n window.clearInterval(this.loadingInterval);\n } else {\n this.form.style.opacity = '';\n }\n\n if (this.form.classList) {\n this.form.classList.remove('mc4wp-loading');\n }\n};\n\nmodule.exports = Loader;\n\n},{}],3:[function(require,module,exports){\n'use strict';\n\nvar ConfigStore = require('./_config.js');\nvar Loader = require('./_form-loader.js');\n\nvar busy = false;\nvar config = new ConfigStore('mc4wp_ajax_vars');\n\n// failsafe against including script twice\nif (!config.get('ready')) {\n\twindow.mc4wp.forms.on('submit', function (form, event) {\n\t\t// does this form have AJAX enabled?\n\t\tif (form.element.getAttribute('class').indexOf('mc4wp-ajax') < 0) {\n\t\t\treturn;\n\t\t}\n\n\t\t// blur active input field\n\t\tif (document.activeElement && document.activeElement.tagName === 'INPUT') {\n\t\t\tdocument.activeElement.blur();\n\t\t}\n\n\t\ttry {\n\t\t\tsubmit(form);\n\t\t} catch (e) {\n\t\t\tconsole.error(e);\n\t\t\treturn true;\n\t\t}\n\n\t\tevent.returnValue = false;\n\t\tevent.preventDefault();\n\t\treturn false;\n\t});\n}\n\nfunction submit(form) {\n\tvar loader = new Loader(form.element);\n\tvar loadingChar = config.get('loading_character');\n\tif (loadingChar) {\n\t\tloader.setCharacter(loadingChar);\n\t}\n\n\tfunction start() {\n\t\t// Clear possible errors from previous submit\n\t\tform.setResponse('');\n\t\tloader.start();\n\t\tfire();\n\t}\n\n\tfunction fire() {\n\t\t// prepare request\n\t\tbusy = true;\n\t\tvar request = new XMLHttpRequest();\n\t\trequest.onreadystatechange = function () {\n\t\t\t// are we done?\n\t\t\tif (this.readyState == 4) {\n\t\t\t\tclean();\n\n\t\t\t\tif (this.status >= 200 && this.status < 400) {\n\t\t\t\t\t// Request success! :-)\n\t\t\t\t\ttry {\n\t\t\t\t\t\tvar response = JSON.parse(this.responseText);\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tconsole.log('MailChimp for WordPress: failed to parse AJAX response.\\n\\nError: \"' + error + '\"');\n\n\t\t\t\t\t\t// Not good..\n\t\t\t\t\t\tform.setResponse('

' + config.get('error_text') + '

');\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tprocess(response);\n\t\t\t\t} else {\n\t\t\t\t\t// Error :(\n\t\t\t\t\tconsole.log(this.responseText);\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t\trequest.open('POST', config.get('ajax_url'), true);\n\t\trequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');\n\t\trequest.send(form.getSerializedData());\n\t\trequest = null;\n\t}\n\n\tfunction process(response) {\n\t\ttrigger('submitted', [form, null]);\n\n\t\tif (response.error) {\n\t\t\tform.setResponse(response.error.message);\n\t\t\ttrigger('error', [form, response.error.errors]);\n\t\t} else {\n\t\t\tvar data = form.getData();\n\n\t\t\t// trigger events\n\t\t\ttrigger('success', [form, data]);\n\t\t\ttrigger(response.data.event, [form, data]);\n\n\t\t\t// for BC: always trigger \"subscribed\" event when firing \"updated_subscriber\" event\n\t\t\t// third boolean parameter indicates this was a BC event\n\t\t\tif (response.data.event === 'updated_subscriber') {\n\t\t\t\ttrigger('subscribed', [form, data, true]);\n\t\t\t}\n\n\t\t\tif (response.data.hide_fields) {\n\t\t\t\tform.element.querySelector('.mc4wp-form-fields').style.display = 'none';\n\t\t\t}\n\n\t\t\t// show success message\n\t\t\tform.setResponse(response.data.message);\n\n\t\t\t// reset form element\n\t\t\tform.element.reset();\n\n\t\t\t// maybe redirect to url\n\t\t\tif (response.data.redirect_to) {\n\t\t\t\twindow.location.href = response.data.redirect_to;\n\t\t\t}\n\t\t}\n\t}\n\n\tfunction trigger(event, args) {\n\t\twindow.mc4wp.forms.trigger(event, args);\n\t\twindow.mc4wp.forms.trigger(args[0].id + \".\" + event, args);\n\t}\n\n\tfunction clean() {\n\t\tloader.stop();\n\t\tbusy = false;\n\t}\n\n\t// let's do this!\n\tif (!busy) {\n\t\tstart();\n\t}\n}\n\nconfig.set('ready', true);\n\n},{\"./_config.js\":1,\"./_form-loader.js\":2}]},{},[3]);\n })();"]}