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

1 line
7.6 KiB
JavaScript

jQuery(function(a){function b(){a(".woocommerce_variations .woocommerce_variation").each(function(b,c){a(".variation_menu_order",c).val(parseInt(a(c).index(".woocommerce_variations .woocommerce_variation"),10))})}var c={items:".woocommerce_variation",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,c){c.item.removeAttr("style"),b()}};a("#variable_product_options").on("click","button.add_variation",function(){a(".woocommerce_variations").block({message:null,overlayCSS:{background:"#fff url("+woocommerce_admin_meta_boxes_variations.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:.6}});var b=a(".woocommerce_variation").size(),c={action:"woocommerce_add_variation",post_id:woocommerce_admin_meta_boxes_variations.post_id,loop:b,security:woocommerce_admin_meta_boxes_variations.add_variation_nonce};return a.post(woocommerce_admin_meta_boxes_variations.ajax_url,c,function(b){a(".woocommerce_variations").append(b),a(".tips").tipTip({attribute:"data-tip",fadeIn:50,fadeOut:50}),a("input.variable_is_downloadable, input.variable_is_virtual").change(),a(".woocommerce_variations").unblock(),a("#variable_product_options").trigger("woocommerce_variations_added")}),!1}),a("#variable_product_options").on("click","button.link_all_variations",function(){var b=window.confirm(woocommerce_admin_meta_boxes_variations.i18n_link_all_variations);if(b){a("#variable_product_options").block({message:null,overlayCSS:{background:"#fff url("+woocommerce_admin_meta_boxes_variations.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:.6}});var c={action:"woocommerce_link_all_variations",post_id:woocommerce_admin_meta_boxes_variations.post_id,security:woocommerce_admin_meta_boxes_variations.link_variation_nonce};a.post(woocommerce_admin_meta_boxes_variations.ajax_url,c,function(b){var c=parseInt(b,10);if(window.alert(1===c?c+" "+woocommerce_admin_meta_boxes_variations.i18n_variation_added:0===c||c>1?c+" "+woocommerce_admin_meta_boxes_variations.i18n_variations_added:woocommerce_admin_meta_boxes_variations.i18n_no_variations_added),c>0){var d=window.location.toString();d=d.replace("post-new.php?","post.php?post="+woocommerce_admin_meta_boxes_variations.post_id+"&action=edit&"),a("#variable_product_options").load(d+" #variable_product_options_inner",function(){a("#variable_product_options").unblock(),a("#variable_product_options").trigger("woocommerce_variations_added"),a(".tips").tipTip({attribute:"data-tip",fadeIn:50,fadeOut:50})})}else a("#variable_product_options").unblock()})}return!1}),a("#variable_product_options").on("click","button.remove_variation",function(b){b.preventDefault();var c=window.confirm(woocommerce_admin_meta_boxes_variations.i18n_remove_variation);if(c){var d=a(this).parent().parent(),e=a(this).attr("rel");if(e>0){a(d).block({message:null,overlayCSS:{background:"#fff url("+woocommerce_admin_meta_boxes_variations.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:.6}});var f={action:"woocommerce_remove_variation",variation_id:e,security:woocommerce_admin_meta_boxes_variations.delete_variation_nonce};a.post(woocommerce_admin_meta_boxes_variations.ajax_url,f,function(){a(d).fadeOut("300",function(){a(d).remove()})})}else a(d).fadeOut("300",function(){a(d).remove()})}return!1}),a(".wc-metaboxes-wrapper").on("click","a.bulk_edit",function(){var b,c,d,e=a("select#field_to_edit").val();switch(e){case"toggle_enabled":b=a('input[name^="variable_enabled"]'),b.attr("checked",!b.attr("checked"));break;case"toggle_downloadable":b=a('input[name^="variable_is_downloadable"]'),b.attr("checked",!b.attr("checked")),a("input.variable_is_downloadable").change();break;case"toggle_virtual":b=a('input[name^="variable_is_virtual"]'),b.attr("checked",!b.attr("checked")),a("input.variable_is_virtual").change();break;case"delete_all":if(c=window.confirm(woocommerce_admin_meta_boxes_variations.i18n_delete_all_variations),c&&(c=window.confirm(woocommerce_admin_meta_boxes_variations.i18n_last_warning))){var f=[];a(".woocommerce_variations .woocommerce_variation").block({message:null,overlayCSS:{background:"#fff url("+woocommerce_admin_meta_boxes_variations.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:.6}}),a(".woocommerce_variations .woocommerce_variation .remove_variation").each(function(){var b=a(this).attr("rel");b>0&&f.push(b)});var g={action:"woocommerce_remove_variations",variation_ids:f,security:woocommerce_admin_meta_boxes_variations.delete_variations_nonce};a.post(woocommerce_admin_meta_boxes_variations.ajax_url,g,function(){a(".woocommerce_variations .woocommerce_variation").fadeOut("300",function(){a(".woocommerce_variations .woocommerce_variation").remove()})})}break;case"variable_regular_price_increase":case"variable_regular_price_decrease":case"variable_sale_price_increase":case"variable_sale_price_decrease":var h;h=0===e.lastIndexOf("variable_regular_price",0)?"variable_regular_price":"variable_sale_price",d=window.prompt(woocommerce_admin_meta_boxes_variations.i18n_enter_a_value_fixed_or_percent),a(':input[name^="'+h+'"]').each(function(){var b,c=Number(a(this).val());d=Number(d.toString().indexOf("%")>=0?Number(c)/100*Number(d.replace(/\%/,"")):d),b=-1!==e.indexOf("increase")?c+d:c-d,a(this).val(b).change()});break;case"variable_regular_price":case"variable_sale_price":case"variable_stock":case"variable_weight":case"variable_length":case"variable_width":case"variable_height":case"variable_download_limit":case"variable_download_expiry":d=window.prompt(woocommerce_admin_meta_boxes_variations.i18n_enter_a_value),a(':input[name^="'+e+'"]').val(d).change();break;default:a("select#field_to_edit").trigger(e)}}),a("#variable_product_options").on("change","input.variable_is_downloadable",function(){a(this).closest(".woocommerce_variation").find(".show_if_variation_downloadable").hide(),a(this).is(":checked")&&a(this).closest(".woocommerce_variation").find(".show_if_variation_downloadable").show()}),a("#variable_product_options").on("change","input.variable_is_virtual",function(){a(this).closest(".woocommerce_variation").find(".hide_if_variation_virtual").show(),a(this).is(":checked")&&a(this).closest(".woocommerce_variation").find(".hide_if_variation_virtual").hide()}),a("input.variable_is_downloadable, input.variable_is_virtual").change(),a("#variable_product_options").on("woocommerce_variations_added",function(){a(".woocommerce_variations").sortable(c)}),a(".woocommerce_variations").sortable(c);var d,e,f,g=wp.media.model.settings.post.id;a("#variable_product_options").on("click",".upload_image_button",function(b){var c=a(this),h=c.attr("rel"),i=c.closest(".upload_image");if(f=i,e=h,b.preventDefault(),c.is(".remove"))f.find(".upload_image_id").val(""),f.find("img").attr("src",woocommerce_admin_meta_boxes_variations.woocommerce_placeholder_img_src),f.find(".upload_image_button").removeClass("remove");else{if(d)return d.uploader.uploader.param("post_id",e),void d.open();wp.media.model.settings.post.id=e,d=wp.media.frames.variable_image=wp.media({title:woocommerce_admin_meta_boxes_variations.i18n_choose_image,button:{text:woocommerce_admin_meta_boxes_variations.i18n_set_image},states:[new wp.media.controller.Library({title:woocommerce_admin_meta_boxes_variations.i18n_choose_image,filterable:"all"})]}),d.on("select",function(){var a=d.state().get("selection").first().toJSON();f.find(".upload_image_id").val(a.id),f.find(".upload_image_button").addClass("remove"),f.find("img").attr("src",a.url),wp.media.model.settings.post.id=g}),d.open()}}),a("a.add_media").on(" click",function(){wp.media.model.settings.post.id=g})});