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

1 line
27 KiB
JavaScript
Raw Normal View History

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