woocommerce/assets/js/admin/meta-boxes-order.min.js

1 line
25 KiB
JavaScript
Raw Normal View History

jQuery(function(u){var p={states:null,init:function(){"undefined"!=typeof woocommerce_admin_meta_boxes_order&&"undefined"!=typeof woocommerce_admin_meta_boxes_order.countries&&(this.states=u.parseJSON(woocommerce_admin_meta_boxes_order.countries.replace(/&quot;/g,'"'))),u(".js_field-country").selectWoo().change(this.change_country),u(".js_field-country").trigger("change",[!0]),u(document.body).on("change","select.js_field-state",this.change_state),u("#woocommerce-order-actions input, #woocommerce-order-actions a").click(function(){window.onbeforeunload=""}),u("a.edit_address").click(this.edit_address),u("a.billing-same-as-shipping").on("click",this.copy_billing_to_shipping),u("a.load_customer_billing").on("click",this.load_billing),u("a.load_customer_shipping").on("click",this.load_shipping),u("#customer_user").on("change",this.change_customer_user)},change_country:function(e,o){if(void 0===o&&(o=!1),null!==p.states){var t,a=u(this),i=a.val(),n=a.parents("div.edit_address").find(":input.js_field-state"),r=n.parent(),c=n.attr("name"),d=n.attr("id"),m=a.data("woocommerce.stickState-"+i)?a.data("woocommerce.stickState-"+i):n.val(),_=n.attr("placeholder");if(o&&a.data("woocommerce.stickState-"+i,m),r.show().find(".select2-container").remove(),u.isEmptyObject(p.states[i]))t=u('<input type="text" />').prop("id",d).prop("name",c).prop("placeholder",_).addClass("js_field-state").val(m),n.replaceWith(t);else{var s=p.states[i],l=u('<option value=""></option>').text(woocommerce_admin_meta_boxes_order.i18n_select_state_text);t=u("<select></select>").prop("id",d).prop("name",c).prop("placeholder",_).addClass("js_field-state select short").append(l),u.each(s,function(e){var o=u("<option></option>").prop("value",e).text(s[e]);t.append(o)}),t.val(m),n.replaceWith(t),t.show().selectWoo().hide().change()}u(document.body).trigger("contry-change.woocommerce",[i,u(this).closest("div")]),u(document.body).trigger("country-change.woocommerce",[i,u(this).closest("div")])}},change_state:function(){var e=u(this),o=e.val(),t=e.parents("div.edit_address").find(":input.js_field-country"),a=t.val();t.data("woocommerce.stickState-"+a,o)},init_tiptip:function(){u("#tiptip_holder").removeAttr("style"),u("#tiptip_arrow").removeAttr("style"),u(".tips").tipTip({attribute:"data-tip",fadeIn:50,fadeOut:50,delay:200})},edit_address:function(e){e.preventDefault();var o=u(this),t=o.closest(".order_data_column"),a=t.find("div.edit_address"),i=t.find("div.address"),n=a.find(".js_field-country"),r=a.find(".js_field-state");i.hide(),o.parent().find("a").toggle(),n.val()||(n.val(woocommerce_admin_meta_boxes_order.default_country).change(),r.val(woocommerce_admin_meta_boxes_order.default_state).change()),a.show()},change_customer_user:function(){u("#_billing_country").val()||(u("a.edit_address").click(),p.load_billing(!0),p.load_shipping(!0))},load_billing:function(e){if(!0===e||window.confirm(woocommerce_admin_meta_boxes.load_billing)){var o=u("#customer_user").val();if(!o)return window.alert(woocommerce_admin_meta_boxes.no_customer_selected),!1;var t={user_id:o,action:"woocommerce_get_customer_details",security:woocommerce_admin_meta_boxes.get_customer_details_nonce};u(this).closest("div.edit_address").block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),u.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:t,type:"POST",success:function(e){e&&e.billing&&u.each(e.billing,function(e,o){u(":input#_billing_"+e).val(o).change()}),u("div.edit_address").unblock()}})}return!1},load_shipping:function(e){if(!0===e||window.confirm(woocommerce_admin_meta_boxes.load_shipping)){var o=u("#customer_user").val();if(!o)return window.alert(woocommerce_admin_meta_boxes.no_customer_selected),!1;var t={user_id:o,action:"woocommerce_get_customer_details",security:woocommerce_admin_meta_boxes.get_customer_details_nonce};u(this).closest("div.edit_address").block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),u.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:t,type:"POST",success:function(e){e&&e.billing&&u.each(e.shipping,function(e,o){u(":input#_shipping_"+e).v