woocommerce/assets/js/admin/users.min.js
2021-12-10 12:03:04 +00:00

1 line
1.9 KiB
JavaScript

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