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

1 line
7.7 KiB
JavaScript

jQuery(function(e){function n(){e(".woocommerce_variations .woocommerce_variation").each(function(t,n){e(".variation_menu_order",n).val(parseInt(e(n).index(".woocommerce_variations .woocommerce_variation")))})}var t={items:".woocommerce_variation",cursor:"move",axis:"y",handle:"h3",scrollSensitivity:40,forcePlaceholderSize:!0,helper:"clone",opacity:.65,placeholder:"wc-metabox-sortable-placeholder",start:function(e,t){t.item.css("background-color","#f6f6f6")},stop:function(e,t){t.item.removeAttr("style");n()}};jQuery("#variable_product_options").on("click","button.add_variation",function(){jQuery(".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 e=jQuery(".woocommerce_variation").size(),t={action:"woocommerce_add_variation",post_id:woocommerce_admin_meta_boxes_variations.post_id,loop:e,security:woocommerce_admin_meta_boxes_variations.add_variation_nonce};jQuery.post(woocommerce_admin_meta_boxes_variations.ajax_url,t,function(e){jQuery(".woocommerce_variations").append(e);jQuery(".tips").tipTip({attribute:"data-tip",fadeIn:50,fadeOut:50});jQuery("input.variable_is_downloadable, input.variable_is_virtual").change();jQuery(".woocommerce_variations").unblock();jQuery("#variable_product_options").trigger("woocommerce_variations_added")});return!1});jQuery("#variable_product_options").on("click","button.link_all_variations",function(){var t=confirm(woocommerce_admin_meta_boxes_variations.i18n_link_all_variations);if(t){jQuery("#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 n={action:"woocommerce_link_all_variations",post_id:woocommerce_admin_meta_boxes_variations.post_id,security:woocommerce_admin_meta_boxes_variations.link_variation_nonce};jQuery.post(woocommerce_admin_meta_boxes_variations.ajax_url,n,function(t){var n=parseInt(t);n==1?alert(n+" "+woocommerce_admin_meta_boxes_variations.i18n_variation_added):n==0||n>1?alert(n+" "+woocommerce_admin_meta_boxes_variations.i18n_variations_added):alert(woocommerce_admin_meta_boxes_variations.i18n_no_variations_added);if(n>0){var r=window.location.toString();r=r.replace("post-new.php?","post.php?post="+woocommerce_admin_meta_boxes_variations.post_id+"&action=edit&");e("#variable_product_options").load(r+" #variable_product_options_inner",function(){e("#variable_product_options").unblock();jQuery("#variable_product_options").trigger("woocommerce_variations_added")})}else e("#variable_product_options").unblock()})}return!1});jQuery("#variable_product_options").on("click","button.remove_variation",function(e){e.preventDefault();var t=confirm(woocommerce_admin_meta_boxes_variations.i18n_remove_variation);if(t){var n=jQuery(this).parent().parent(),r=jQuery(this).attr("rel");if(r>0){jQuery(n).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 i={action:"woocommerce_remove_variation",variation_id:r,security:woocommerce_admin_meta_boxes_variations.delete_variation_nonce};jQuery.post(woocommerce_admin_meta_boxes_variations.ajax_url,i,function(e){jQuery(n).fadeOut("300",function(){jQuery(n).remove()})})}else jQuery(n).fadeOut("300",function(){jQuery(n).remove()})}return!1});jQuery(".wc-metaboxes-wrapper").on("click","a.bulk_edit",function(e){var t=jQuery("select#field_to_edit").val();switch(t){case"toggle_enabled":var n=jQuery('input[name^="variable_enabled"]');n.attr("checked",!n.attr("checked"));break;case"toggle_downloadable":var n=jQuery('input[name^="variable_is_downloadable"]');n.attr("checked",!n.attr("checked"));jQuery("input.variable_is_downloadable").change();break;case"toggle_virtual":var n=jQuery('input[name^="variable_is_virtual"]');n.attr("checked",!n.attr("checked"));jQuery("input.variable_is_virtual").change();break;case"delete_all":var r=confirm(woocommerce_admin_meta_boxes_variations.i18n_delete_all_variations);if(r){var r=confirm(woocommerce_admin_meta_boxes_variations.i18n_last_warning);if(r){var i=[];jQuery(".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}});jQuery(".woocommerce_variations .woocommerce_variation .remove_variation").each(function(){var e=jQuery(this).attr("rel");e>0&&i.push(e)});var s={action:"woocommerce_remove_variations",variation_ids:i,security:woocommerce_admin_meta_boxes_variations.delete_variations_nonce};jQuery.post(woocommerce_admin_meta_boxes_variations.ajax_url,s,function(e){jQuery(".woocommerce_variations .woocommerce_variation").fadeOut("300",function(){jQuery(".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":if(t.lastIndexOf("variable_regular_price",0)===0)var o="variable_regular_price";else var o="variable_sale_price";var u=prompt(woocommerce_admin_meta_boxes_variations.i18n_enter_a_value_fixed_or_percent);jQuery(':input[name^="'+o+'["]').each(function(){var e=Number(jQuery(this).val());u.indexOf("%")>=0?u=Number(Number(e)/100*Number(u.replace(/\%/,""))):u=Number(u);if(t.indexOf("increase")!=-1)var n=e+u;else var n=e-u;jQuery(this).val(n).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":var u=prompt(woocommerce_admin_meta_boxes_variations.i18n_enter_a_value);jQuery(':input[name^="'+t+'["]').val(u).change();break;default:jQuery("select#field_to_edit").trigger(t)}});jQuery("#variable_product_options").on("change","input.variable_is_downloadable",function(){jQuery(this).closest(".woocommerce_variation").find(".show_if_variation_downloadable").hide();jQuery(this).is(":checked")&&jQuery(this).closest(".woocommerce_variation").find(".show_if_variation_downloadable").show()});jQuery("#variable_product_options").on("change","input.variable_is_virtual",function(){jQuery(this).closest(".woocommerce_variation").find(".hide_if_variation_virtual").show();jQuery(this).is(":checked")&&jQuery(this).closest(".woocommerce_variation").find(".hide_if_variation_virtual").hide()});jQuery("input.variable_is_downloadable, input.variable_is_virtual").change();e("#variable_product_options").on("woocommerce_variations_added",function(){e(".woocommerce_variations").sortable(t)});e(".woocommerce_variations").sortable(t);var r,i,s,o=wp.media.model.settings.post.id;jQuery("#variable_product_options").on("click",".upload_image_button",function(e){var t=jQuery(this),n=t.attr("rel"),u=t.closest(".upload_image");s=u;i=n;e.preventDefault();if(t.is(".remove")){s.find(".upload_image_id").val("");s.find("img").attr("src",woocommerce_admin_meta_boxes_variations.woocommerce_placeholder_img_src);s.find(".upload_image_button").removeClass("remove")}else{if(r){r.uploader.uploader.param("post_id",i);r.open();return}wp.media.model.settings.post.id=i;r=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}});r.on("select",function(){attachment=r.state().get("selection").first().toJSON();s.find(".upload_image_id").val(attachment.id);s.find(".upload_image_button").addClass("remove");s.find("img").attr("src",attachment.url);wp.media.model.settings.post.id=o});r.open()}});jQuery("a.add_media").on("click",function(){wp.media.model.settings.post.id=o})});