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iBAAmBtC,EAAGuC,UAAS,WAChC,OAAO9B,EAAKW,WAAaX,EAAKS,aAClC,GAAGR,KAQP,C","sources":["webpack://ui-toolkit/./sass/blocks/newsletter-signup.js","webpack://ui-toolkit/./sass/blocks/newsletter-signup.vm.js"],"sourcesContent":["var $ = require('jquery');\r\nvar ko = require('knockout');\r\nvar NewsletterSignupViewModel = require('./newsletter-signup.vm.js');\r\n\r\n$(function () {\r\n $('.ws-newsletter-signup').each(function (index, item) {\r\n ko.applyBindings(new NewsletterSignupViewModel(item), item);\r\n });\r\n});","var $ = require('jquery');\r\nvar ko = require('knockout');\r\n\r\nfunction NewsletterSignupViewModel(element) {\r\n var self = this;\r\n var $element = $(element);\r\n var $form = $element.find('form');\r\n var datasourceId = $element.data('datasource-id');\r\n\r\n self.email = ko.observable('');\r\n self.loading = ko.observable(false);\r\n self.showSuccess = ko.observable(false);\r\n self.showError = ko.observable(false);\r\n self.xhr = null;\r\n\r\n self.submit = function () {\r\n // setting errorPlacement callback to an empty function prevents showing error labels\r\n $form.validate({ errorPlacement: function () { } });\r\n if ($form.valid()) {\r\n self.showSuccess(false);\r\n self.showError(false);\r\n self.loading(true);\r\n\r\n if (self.xhr !== null && self.xhr.readyState !== 4) {\r\n self.xhr.abort();\r\n }\r\n\r\n var data = $.param({\r\n DatasourceId: datasourceId,\r\n EmailAddress: self.email()\r\n });\r\n\r\n self.xhr = $.post(\"/api/sitecore/NewsletterSignupApi/DataExtensionSignup\", data).then(handleResponse).catch(() => handleResponse(false));\r\n }\r\n };\r\n\r\n self.setValueAndSubmit = function () {\r\n // submitting the form by pressing Enter in the text box fires before the observable value is updated (updated on loss of focus), so we need to force the update so the correct value is used\r\n self.email($form.find('input[name=email]').val());\r\n return self.submit();\r\n };\r\n\r\n self.loadingOrSuccess = ko.computed(function () {\r\n return self.loading() || self.showSuccess();\r\n }, this);\r\n\r\n function handleResponse(response) {\r\n self.showSuccess(response);\r\n self.showError(!response);\r\n self.loading(false);\r\n self.email('');\r\n }\r\n}\r\n\r\nmodule.exports = NewsletterSignupViewModel;"],"names":["$","require","ko","NewsletterSignupViewModel","each","index","item","applyBindings","module","exports","element","self","this","$element","$form","find","datasourceId","data","handleResponse","response","showSuccess","showError","loading","email","observable","xhr","submit","validate","errorPlacement","valid","readyState","abort","param","DatasourceId","EmailAddress","post","then","catch","setValueAndSubmit","val","loadingOrSuccess","computed"],"sourceRoot":""}