{"version":3,"file":"../../woocommerce-extra-checkout-fields-for-brazil/frontend-3110.min.js","sources":["woocommerce-extra-checkout-fields-for-brazil/frontend-3110.js"],"sourcesContent":["/* global bmwPublicParams */\njQuery(function ($) {\n\t/**\n\t * Frontend actions\n\t */\n\tconst bmwFrontEnd = {\n\t\t/**\n\t\t * Initialize frontend actions\n\t\t */\n\t\tinit() {\n\t\t\tif ('0' !== bmwPublicParams.person_type) {\n\t\t\t\t// CHANGE: Fix refence to function in main object\n\t\t\t\tbmwFrontEnd.person_type_fields();\n\t\t\t}\n\n\t\t\tif ('yes' === bmwPublicParams.maskedinput) {\n\t\t\t\t$(document.body).on('change', '#billing_country', function () {\n\t\t\t\t\tif ('BR' === $(this).val()) {\n\t\t\t\t\t\tbmwFrontEnd.maskBilling();\n\t\t\t\t\t} else {\n\t\t\t\t\t\tbmwFrontEnd.unmaskBilling();\n\t\t\t\t\t}\n\t\t\t\t});\n\n\t\t\t\t$(document.body).on('change', '#shipping_country', function () {\n\t\t\t\t\tif ('BR' === $(this).val()) {\n\t\t\t\t\t\tbmwFrontEnd.maskShipping();\n\t\t\t\t\t} else {\n\t\t\t\t\t\tbmwFrontEnd.unmaskShipping();\n\t\t\t\t\t}\n\t\t\t\t});\n\n\t\t\t\tif ('BR' === $('#billing_country').val()) {\n\t\t\t\t\tbmwFrontEnd.maskBilling();\n\t\t\t\t}\n\n\t\t\t\tif ('BR' === $('#shipping_country').val()) {\n\t\t\t\t\tbmwFrontEnd.maskShipping();\n\t\t\t\t}\n\n\t\t\t\t// CHANGE: Fix refence to function in main object\n\t\t\t\tbmwFrontEnd.maskGeneral();\n\t\t\t}\n\n\t\t\t// CHANGE: Remove code of the Mailcheck feature from Brazilian Market plugin as it is already provided by Fluid Checkout\n\n\t\t\t// Check if select2 exists.\n\t\t\tif ($().select2) {\n\t\t\t\t$('.wc-ecfb-select').select2();\n\t\t\t}\n\t\t},\n\n\t\tperson_type_fields() {\n\t\t\t/**\n\t\t\t * Control person type fields\n\t\t\t *\n\t\t\t * @param {string} personType\n\t\t\t * @param {boolean} checkCountry\n\t\t\t */\n\t\t\tconst handleFields = function (personType, checkCountry = false) {\n\t\t\t\tlet country = 'BR';\n\n\t\t\t\tif (checkCountry) {\n\t\t\t\t\tcountry = $('#billing_country').val();\n\t\t\t\t}\n\n\t\t\t\t$('.person-type-field')\n\t\t\t\t\t.hide()\n\t\t\t\t\t.removeClass(\n\t\t\t\t\t\t'validate-required is-active woocommerce-validated'\n\t\t\t\t\t);\n\t\t\t\t$('#billing_persontype_field').show().addClass('is-active');\n\n\t\t\t\tif ('1' === personType) {\n\t\t\t\t\tif ('BR' === country) {\n\t\t\t\t\t\t$('#billing_cpf_field')\n\t\t\t\t\t\t\t.addClass(\n\t\t\t\t\t\t\t\t'validate-required is-active woocommerce-validated'\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t.show();\n\t\t\t\t\t\t$('#billing_rg_field')\n\t\t\t\t\t\t\t.addClass(\n\t\t\t\t\t\t\t\t'validate-required is-active woocommerce-validated'\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t.show();\n\t\t\t\t\t} else {\n\t\t\t\t\t\t$('#billing_cpf_field').show().addClass('is-active');\n\t\t\t\t\t\t$('#billing_rg_field').show().addClass('is-active');\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif ('2' === personType) {\n\t\t\t\t\tif ('BR' === country) {\n\t\t\t\t\t\t$('#billing_company_field')\n\t\t\t\t\t\t\t.addClass(\n\t\t\t\t\t\t\t\t'validate-required is-active woocommerce-validated'\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t.show();\n\t\t\t\t\t\t$('#billing_cnpj_field')\n\t\t\t\t\t\t\t.addClass(\n\t\t\t\t\t\t\t\t'validate-required is-active woocommerce-validated'\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t.show();\n\t\t\t\t\t\t$('#billing_ie_field')\n\t\t\t\t\t\t\t.addClass(\n\t\t\t\t\t\t\t\t'validate-required is-active woocommerce-validated'\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t.show();\n\t\t\t\t\t} else {\n\t\t\t\t\t\t$('#billing_company_field')\n\t\t\t\t\t\t\t.addClass('is-active')\n\t\t\t\t\t\t\t.show();\n\t\t\t\t\t\t$('#billing_cnpj_field').addClass('is-active').show();\n\t\t\t\t\t\t$('#billing_ie_field').addClass('is-active').show();\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif ('BR' === country) {\n\t\t\t\t\t$('.person-type-field label .required').remove();\n\t\t\t\t\t$('.person-type-field label').append(\n\t\t\t\t\t\t' *'\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t};\n\n\t\t\t/**\n\t\t\t * Maybe run handle fields\n\t\t\t *\n\t\t\t * @param {boolean} checkCountry\n\t\t\t * @return {void}\n\t\t\t */\n\t\t\tconst maybeRunHandleFields = function (checkCountry = false) {\n\t\t\t\tif ('1' === bmwPublicParams.person_type) {\n\t\t\t\t\t$('#billing_persontype')\n\t\t\t\t\t\t.on('change', function () {\n\t\t\t\t\t\t\tconst personType = $(this).val();\n\n\t\t\t\t\t\t\thandleFields(personType, checkCountry);\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.change();\n\t\t\t\t}\n\t\t\t};\n\n\t\t\t// Required fields.\n\t\t\tif ('no' === bmwPublicParams.only_brazil) {\n\t\t\t\t$('.person-type-field label .required').remove();\n\t\t\t\t$('.person-type-field label').append(\n\t\t\t\t\t' *'\n\t\t\t\t);\n\n\t\t\t\tmaybeRunHandleFields();\n\t\t\t} else {\n\t\t\t\t// CHANGE: Extract anonymous function to a named function that can be reused\n\t\t\t\tvar updateBillingPersonFieldArgs = function () {\n\t\t\t\t\t$('.person-type-field').removeClass(\n\t\t\t\t\t\t'validate-required is-active woocommerce-validated'\n\t\t\t\t\t);\n\t\t\t\t\t$('.person-type-field label .required').remove();\n\t\t\t\t\tmaybeRunHandleFields(true);\n\n\t\t\t\t\t// CHANGE: Get field directly as referencing it with `this` do not work in this context\n\t\t\t\t\tconst current = $('#billing_country').val();\n\n\t\t\t\t\t\tif ('BR' === current) {\n\t\t\t\t\t\t\t$('.person-type-field label .required').remove();\n\t\t\t\t\t\t\t$('.person-type-field').addClass(\n\t\t\t\t\t\t\t\t'validate-required'\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t$('.person-type-field label').append(\n\t\t\t\t\t\t\t\t' *'\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t$('.person-type-field').removeClass(\n\t\t\t\t\t\t\t\t'validate-required'\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t$('.person-type-field label .required').remove();\n\t\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t\t// CHANGE: Replace `change` event trigger with calling the function directly\n\t\t\t\t$('#billing_country').on('change', updateBillingPersonFieldArgs);\n\t\t\t\tupdateBillingPersonFieldArgs();\n\t\t\t}\n\n\t\t\tif ('1' === bmwPublicParams.person_type) {\n\t\t\t\t// CHANGE: Extract anonymous function to a named function that can be reused\n\t\t\t\tvar updateBillingFieldsArgs = function () {\n\t\t\t\t\t// CHANGE: Get field directly as referencing it with `this` do not work in this context\n\t\t\t\t\tconst current = $('#billing_persontype').val();\n\n\t\t\t\t\t$('#billing_cpf_field').hide();\n\t\t\t\t\t$('#billing_rg_field').hide();\n\t\t\t\t\t$('#billing_company_field').hide();\n\t\t\t\t\t$('#billing_cnpj_field').hide();\n\t\t\t\t\t$('#billing_ie_field').hide();\n\n\t\t\t\t\tif ('1' === current) {\n\t\t\t\t\t\t$('#billing_cpf_field').show();\n\t\t\t\t\t\t$('#billing_rg_field').show();\n\t\t\t\t\t}\n\n\t\t\t\t\tif ('2' === current) {\n\t\t\t\t\t\t$('#billing_company_field').show();\n\t\t\t\t\t\t$('#billing_cnpj_field').show();\n\t\t\t\t\t\t$('#billing_ie_field').show();\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t\t// CHANGE: Replace `change` event trigger with calling the function directly\n\t\t\t\t$('#billing_persontype').on( 'change', updateBillingFieldsArgs );\n\t\t\t\tupdateBillingFieldsArgs();\n\t\t\t}\n\t\t},\n\n\t\tmaskBilling() {\n\t\t\t// CHANGE: Maybe do not mask phone fields\n\t\t\tif ( 'yes' === bmwPublicParams.maskedinput_phone ) {\n\t\t\t\tbmwFrontEnd.maskPhone('#billing_phone, #billing_cellphone');\n\t\t\t}\n\n\t\t\t$('#billing_birthdate').mask('00/00/0000');\n\t\t\t$('#billing_postcode').mask('00000-000');\n\t\t\t$(\n\t\t\t\t'#billing_phone, #billing_cellphone, #billing_birthdate, #billing_postcode'\n\t\t\t).attr('type', 'tel');\n\t\t},\n\n\t\tunmaskBilling() {\n\t\t\t$(\n\t\t\t\t'#billing_phone, #billing_cellphone, #billing_birthdate, #billing_postcode'\n\t\t\t)\n\t\t\t\t.unmask()\n\t\t\t\t.attr('type', 'text');\n\t\t},\n\n\t\tmaskShipping() {\n\t\t\t// CHANGE: Maybe mask shipping phone field\n\t\t\tif ( 'yes' === bmwPublicParams.maskedinput_phone ) {\n\t\t\t\tbmwFrontEnd.maskPhone( '#shipping_phone' );\n\t\t\t}\n\n\t\t\t$('#shipping_postcode').mask('00000-000').attr('type', 'tel');\n\t\t},\n\n\t\tunmaskShipping() {\n\t\t\t$('#shipping_postcode').unmask().attr('type', 'text');\n\n\t\t\t// CHANGE: Unmask shipping phone field, but do not change type attribute\n\t\t\t$( '#shipping_phone' ).unmask();\n\t\t},\n\n\t\tmaskGeneral() {\n\t\t\t$('#billing_cpf, #credit-card-cpf').mask('000.000.000-00');\n\t\t\t$('#billing_cnpj').mask('00.000.000/0000-00');\n\t\t\tbmwFrontEnd.maskPhone('#credit-card-phone');\n\t\t},\n\n\t\tmaskPhone(selector) {\n\t\t\tconst $element = $(selector),\n\t\t\t\tMaskBehavior = function (val) {\n\t\t\t\t\treturn val.replace(/\\D/g, '').length === 11\n\t\t\t\t\t\t? '(00) 00000-0000'\n\t\t\t\t\t\t: '(00) 0000-00009';\n\t\t\t\t},\n\t\t\t\tmaskOptions = {\n\t\t\t\t\tonKeyPress(val, e, field, options) {\n\t\t\t\t\t\tfield.mask(MaskBehavior.apply({}, arguments), options);\n\t\t\t\t\t},\n\t\t\t\t};\n\n\t\t\t$element.mask(MaskBehavior, maskOptions);\n\t\t},\n\n\t\t// CHANGE: Remove code of the Mailcheck feature from Brazilian Market plugin as it is already provided by Fluid Checkout\n\t};\n\n\tbmwFrontEnd.init();\n\n\t// CHANGE: Also run initialization after every checkout update as sections with affected fields might have have been replaced\n\t$( document.body ).on( 'updated_checkout', bmwFrontEnd.init );\n});\n"],"names":["jQuery","$","bmwFrontEnd","init","bmwPublicParams","person_type","person_type_fields","maskedinput","document","body","on","this","val","maskBilling","unmaskBilling","maskShipping","unmaskShipping","maskGeneral","select2","maybeRunHandleFields","checkCountry","personType","handleFields","let","country","hide","removeClass","show","addClass","remove","append","required","change","updateBillingFieldsArgs","only_brazil","updateBillingPersonFieldArgs","current","maskedinput_phone","maskPhone","mask","attr","unmask","selector","MaskBehavior","replace","length","$element","maskOptions","onKeyPress","e","field","options","apply","arguments"],"mappings":"AACAA,OAAO,SAAUC,GAIhB,MAAMC,EAAc,CAInBC,OACK,MAAQC,gBAAgBC,aAE3BH,EAAYI,mBAAmB,EAG5B,QAAUF,gBAAgBG,cAC7BN,EAAEO,SAASC,IAAI,EAAEC,GAAG,SAAU,mBAAoB,WAC7C,OAAST,EAAEU,IAAI,EAAEC,IAAI,EACxBV,EAAYW,YAAY,EAExBX,EAAYY,cAAc,CAE5B,CAAC,EAEDb,EAAEO,SAASC,IAAI,EAAEC,GAAG,SAAU,oBAAqB,WAC9C,OAAST,EAAEU,IAAI,EAAEC,IAAI,EACxBV,EAAYa,aAAa,EAEzBb,EAAYc,eAAe,CAE7B,CAAC,EAEG,OAASf,EAAE,kBAAkB,EAAEW,IAAI,GACtCV,EAAYW,YAAY,EAGrB,OAASZ,EAAE,mBAAmB,EAAEW,IAAI,GACvCV,EA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