woocommerce/assets/js/frontend/country-select.min.js

1 line
3.1 KiB
JavaScript
Raw Normal View History

2019-03-15 12:21:51 +00:00
jQuery(function(u){if("undefined"==typeof wc_country_select_params)return!1;if(u().selectWoo){var t=function(){u("select.country_select:visible, select.state_select:visible").each(function(){var t=u.extend({placeholder:u(this).attr("data-placeholder")||u(this).attr("placeholder")||"",width:"100%"},{language:{errorLoading:function(){return wc_country_select_params.i18n_searching},inputTooLong:function(t){var e=t.input.length-t.maximum;return 1===e?wc_country_select_params.i18n_input_too_long_1:wc_country_select_params.i18n_input_too_long_n.replace("%qty%",e)},inputTooShort:function(t){var e=t.minimum-t.input.length;return 1===e?wc_country_select_params.i18n_input_too_short_1:wc_country_select_params.i18n_input_too_short_n.replace("%qty%",e)},loadingMore:function(){return wc_country_select_params.i18n_load_more},maximumSelected:function(t){return 1===t.maximum?wc_country_select_params.i18n_selection_too_long_1:wc_country_select_params.i18n_selection_too_long_n.replace("%qty%",t.maximum)},noResults:function(){return wc_country_select_params.i18n_no_matches},searching:function(){return wc_country_select_params.i18n_searching}}});u(this).on("select2:select",function(){u(this).focus()}).selectWoo(t)})};t(),u(document.body).bind("country_to_state_changed",function(){t()})}var e=wc_country_select_params.countries.replace(/&quot;/g,'"'),p=u.parseJSON(e),d=".woocommerce-billing-fields,.woocommerce-shipping-fields,.woocommerce-address-fields,.woocommerce-shipping-calculator";u(document.body).on("change refresh","select.country_to_state, input.country_to_state",function(){var t=u(this).closest(d);t.length||(t=u(this).closest(".form-row").parent());var e=u(this).val(),n=t.find("#billing_state, #shipping_state, #calc_shipping_state"),c=n.closest("p.form-row"),o=n.attr("name"),i=n.attr("id"),r=n.val(),a=n.attr("placeholder")||n.attr("data-placeholder")||"";if(p[e])if(u.isEmptyObject(p[e]))c.hide().find(".select2-container").remove(),n.replaceWith('<input type="hidden" class="hidden" name="'+o+'" id="'+i+'" value="" placeholder="'+a+'" />'),u(document.body).trigger("country_to_state_changed",[e,t]);else{var s="",_=p[e];for(var l in _)_.hasOwnProperty(l)&&(s=s+'<option value="'+l+'">'+_[l]+"</option>");a||(a=wc_country_select_params.i18n_select_state_text),c.show(),n.is("input")&&(n.replaceWith('<select name="'+o+'" id="'+i+'" class="state_select" data-placeholder="'+a+'"></select>'),n=t.find("#billing_state, #shipping_state, #calc_shipping_state")),n.html('<option value="">'+wc_country_select_params.i18n_select_state_text+"</option>"+s),n.val(r).change(),u(document.body).trigger("country_to_state_changed",[e,t])}else n.is('select, input[type="hidden"]')&&(c.show().find(".select2-container").remove(),n.replaceWith('<input type="text" class="input-text" name="'+o+'" id="'+i+'" placeholder="'+a+'" />'),u(document.body).trigger("country_to_state_changed",[e,t]));u(document.body).trigger("country_to_state_changing",[e,t])}),u(document.body).on("wc_address_i18n_ready",function(){u(d).each(function(){var t=u(this).find("#billing_country, #shipping_country, #calc_shipping_country");0!==t.length&&0!==t.val().length&&t.trigger("refresh")})})});