1 line
7.9 KiB
JavaScript
1 line
7.9 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")))})}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()}};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 a=jQuery(".woocommerce_variation").size(),b={action:"woocommerce_add_variation",post_id:woocommerce_admin_meta_boxes_variations.post_id,loop:a,security:woocommerce_admin_meta_boxes_variations.add_variation_nonce};return jQuery.post(woocommerce_admin_meta_boxes_variations.ajax_url,b,function(a){jQuery(".woocommerce_variations").append(a),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")}),!1}),jQuery("#variable_product_options").on("click","button.link_all_variations",function(){var b=confirm(woocommerce_admin_meta_boxes_variations.i18n_link_all_variations);if(b){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 c={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,c,function(b){var c=parseInt(b);if(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(),jQuery("#variable_product_options").trigger("woocommerce_variations_added"),jQuery(".tips").tipTip({attribute:"data-tip",fadeIn:50,fadeOut:50})})}else a("#variable_product_options").unblock()})}return!1}),jQuery("#variable_product_options").on("click","button.remove_variation",function(a){a.preventDefault();var b=confirm(woocommerce_admin_meta_boxes_variations.i18n_remove_variation);if(b){var c=jQuery(this).parent().parent(),d=jQuery(this).attr("rel");if(d>0){jQuery(c).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={action:"woocommerce_remove_variation",variation_id:d,security:woocommerce_admin_meta_boxes_variations.delete_variation_nonce};jQuery.post(woocommerce_admin_meta_boxes_variations.ajax_url,e,function(){jQuery(c).fadeOut("300",function(){jQuery(c).remove()})})}else jQuery(c).fadeOut("300",function(){jQuery(c).remove()})}return!1}),jQuery(".wc-metaboxes-wrapper").on("click","a.bulk_edit",function(){var a=jQuery("select#field_to_edit").val();switch(a){case"toggle_enabled":var b=jQuery('input[name^="variable_enabled"]');b.attr("checked",!b.attr("checked"));break;case"toggle_downloadable":var b=jQuery('input[name^="variable_is_downloadable"]');b.attr("checked",!b.attr("checked")),jQuery("input.variable_is_downloadable").change();break;case"toggle_virtual":var b=jQuery('input[name^="variable_is_virtual"]');b.attr("checked",!b.attr("checked")),jQuery("input.variable_is_virtual").change();break;case"delete_all":var c=confirm(woocommerce_admin_meta_boxes_variations.i18n_delete_all_variations);if(c){var c=confirm(woocommerce_admin_meta_boxes_variations.i18n_last_warning);if(c){var d=[];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 a=jQuery(this).attr("rel");a>0&&d.push(a)});var e={action:"woocommerce_remove_variations",variation_ids:d,security:woocommerce_admin_meta_boxes_variations.delete_variations_nonce};jQuery.post(woocommerce_admin_meta_boxes_variations.ajax_url,e,function(){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(0===a.lastIndexOf("variable_regular_price",0))var f="variable_regular_price";else var f="variable_sale_price";var g=prompt(woocommerce_admin_meta_boxes_variations.i18n_enter_a_value_fixed_or_percent);jQuery(':input[name^="'+f+'["]').each(function(){var b=Number(jQuery(this).val());if(g=Number(g.indexOf("%")>=0?Number(b)/100*Number(g.replace(/\%/,"")):g),-1!=a.indexOf("increase"))var c=b+g;else var c=b-g;jQuery(this).val(c).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 g=prompt(woocommerce_admin_meta_boxes_variations.i18n_enter_a_value);jQuery(':input[name^="'+a+'["]').val(g).change();break;default:jQuery("select#field_to_edit").trigger(a)}}),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(),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;jQuery("#variable_product_options").on("click",".upload_image_button",function(a){var b=jQuery(this),c=b.attr("rel"),h=b.closest(".upload_image");if(f=h,e=c,a.preventDefault(),b.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(){attachment=d.state().get("selection").first().toJSON(),f.find(".upload_image_id").val(attachment.id),f.find(".upload_image_button").addClass("remove"),f.find("img").attr("src",attachment.url),wp.media.model.settings.post.id=g}),d.open()}}),jQuery("a.add_media").on("click",function(){wp.media.model.settings.post.id=g})}); |