{"version":3,"sources":["webpack:///./src/js/modules/news-media/NewsSubscribe.js"],"names":["_core","__webpack_require__","_countryList","NewsSubscribe","Component","this","dom","$subscribeModalTrigger","$el","find","$modal","$modalCloseButton","$modalTitle","$modalForm","$modalIcon","$modalFormButton","$countrySelect","$typeSelect","initSelect","on","createModal","bind","closeModal","onFormSubmit","countries","_orderBy2","default","getNames","map","country","join","append","config","searchEnabled","searchChoices","itemSelectText","shouldSort","countryChoices","Choices","typeChoices","_this2","removeAttr","modal","tingle","closeMethods","cssClass","onClose","onModalClose","setContent","open","show","trigger","setChoiceByValue","$","hide","removeClass","prop","close","e","preventDefault","redirectUrl","attr","endpoint","target","data","serializedData","serializeArray","email","_ref2","name","value","_isEmail2","_ref3","_defineProperty","ajax","url","type","dataType","contentType","addClass","window","location","href"],"mappings":"sjBAAAA,EAAAC,EAAA,QACAA,EAAA,UACAA,EAAA,MACAC,EAAAD,EAAA,SACAA,EAAA,UACAA,EAAA,oLAEME,grBAAsBC,wDAExBC,KAAKC,KACHC,uBAAwBF,KAAKG,IAAIC,KAC/B,wCAEFC,OAAQL,KAAKG,IAAIC,KAAK,0BACtBE,kBAAmBN,KAAKG,IAAIC,KAAK,iCACjCG,YAAaP,KAAKG,IAAIC,KAAK,iCAC3BI,WAAYR,KAAKG,IAAIC,KAAK,gCAC1BK,WAAYT,KAAKG,IAAIC,KAAK,0CAC1BM,iBAAkBV,KAAKG,IAAIC,KAAK,yCAChCO,eAAgBX,KAAKG,IAAIC,KAAK,wBAC9BQ,YAAaZ,KAAKG,IAAIC,KAAK,sBAE7BJ,KAAKa,oDAILb,KAAKC,IAAIC,uBAAuBY,GAAG,QAAWd,KAAKe,YAAnDC,KAA8ChB,OAC9CA,KAAKC,IAAIK,kBAAkBQ,GAAG,QAAWd,KAAKiB,WAA9CD,KAAyChB,OACzCA,KAAKC,IAAIO,WAAWM,GAAG,SAAYd,KAAKkB,aAAxCF,KAAmChB,4CAInC,IACMmB,GADiB,EAAAC,EAAAC,UAA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EAAerC,IACb,SAAA4C,GAAA,IAAGH,EAAHG,EAAGH,KAAMC,EAATE,EAASF,MAAT,OAAsBN,OAAYA,EAAZS,KAAmBJ,EAAOC,MAElDjB,EAAEqB,MACAC,IAAKb,EACLc,KAAM,OACNZ,OACAa,SAAU,QACVC,YAAa,oCAEfzE,KAAKC,IAAIO,WAAWyC,OACpBD,EAAEhD,KAAKC,IAAIM,YAAY,IAAI0C,OAC3BD,EAAEhD,KAAKC,IAAIM,YAAY,IAAIsC,OAC3B7C,KAAKC,IAAIQ,WAAWiE,SAAS,UAC7BC,OAAOC,SAASC,KAAOtB,yHAKdzD","file":"56.1b7637636efa8cc3c098.bundle.js","sourcesContent":["import { Component } from '@verndale/core';\nimport orderBy from 'lodash/orderBy';\nimport isEmail from 'validator/lib/isEmail';\nimport { getNames } from 'country-list';\nimport Choices from 'choices.js';\nimport tingle from 'tingle.js';\n\nclass NewsSubscribe extends Component {\n setupDefaults() {\n this.dom = {\n $subscribeModalTrigger: this.$el.find(\n '.news-subscribe__banner__content-btn'\n ),\n $modal: this.$el.find('.news-subscribe__modal'),\n $modalCloseButton: this.$el.find('.news-subscribe__modal__close'),\n $modalTitle: this.$el.find('.news-subscribe__modal__title'),\n $modalForm: this.$el.find('.news-subscribe__modal__form'),\n $modalIcon: this.$el.find('.news-subscribe__modal__icon-container'),\n $modalFormButton: this.$el.find('.news-subscribe__modal__form > button'),\n $countrySelect: this.$el.find('.js-country-selector'),\n $typeSelect: this.$el.find('.js-type-selector')\n };\n this.initSelect();\n }\n\n addListeners() {\n this.dom.$subscribeModalTrigger.on('click', ::this.createModal);\n this.dom.$modalCloseButton.on('click', ::this.closeModal);\n this.dom.$modalForm.on('submit', ::this.onFormSubmit);\n }\n\n initSelect() {\n const countriesNames = orderBy(getNames());\n const countries = countriesNames\n .map(country => ``)\n .join('');\n this.dom.$countrySelect.append(countries);\n const config = {\n searchEnabled: false,\n searchChoices: false,\n itemSelectText: '',\n shouldSort: false\n };\n this.countryChoices = new Choices(this.dom.$countrySelect[0], config);\n this.typeChoices = new Choices(this.dom.$typeSelect[0], config);\n }\n\n createModal() {\n this.dom.$modal.removeAttr('hidden');\n\n this.modal = new tingle.modal({\n closeMethods: ['overlay', 'escape'],\n cssClass: ['tingle-news-subscribe-modal'],\n onClose: () => this.onModalClose()\n });\n\n this.modal.setContent(this.dom.$modal[0]);\n this.modal.open();\n }\n\n onModalClose() {\n this.dom.$modalForm.show().trigger('reset');\n this.countryChoices.setChoiceByValue('');\n this.typeChoices.setChoiceByValue('');\n $(this.dom.$modalTitle[0]).show();\n $(this.dom.$modalTitle[1]).hide();\n this.dom.$modalIcon.removeClass('active');\n this.dom.$modalFormButton.prop('disabled', false);\n }\n\n closeModal() {\n if (this.modal) {\n this.modal.close();\n this.modal = null;\n }\n }\n\n async onFormSubmit(e) {\n e.preventDefault();\n const redirectUrl = this.dom.$modalForm.attr('action');\n const endpoint = $(e.target).data('url');\n const serializedData = $(e.target).serializeArray();\n const email = serializedData.find(({ name }) => name === 'EMAIL').value;\n if (isEmail(email)) {\n this.dom.$modalFormButton.prop('disabled', true);\n let data = {};\n serializedData.map(\n ({ name, value }) => (data = { ...data, [name]: value })\n );\n $.ajax({\n url: endpoint,\n type: 'POST',\n data,\n dataType: 'jsonp',\n contentType: 'application/json; charset=utf-8'\n });\n this.dom.$modalForm.hide();\n $(this.dom.$modalTitle[0]).hide();\n $(this.dom.$modalTitle[1]).show();\n this.dom.$modalIcon.addClass('active');\n window.location.href = redirectUrl;\n }\n }\n}\n\nexport default NewsSubscribe;\n"],"sourceRoot":""}