woocommerce/assets/js/admin/users.min.js

1 line
1.8 KiB
JavaScript

jQuery(function(e){var t={states:null,init:function(){"undefined"!=typeof wc_users_params.countries&&(this.states=e.parseJSON(wc_users_params.countries.replace(/&quot;/g,'"'))),e(".js_field-country").select2().change(this.change_country),e(".js_field-country").trigger("change",[!0]),e(document.body).on("change","select.js_field-state",this.change_state),e(document.body).on("click","button.js_copy-billing",this.copy_billing)},change_country:function(a,n){if(void 0===n&&(n=!1),null!==t.states){var i=e(this),c=i.val(),s=i.parents(".form-table").find(":input.js_field-state"),o=s.parent(),l=s.attr("name"),r=s.attr("id"),u=i.data("woocommerce.stickState-"+c)?i.data("woocommerce.stickState-"+c):s.val();if(n&&i.data("woocommerce.stickState-"+c,u),o.show().find(".select2-container").remove(),e.isEmptyObject(t.states[c]))s.replaceWith('<input type="text" class="js_field-state" name="'+l+'" id="'+r+'" value="'+u+'" />');else{var d=e('<select name="'+l+'" id="'+r+'" class="js_field-state" style="width: 25em;"></select>'),p=t.states[c];d.append(e('<option value="">'+wc_users_params.i18n_select_state_text+"</option>")),e.each(p,function(t){d.append(e('<option value="'+t+'">'+p[t]+"</option>"))}),d.val(u),s.replaceWith(d),d.show().select2().hide().change()}e(document.body).trigger("contry-change.woocommerce",[c,e(this).closest("div")]),e(document.body).trigger("country-change.woocommerce",[c,e(this).closest("div")])}},change_state:function(){var t=e(this),a=t.val(),n=t.parents(".form-table").find(":input.js_field-country"),i=n.val();n.data("woocommerce.stickState-"+i,a)},copy_billing:function(t){t.preventDefault(),e("#fieldset-billing").find("input, select").each(function(t,a){var n=a.name.replace(/^billing_/,"shipping_"),i=e('[name="'+n+'"]');i.length&&i.val(a.value).trigger("change")})}};t.init()});