woocommerce/assets/js/admin/write-panels.min.js

1 line
20 KiB
JavaScript

jQuery(function(a){function e(){a(".woocommerce_attributes .woocommerce_attribute").each(function(b,c){a(".attribute_position",c).val(parseInt(a(c).index(".woocommerce_attributes .woocommerce_attribute")))})}a("#upsell_product_data").bind("keypress",function(a){if(a.keyCode==13)return!1});a("ul.tabs").show();a("div.panel-wrap").each(function(){a("div.panel:not(div.panel:first)",this).hide()});a("ul.tabs a").click(function(){var b=a(this).closest("div.panel-wrap");a("ul.tabs li",b).removeClass("active");a(this).parent().addClass("active");a("div.panel",b).hide();a(a(this).attr("href")).show();return!1});jQuery("select.chosen_select").chosen();jQuery("select.chosen_select_nostd").chosen({allow_single_deselect:"true"});jQuery("select.ajax_chosen_select_products").ajaxChosen({method:"GET",url:woocommerce_writepanel_params.ajax_url,dataType:"json",data:{action:"woocommerce_json_search_products",security:woocommerce_writepanel_params.search_products_nonce}},function(b){var c={};a.each(b,function(a,b){c[a]=b});return c});a(".multi_select_products #product_search").bind("keyup click",function(){a(".multi_select_products_source").addClass("loading");a(".multi_select_products_source li:not(.product_search)").remove();var b=a(this).val(),c=this,d=a(this).attr("rel");if(b.length<3){a(".multi_select_products_source").removeClass("loading");return}var e={name:d,search:encodeURI(b),action:"woocommerce_upsell_crosssell_search_products",security:woocommerce_writepanel_params.search_products_nonce};f=a.ajax({url:woocommerce_writepanel_params.ajax_url,data:e,type:"POST",success:function(b){a(".multi_select_products_source").removeClass("loading");a(".multi_select_products_source li:not(.product_search)").remove();a(c).parent().parent().append(b)}})});jQuery("#woocommerce-order-actions input, #woocommerce-order-actions a").click(function(){window.onbeforeunload=""});a("a.edit_address").click(function(b){a(this).hide();a(this).closest(".order_data").find("div.address").hide();a(this).closest(".order_data").find("div.edit_address").show();b.preventDefault()});a("#order_items_list .remove_row").live("click",function(){var b=confirm(woocommerce_writepanel_params.remove_item_notice);if(b){a(this).closest("tr.item").hide();a("input",a(this).closest("tr.item")).val("")}return!1});a("button.calc_line_taxes").live("click",function(){a(".woocommerce_order_items_wrapper").block({message:null,overlayCSS:{background:"#fff url("+woocommerce_writepanel_params.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:.6}});var b=confirm(woocommerce_writepanel_params.calc_line_taxes);if(b){var c=a("#order_items_list tr.item"),d=a("#_shipping_country").val();if(d)var e=a("#_shipping_state").val(),f=a("#_shipping_postcode").val();else{d=a("#_billing_country").val();var e=a("#_billing_state").val(),f=a("#_billing_postcode").val()}c.each(function(b){var g=a(this),h={action:"woocommerce_calc_line_taxes",item_id:g.find("input.item_id").val(),line_subtotal:g.find("input.line_subtotal").val(),line_total:g.find("input.line_total").val(),tax_class:g.find("select.tax_class").val(),country:d,state:e,postcode:f,security:woocommerce_writepanel_params.calc_totals_nonce};a.post(woocommerce_writepanel_params.ajax_url,h,function(d){result=jQuery.parseJSON(d);g.find("input.line_subtotal_tax").val(result.line_subtotal_tax);g.find("input.line_tax").val(result.line_tax);b==c.size()-1&&a(".woocommerce_order_items_wrapper").unblock()})})}else a(".woocommerce_order_items_wrapper").unblock();return!1}).hover(function(){a("#order_items_list input.line_subtotal_tax, #order_items_list input.line_tax").css("background-color","#d8c8d2")},function(){a("#order_items_list input.line_subtotal_tax, #order_items_list input.line_tax").css("background-color","")});a("button.calc_totals").live("click",function(){a("#woocommerce-order-totals").block({message:null,overlayCSS:{background:"#fff url("+woocommerce_writepanel_params.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:.6}});var b=confirm(woocommerce_writepanel_params.calc_totals);if(b){var c=0,d=0,e=0,f=0,g=0,h=parseFloat(a("#_order_shipping").val()),i=parseFloat(a("#_order_shipping_tax").val()),j=parseFloat(a("#_order_discount").val());h||(h=0);i||(i=0);j||(j=0);a("#order_items_list tr.item").each(function(){var b=parseFloat(a(this).find("input.line_subtotal").val()),f=parseFloat(a(this).find("input.line_subtotal_tax").val()),h=parseFloat(a(this).find("input.line_total").val()),i=parseFloat(a(this).find("input.line_tax").val());c=parseFloat(c+b);d=parseFloat(d+f);e=parseFloat(e+h);woocommerce_writepanel_params.round_at_subtotal=="no"&&(i=parseFloat(i.toFixed(2)));g=parseFloat(g+i)});woocommerce_writepanel_params.round_at_subtotal=="yes"&&(g=parseFloat(g.toFixed(2)));var f=c+d-(e+g);f<0&&(f=0);f=f.toFixed(2);var k=e+g+h+i-j;k=k.toFixed(2);a("#_cart_discount").val(f);a("#_order_tax").val(g);a("#_order_total").val(k);a("#tax_rows").empty();a("#woocommerce-order-totals").unblock()}else a("#woocommerce-order-totals").unblock();return!1}).hover(function(){a("#woocommerce-order-totals .calculated").css("background-color","#d8c8d2")},function(){a("#woocommerce-order-totals .calculated").css("background-color","")});a("button.add_shop_order_item").click(function(){var b=a("select.add_item_id").val();if(b){a("table.woocommerce_order_items").block({message:null,overlayCSS:{background:"#fff url("+woocommerce_writepanel_params.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:.6}});var c=a("table.woocommerce_order_items tbody tr.item").size(),d={action:"woocommerce_add_order_item",item_to_add:a("select.add_item_id").val(),index:c,security:woocommerce_writepanel_params.add_order_item_nonce};a.post(woocommerce_writepanel_params.ajax_url,d,function(b){a("table.woocommerce_order_items tbody#order_items_list").append(b);a("table.woocommerce_order_items").unblock();a("select.add_item_id").css("border-color","").val("");jQuery(".tips").tipTip({attribute:"tip",fadeIn:50,fadeOut:50})})}else a("select.add_item_id").css("border-color","red")});a("button.add_meta").live("click",function(){var b=a(this).closest("tr.item").attr("rel");a(this).closest("table.meta").find(".meta_items").append('<tr><td><input type="text" name="meta_name['+b+'][]" placeholder="'+woocommerce_writepanel_params.meta_name+'" /></td><td><input type="text" name="meta_value['+b+'][]" placeholder="'+woocommerce_writepanel_params.meta_value+'" /></td><td width="1%"><button class="remove_meta button">&times;</button></td></tr>');return!1});a("button.remove_meta").live("click",function(){var b=confirm("Remove this meta key?");b&&a(this).closest("tr").remove();return!1});a("button.load_customer_billing").live("click",function(){var b=confirm(woocommerce_writepanel_params.load_billing);if(b){var c=a("#customer_user").val();if(!c){alert(woocommerce_writepanel_params.no_customer_selected);return!1}var d={user_id:c,type_to_load:"billing",action:"woocommerce_get_customer_details",security:woocommerce_writepanel_params.get_customer_details_nonce};a(this).closest(".edit_address").block({message:null,overlayCSS:{background:"#fff url("+woocommerce_writepanel_params.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:.6}});a.ajax({url:woocommerce_writepanel_params.ajax_url,data:d,type:"POST",success:function(b){var c=jQuery.parseJSON(b);if(c){a("input#_billing_first_name").val(c.billing_first_name);a("input#_billing_last_name").val(c.billing_last_name);a("input#_billing_company").val(c.billing_company);a("input#_billing_address_1").val(c.billing_address_1);a("input#_billing_address_2").val(c.billing_address_2);a("input#_billing_city").val(c.billing_city);a("input#_billing_postcode").val(c.billing_postcode);a("input#_billing_country").val(c.billing_country);a("input#_billing_state").val(c.billing_state);a("input#_billing_email").val(c.billing_email);a("input#_billing_phone").val(c.billing_phone)}a(".edit_address").unblock()}})}return!1});a("button.load_customer_shipping").live("click",function(){var b=confirm(woocommerce_writepanel_params.load_shipping);if(b){var c=a("#customer_user").val();if(!c){alert(woocommerce_writepanel_params.no_customer_selected);return!1}var d={user_id:c,type_to_load:"shipping",action:"woocommerce_get_customer_details",security:woocommerce_writepanel_params.get_customer_details_nonce};a(this).closest(".edit_address").block({message:null,overlayCSS:{background:"#fff url("+woocommerce_writepanel_params.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:.6}});a.ajax({url:woocommerce_writepanel_params.ajax_url,data:d,type:"POST",success:function(b){var c=jQuery.parseJSON(b);if(c){a("input#_shipping_first_name").val(c.shipping_first_name);a("input#_shipping_last_name").val(c.shipping_last_name);a("input#_shipping_company").val(c.shipping_company);a("input#_shipping_address_1").val(c.shipping_address_1);a("input#_shipping_address_2").val(c.shipping_address_2);a("input#_shipping_city").val(c.shipping_city);a("input#_shipping_postcode").val(c.shipping_postcode);a("input#_shipping_country").val(c.shipping_country);a("input#_shipping_state").val(c.shipping_state)}a(".edit_address").unblock()}})}return!1});a("button.billing-same-as-shipping").live("click",function(){var b=confirm(woocommerce_writepanel_params.copy_billing);if(b){a("input#_shipping_first_name").val(a("input#_billing_first_name").val());a("input#_shipping_last_name").val(a("input#_billing_last_name").val());a("input#_shipping_company").val(a("input#_billing_company").val());a("input#_shipping_address_1").val(a("input#_billing_address_1").val());a("input#_shipping_address_2").val(a("input#_billing_address_2").val());a("input#_shipping_city").val(a("input#_billing_city").val());a("input#_shipping_postcode").val(a("input#_billing_postcode").val());a("input#_shipping_country").val(a("input#_billing_country").val());a("input#_shipping_state").val(a("input#_billing_state").val())}return!1});a("a.add_tax_row").live("click",function(){var b=a("#tax_rows .tax_row").size();a("#tax_rows").append('<div class="tax_row">\t\t\t<p class="first">\t\t\t\t<label>'+woocommerce_writepanel_params.tax_label+'</label>\t\t\t\t<input type="text" name="_order_taxes_label['+b+']" placeholder="'+woocommerce_writepanel_params.tax_or_vat+'" />\t\t\t</p>\t\t\t<p class="last">\t\t\t\t<label>'+woocommerce_writepanel_params.compound_label+'\t\t\t\t<input type="checkbox" name="_order_taxes_compound['+b+']" /></label>\t\t\t</p>\t\t\t<p class="first">\t\t\t\t<label>'+woocommerce_writepanel_params.cart_tax_label+'</label>\t\t\t\t<input type="text" name="_order_taxes_cart['+b+']" placeholder="0.00" />\t\t\t</p>\t\t\t<p class="last">\t\t\t\t<label>'+woocommerce_writepanel_params.shipping_tax_label+'</label>\t\t\t\t<input type="text" name="_order_taxes_shipping['+b+']" placeholder="0.00" />\t\t\t</p>\t\t\t<a href="#" class="delete_tax_row">&times;</a>\t\t\t<div class="clear"></div>\t\t</div>');return!1});a("a.delete_tax_row").live("click",function(){$tax_row=a(this).closest(".tax_row");$tax_row.find("input").val("");$tax_row.hide();return!1});a("select#product-type").change(function(){var b=a(this).val();a(".hide_if_grouped").show();a(".show_if_simple, .show_if_variable, .show_if_grouped, .show_if_external").hide();if(b=="simple"){a(".show_if_simple").show();a("input#_manage_stock").change()}else if(b=="variable"){a(".show_if_variable").show();a("input#_manage_stock").change();a("input#_downloadable").prop("checked",!1).change();a("input#_virtual").removeAttr("checked").change()}else if(b=="grouped"){a(".show_if_grouped").show();a("input#_downloadable").prop("checked",!1).change();a("input#_virtual").removeAttr("checked").change();a(".hide_if_grouped").hide()}else if(b=="external"){a(".show_if_external").show();a("input#_downloadable").prop("checked",!1).change();a("input#_virtual").removeAttr("checked").change()}a("ul.tabs li:visible").eq(0).find("a").click();a("body").trigger("woocommerce-product-type-change",b,a(this))}).change();a("input#_downloadable").change(function(){a(".show_if_downloadable").hide();a("input#_downloadable").is(":checked")&&a(".show_if_downloadable").show();a(".downloads_tab").is(".active")&&a("ul.tabs li:visible").eq(0).find("a").click()}).change();a("input#_virtual").change(function(){a(".show_if_virtual").hide();a(".hide_if_virtual").show();if(a("input#_virtual").is(":checked")){a(".show_if_virtual").show();a(".hide_if_virtual").hide()}}).change();var b=!1;a(".sale_price_dates_fields input").each(function(){a(this).val()!=""&&(b=!0)});if(b){a(".sale_schedule").hide();a(".sale_price_dates_fields").show()}else{a(".sale_schedule").show();a(".sale_price_dates_fields").hide()}a(".sale_schedule").click(function(){a(this).hide();a(".sale_price_dates_fields").show();return!1});a(".cancel_sale_schedule").click(function(){a(this).closest("p").find("input").val("");a(".sale_schedule").show();a(".sale_price_dates_fields").hide();return!1});a("input#_manage_stock").change(function(){a(this).is(":checked")?a("div.stock_fields").show():a("div.stock_fields").hide()}).change();var c=a("#_sale_price_dates_from, #_sale_price_dates_to").datepicker({defaultDate:"",dateFormat:"yy-mm-dd",numberOfMonths:1,showButtonPanel:!0,showOn:"button",buttonImage:woocommerce_writepanel_params.calendar_image,buttonImageOnly:!0,onSelect:function(b){var d=this.id=="_sale_price_dates_from"?"minDate":"maxDate",e=a(this).data("datepicker"),f=a.datepicker.parseDate(e.settings.dateFormat||a.datepicker._defaults.dateFormat,b,e.settings);c.not(this).datepicker("option",d,f)}});a(".date-picker").datepicker({dateFormat:"yy-mm-dd",numberOfMonths:1,showButtonPanel:!0,showOn:"button",buttonImage:woocommerce_writepanel_params.calendar_image,buttonImageOnly:!0});jQuery(".expand_all").click(function(){jQuery(this).closest(".wc-metaboxes-wrapper").find(".wc-metabox table").show();return!1});jQuery(".close_all").click(function(){jQuery(this).closest(".wc-metaboxes-wrapper").find(".wc-metabox table").hide();return!1});jQuery(".wc-metaboxes-wrapper").on("click",".wc-metabox h3",function(){jQuery(this).next(".wc-metabox-content").toggle()});jQuery(".wc-metabox.closed").each(function(){jQuery(this).find(".wc-metabox-content").hide()});a(".woocommerce_attributes select.multiselect").chosen();var d=a(".woocommerce_attributes").find(".woocommerce_attribute").get();d.sort(function(b,c){var d=parseInt(a(b).attr("rel")),e=parseInt(a(c).attr("rel"));return d<e?-1:d>e?1:0});a(d).each(function(b,c){a(".woocommerce_attributes").append(c)});a("button.add_attribute").on("click",function(){var b=a(".woocommerce_attributes .woocommerce_attribute").size(),c=a("select.attribute_taxonomy").val();if(!c){var d=a("select#product-type").val();d!="variable"?enable_variation='style="display:none;"':enable_variation="";a(".woocommerce_attributes").append('<div class="woocommerce_attribute wc-metabox">\t\t\t\t\t\t<h3>\t\t\t\t\t\t\t<button type="button" class="remove_row button">'+woocommerce_writepanel_params.remove_label+'</button>\t\t\t\t\t\t\t<div class="handlediv" title="'+woocommerce_writepanel_params.click_to_toggle+'"></div>\t\t\t\t\t\t\t<strong class="attribute_name"></strong>\t\t\t\t\t\t</h3>\t\t\t\t\t\t<table cellpadding="0" cellspacing="0" class="woocommerce_attribute_data">\t\t\t\t\t\t\t<tbody>\t\t\t\t\t\t\t\t<tr>\t\t\t\t\t\t\t\t\t<td class="attribute_name">\t\t\t\t\t\t\t\t\t\t<label>'+woocommerce_writepanel_params.name_label+':</label>\t\t\t\t\t\t\t\t\t\t<input type="text" class="attribute_name" name="attribute_names['+b+']" />\t\t\t\t\t\t\t\t\t\t<input type="hidden" name="attribute_is_taxonomy['+b+']" value="0" />\t\t\t\t\t\t\t\t\t\t<input type="hidden" name="attribute_position['+b+']" class="attribute_position" value="'+b+'" />\t\t\t\t\t\t\t\t\t</td>\t\t\t\t\t\t\t\t\t<td rowspan="3">\t\t\t\t\t\t\t\t\t\t<label>'+woocommerce_writepanel_params.values_label+':</label>\t\t\t\t\t\t\t\t\t\t<textarea name="attribute_values['+b+']" cols="5" rows="5" placeholder="'+woocommerce_writepanel_params.text_attribute_tip+'"></textarea>\t\t\t\t\t\t\t\t\t</td>\t\t\t\t\t\t\t\t</tr>\t\t\t\t\t\t\t\t<tr>\t\t\t\t\t\t\t\t\t<td>\t\t\t\t\t\t\t\t\t\t<label><input type="checkbox" class="checkbox" checked="checked" name="attribute_visibility['+b+']" value="1" /> '+woocommerce_writepanel_params.visible_label+'</label>\t\t\t\t\t\t\t\t\t</td>\t\t\t\t\t\t\t\t</tr>\t\t\t\t\t\t\t\t<tr>\t\t\t\t\t\t\t\t\t<td>\t\t\t\t\t\t\t\t\t\t<div class="enable_variation show_if_variable" '+enable_variation+'>\t\t\t\t\t\t\t\t\t\t<label><input type="checkbox" class="checkbox" name="attribute_variation['+b+']" value="1" /> '+woocommerce_writepanel_params.used_for_variations_label+"</label>\t\t\t\t\t\t\t\t\t\t</div>\t\t\t\t\t\t\t\t\t</td>\t\t\t\t\t\t\t\t</tr>\t\t\t\t\t\t\t</tbody>\t\t\t\t\t\t</table>\t\t\t\t\t</div>")}else{var f=a(".woocommerce_attributes .woocommerce_attribute."+c);a(".woocommerce_attributes").append(a(f));a(f).show().find(".woocommerce_attribute_data").show();e()}a("select.attribute_taxonomy").val("")});a(".woocommerce_attributes").on("blur","input.attribute_name",function(){a(this).closest(".woocommerce_attribute").find("strong.attribute_name").text(a(this).val())});a(".woocommerce_attributes").on("click","button.select_all_attributes",function(){a(this).closest("td").find("select option").attr("selected","selected");a(this).closest("td").find("select").trigger("liszt:updated");return!1});a(".woocommerce_attributes").on("click","button.select_no_attributes",function(){a(this).closest("td").find("select option").removeAttr("selected");a(this).closest("td").find("select").trigger("liszt:updated");return!1});a(".woocommerce_attributes").on("click","button.remove_row",function(){var b=confirm(woocommerce_writepanel_params.remove_attribute);if(b){var c=a(this).parent().parent();if(c.is(".taxonomy")){c.find("select, input[type=text]").val("");c.hide()}else{c.find("select, input[type=text]").val("");c.hide();e()}}return!1});a(".woocommerce_attributes").sortable({items:".woocommerce_attribute",cursor:"move",axis:"y",handle:"h3",scrollSensitivity:40,forcePlaceholderSize:!0,helper:"clone",opacity:.65,placeholder:"wc-metabox-sortable-placeholder",start:function(a,b){b.item.css("background-color","#f6f6f6")},stop:function(a,b){b.item.removeAttr("style");e()}});a(".multi_select_products button").live("click",function(){var b=a(this).parent().parent().parent().parent(),c=a(this),d=c.parent().parent();if(d.is(".multi_select_products_target_upsell")||d.is(".multi_select_products_target_crosssell"))c.parent().remove();else{if(c.is(".add_upsell"))var e=a(".multi_select_products_target_upsell",a(b)),f="upsell_ids[]";else var e=a(".multi_select_products_target_crosssell",a(b)),f="crosssell_ids[]";var g=a("li[rel="+c.parent().attr("rel")+"]",e);if(a(g).size()>0)return!1;var h=c.parent().clone();h.find("button:eq(0)").html("&times;");h.find("button:eq(1)").remove();h.find("input").val(c.parent().attr("rel"));h.find(".product_id").attr("name",f);h.appendTo(e)}});var f;a(".multi_select_products #product_search").bind("keyup click",function(){a(".multi_select_products_source").addClass("loading");a(".multi_select_products_source li:not(.product_search)").remove();f&&f.abort();var b=a(this).val(),c=this,d=a(this).attr("rel");if(b.length<3){a(".multi_select_products_source").removeClass("loading");return}var e={name:d,search:encodeURI(b),action:"woocommerce_upsell_crosssell_search_products",security:woocommerce_writepanel_params.search_products_nonce};f=a.ajax({url:woocommerce_writepanel_params.ajax_url,data:e,type:"POST",success:function(b){a(".multi_select_products_source").removeClass("loading");a(".multi_select_products_source li:not(.product_search)").remove();a(c).parent().parent().append(b)}})});var g;window.send_to_editor_default=window.send_to_editor;jQuery(".upload_file_button").live("click",function(){g=jQuery(this).parent().find(".file_path");formfield=jQuery(g).attr("name");window.send_to_editor=window.send_to_download_url;tb_show("","media-upload.php?post_id="+woocommerce_writepanel_params.post_id+"&amp;type=downloadable_product&amp;from=wc01&amp;TB_iframe=true");return!1});window.send_to_download_url=function(a){file_url=jQuery(a).attr("href");file_url&&jQuery(g).val(file_url);tb_remove();window.send_to_editor=window.send_to_editor_default}});