1 line
9.4 KiB
JavaScript
1 line
9.4 KiB
JavaScript
jQuery(function(d){d("#upsell_product_data").bind("keypress",function(g){if(g.keyCode==13){return false}});d("ul.tabs").show();d("div.panel-wrap").each(function(){d("div.panel:not(div.panel:first)",this).hide()});d("ul.tabs a").click(function(){var g=d(this).closest("div.panel-wrap");d("ul.tabs li",g).removeClass("active");d(this).parent().addClass("active");d("div.panel",g).hide();d(d(this).attr("href")).show();return false});d("#order_items_list button.remove_row").live("click",function(){var g=confirm(woocommerce_writepanel_params.remove_item_notice);if(g){d(this).closest("tr.item").hide();d("input",d(this).closest("tr.item")).val("")}return false});d("button.calc_totals").live("click",function(){var p=confirm(woocommerce_writepanel_params.cart_total);if(p){var h=d("#order_items_list tr.item").size();var n=0;var o=d("input#_order_discount").val();var g=d("input#_order_shipping").val();var k=parseFloat(d("input#_order_shipping_tax").val());var l=0;var j=0;var m=0;if(!o){o=0}if(!g){g=0}if(!k){k=0}if(h>0){for(i=0;i<h;i++){itemCost=d("input[name^=item_cost]:eq("+i+")").val();itemQty=parseInt(d("input[name^=item_quantity]:eq("+i+")").val());itemTax=d("input[name^=item_tax_rate]:eq("+i+")").val();if(!itemCost){itemCost=0}if(!itemTax){itemTax=0}if(!itemQty){itemQty=0}totalItemTax=0;totalItemCost=itemCost*itemQty;if(itemTax&&itemTax>0){taxRate=itemTax/100;itemTaxAmount=((itemCost*taxRate)*100);itemTaxAmount=itemTaxAmount.toFixed(2);totalItemTax=Math.round(itemTaxAmount)/100;totalItemTax=totalItemTax*itemQty}j=j+totalItemCost;l=l+totalItemTax}}n=j;m=parseFloat(n)+parseFloat(l)-parseFloat(o)+parseFloat(g)+parseFloat(k);if(m<0){m=0}d("input#_order_subtotal").val(n.toFixed(2));d("input#_order_tax").val(l.toFixed(2));d("input#_order_shipping_tax").val(k.toFixed(2));d("input#_order_total").val(m.toFixed(2))}return false});d("button.add_shop_order_item").click(function(){var j=d("select.add_item_id").val();if(j){d("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:0.6}});var g=d("table.woocommerce_order_items tbody tr.item").size();var h={action:"woocommerce_add_order_item",item_to_add:d("select.add_item_id").val(),index:g,security:woocommerce_writepanel_params.add_order_item_nonce};d.post(woocommerce_writepanel_params.ajax_url,h,function(k){d("table.woocommerce_order_items tbody#order_items_list").append(k);d("table.woocommerce_order_items").unblock();d("select.add_item_id").css("border-color","").val("");d(".tips").easyTooltip()})}else{d("select.add_item_id").css("border-color","red")}});d("button.add_meta").live("click",function(){var g=d(this).closest("tr.item").attr("rel");d(this).closest("table.meta").find(".meta_items").append('<tr><td><input type="text" name="meta_name['+g+'][]" placeholder="'+woocommerce_writepanel_params.meta_name+'" /></td><td><input type="text" name="meta_value['+g+'][]" placeholder="'+woocommerce_writepanel_params.meta_value+'" /></td><td><button class="remove_meta button">×</button></td></tr>');return false});d("button.remove_meta").live("click",function(){var g=confirm("Remove this meta key?");if(g){d(this).closest("tr").remove()}return false});d("button.billing-same-as-shipping").live("click",function(){var g=confirm(woocommerce_writepanel_params.copy_billing);if(g){d("input#shipping_first_name").val(d("input#billing_first_name").val());d("input#shipping_last_name").val(d("input#billing_last_name").val());d("input#shipping_company").val(d("input#billing_company").val());d("input#shipping_address_1").val(d("input#billing_address_1").val());d("input#shipping_address_2").val(d("input#billing_address_2").val());d("input#shipping_city").val(d("input#billing_city").val());d("input#shipping_postcode").val(d("input#billing_postcode").val());d("input#shipping_country").val(d("input#billing_country").val());d("input#shipping_state").val(d("input#billing_state").val())}return false});d("select#product-type").change(function(){var g=d(this).val();d(".show_if_simple, .show_if_variable, .show_if_grouped").hide();if(g=="simple"){d(".show_if_simple").show()}else{if(g=="variable"){d(".show_if_variable").show()}else{if(g=="grouped"){d(".show_if_grouped").show();d("input#downloadable").removeAttr("checked").change()}}}d("ul.tabs li:visible").eq(0).find("a").click();d("input#manage_stock").change();d("body").trigger("woocommerce-product-type-change",g,d(this))}).change();d("input#downloadable").change(function(){d(".show_if_downloadable").hide();if(d("input#downloadable").is(":checked")){d(".show_if_downloadable").show()}if(d(".downloads_tab").is(".active")){d("ul.tabs li:visible").eq(0).find("a").click()}}).change();d("input#virtual").change(function(){d(".show_if_virtual").hide();if(d("input#virtual").is(":checked")){d(".show_if_virtual").show()}}).change();d("input#manage_stock").change(function(){if(d(this).is(":checked")){d("div.stock_fields").show()}else{d("div.stock_fields").hide()}}).change();var e=d("#sale_price_dates_from, #sale_price_dates_to").datepicker({defaultDate:"",dateFormat:"yy-mm-dd",numberOfMonths:1,showButtonPanel:true,showOn:"button",buttonImage:woocommerce_writepanel_params.calendar_image,buttonImageOnly:true,onSelect:function(j){var k=this.id=="sale_price_dates_from"?"minDate":"maxDate",g=d(this).data("datepicker"),h=d.datepicker.parseDate(g.settings.dateFormat||d.datepicker._defaults.dateFormat,j,g.settings);e.not(this).datepicker("option",k,h)}});d(".date-picker").datepicker({dateFormat:"yy-mm-dd",numberOfMonths:1,showButtonPanel:true,showOn:"button",buttonImage:woocommerce_writepanel_params.calendar_image,buttonImageOnly:true});d("#attributes_list select.multiselect").multiselect({noneSelectedText:woocommerce_writepanel_params.select_terms,selectedList:4});var c=d("#attributes_list").children("tr").get();c.sort(function(h,g){var k=d(h).attr("rel");var j=d(g).attr("rel");return(k<j)?-1:(k>j)?1:0});d(c).each(function(g,h){d("#attributes_list").append(h)});function a(){d("table.woocommerce_attributes, table.woocommerce_variable_attributes").each(function(){if(d("tbody tr",this).size()==0){d(this).parent().hide()}else{d(this).parent().show()}})}a();function b(){d("#attributes_list tr").each(function(g,h){d(".attribute_position",h).val(parseInt(d(h).index("#attributes_list tr")))})}d("button.add_attribute").click(function(){var h=d("table.woocommerce_attributes tbody tr").size();var j=d("select.attribute_taxonomy").val();if(!j){var k=d("select#product-type").val();if(k!="variable"){enable_variation='style="display:none;"'}else{enable_variation=""}d("table.woocommerce_attributes tbody").append('<tr><td><input type="text" name="attribute_names['+h+']" /><input type="hidden" name="attribute_is_taxonomy['+h+']" value="0" /><input type="hidden" name="attribute_position['+h+']" class="attribute_position" value="'+h+'" /></td><td><input type="text" name="attribute_values['+h+']" /></td><td class="center"><input type="checkbox" checked="checked" name="attribute_visibility['+h+']" value="1" /></td><td class="center enable_variation" '+enable_variation+'><input type="checkbox" name="attribute_variation['+h+']" value="1" /></td><td class="center"><button type="button" class="remove_row button">×</button></td></tr>')}else{var g=d("table.woocommerce_attributes tbody tr."+j);d("table.woocommerce_attributes tbody").append(d(g));d(g).show();b()}a()});d("button.hide_row").live("click",function(){var g=confirm("Remove this attribute?");if(g){d(this).parent().parent().find("select, input[type=text]").val("");d(this).parent().parent().hide();a()}return false});d("#attributes_list button.remove_row").live("click",function(){var g=confirm("Remove this attribute?");if(g){d(this).parent().parent().remove();a();b()}return false});d("table.woocommerce_attributes tbody").sortable({items:"tr",cursor:"move",axis:"y",scrollSensitivity:40,helper:function(h,g){g.children().each(function(){d(this).width(d(this).width())});return g},start:function(g,h){h.item.css("background-color","#f6f6f6")},stop:function(g,h){h.item.removeAttr("style");b()}});d(".multi_select_products button").live("click",function(){var n=d(this).parent().parent().parent().parent();var g=d(this);var j=g.parent().parent();if(j.is(".multi_select_products_target_upsell")||j.is(".multi_select_products_target_crosssell")){g.parent().remove()}else{if(g.is(".add_upsell")){var l=d(".multi_select_products_target_upsell",d(n));var m="upsell_ids[]"}else{var l=d(".multi_select_products_target_crosssell",d(n));var m="crosssell_ids[]"}var h=d("li[rel="+g.parent().attr("rel")+"]",l);if(d(h).size()>0){return false}var k=g.parent().clone();k.find("button:eq(0)").html("×");k.find("button:eq(1)").remove();k.find("input").val(g.parent().attr("rel"));k.find(".product_id").attr("name",m);k.appendTo(l)}});var f;d(".multi_select_products #product_search").bind("keyup click",function(){d(".multi_select_products_source").addClass("loading");d(".multi_select_products_source li:not(.product_search)").remove();if(f){f.abort()}var j=d(this).val();var g=this;var h=d(this).attr("rel");if(j.length<3){d(".multi_select_products_source").removeClass("loading");return}var k={name:h,search:encodeURI(j),action:"woocommerce_upsell_crosssell_search_products",security:woocommerce_writepanel_params.upsell_crosssell_search_products_nonce};f=d.ajax({url:woocommerce_writepanel_params.ajax_url,data:k,type:"POST",success:function(l){d(".multi_select_products_source").removeClass("loading");d(".multi_select_products_source li:not(.product_search)").remove();d(g).parent().parent().append(l)}})})}); |