woocommerce/assets/js/frontend/address-i18n.min.js

1 line
1.7 KiB
JavaScript

jQuery(function(e){var t=wc_address_i18n_params.locale.replace(/&quot;/g,'"'),n=e.parseJSON(t),r=' <abbr class="required" title="'+wc_address_i18n_params.i18n_required_text+'">*</abbr>';e("body").bind("country_to_state_changing",function(t,i,s){var o=s,u;if(typeof n[i]!=="undefined"){u=n[i]}else{u=n["default"]}var a=e.parseJSON(wc_address_i18n_params.locale_fields);e.each(a,function(e,t){var i=o.find(t);if(u[e]){if(u[e].label){i.find("label").html(u[e].label)}if(u[e].placeholder){i.find("input").attr("placeholder",u[e].placeholder)}i.find("label abbr").remove();if(typeof u[e].required==="undefined"&&n["default"][e].required===true){i.find("label").append(r)}else if(u[e].required===true){i.find("label").append(r)}if(e!=="state"){if(u[e].hidden===true){i.hide().find("input").val("")}else{i.show()}}}else if(n["default"][e]){if(n["default"][e].required===true){if(i.find("label abbr").size()===0)i.find("label").append(r)}if(e!=="state"){if(typeof n["default"][e].hidden==="undefined"||n["default"][e].hidden===false){i.show()}else if(n["default"][e].hidden===true){i.hide().find("input").val("")}}}});var f=o.find("#billing_postcode_field, #shipping_postcode_field"),l=o.find("#billing_city_field, #shipping_city_field"),c=o.find("#billing_state_field, #shipping_state_field");if(!f.attr("data-o_class")){f.attr("data-o_class",f.attr("class"));l.attr("data-o_class",l.attr("class"));c.attr("data-o_class",c.attr("class"))}if(u.postcode_before_city){f.add(l).add(c).removeClass("form-row-first form-row-last").addClass("form-row-wide");f.insertBefore(l)}else{f.attr("class",f.attr("data-o_class"));l.attr("class",l.attr("data-o_class"));c.attr("class",c.attr("data-o_class"));f.insertAfter(c)}})})