woocommerce/assets/js/frontend/add-to-cart-variation.min.js

4 lines
7.5 KiB
JavaScript
Raw Normal View History

/*!
* Variations Plugin
*/
(function(d,c,a,e){d.fn.wc_variation_form=function(){var p=this,g=p.find(".single_variation"),k=p.closest(".product"),o=parseInt(p.data("product_id"),10),f=p.data("product_variations"),i=f===false,j=false,l=p.find(".reset_variations"),n=wp.template("variation-template"),m=wp.template("unavailable-variation-template"),h=p.find(".single_variation_wrap");h.show();p.unbind("check_variations update_variation_values found_variation");p.find(".reset_variations").unbind("click");p.find(".variations select").unbind("change focusin");p.on("click",".reset_variations",function(){p.find(".variations select").val("").change();p.trigger("reset_data");return false}).on("hide_variation",function(){p.find(".single_add_to_cart_button").attr("disabled","disabled").attr("title",wc_add_to_cart_variation_params.i18n_make_a_selection_text);return false}).on("show_variation",function(s,r,q){if(q){p.find(".single_add_to_cart_button").removeAttr("disabled").removeAttr("title")}else{p.find(".single_add_to_cart_button").attr("disabled","disabled").attr("title",wc_add_to_cart_variation_params.i18n_unavailable_text)}return false}).on("reload_product_variations",function(){f=p.data("product_variations");i=f===false}).on("reset_data",function(){k.find(".product_meta").find(".sku").wc_reset_content();d(".product_weight").wc_reset_content();d(".product_dimensions").wc_reset_content();p.trigger("reset_image");g.slideUp(200).trigger("hide_variation")}).on("reset_image",function(){p.wc_variations_image_update(false)}).on("change",".variations select",function(){p.find('input[name="variation_id"], input.variation_id').val("").change();p.find(".wc-no-matching-variations").remove();if(i){if(j){j.abort()}var q=true;var r=false;var s={};p.find(".variations select").each(function(){var t=d(this).data("attribute_name")||d(this).attr("name");if(d(this).val().length===0){q=false}else{r=true}s[t]=d(this).val()});if(q){s.product_id=o;j=d.ajax({url:wc_cart_fragments_params.wc_ajax_url.toString().replace("%%endpoint%%","get_variation"),type:"POST",data:s,success:function(t){if(t){p.trigger("found_variation",[t])}else{p.trigger("reset_data");p.find(".single_variation").after('<p class="wc-no-matching-variations woocommerce-info">'+wc_add_to_cart_variation_params.i18n_no_matching_variations_text+"</p>");p.find(".wc-no-matching-variations").slideDown(200)}}})}else{p.trigger("reset_data")}if(r){if(l.css("visibility")==="hidden"){l.css("visibility","visible").hide().fadeIn()}}else{l.css("visibility","hidden")}}else{p.trigger("woocommerce_variation_select_change");p.trigger("check_variations",["",false]);d(this).blur()}d(".product.has-default-attributes > .images").fadeTo(200,1);p.trigger("woocommerce_variation_has_changed")}).on("focusin touchstart",".variations select",function(){d(this).find("option:selected").attr("selected","selected");if(!i){p.trigger("woocommerce_variation_select_focusin");p.trigger("check_variations",[d(this).data("attribute_name")||d(this).attr("name"),true])}}).on("found_variation",function(v,t){var r=k.find(".product_meta").find(".sku"),w=k.find(".product_weight"),u=k.find(".product_dimensions"),q=h.find(".quantity"),s=true;if(t.sku){r.wc_set_content(t.sku)}else{r.wc_reset_content()}if(t.weight){w.wc_set_content(t.weight)}else{w.wc_reset_content()}if(t.dimensions){u.wc_set_content(t.dimensions)}else{u.wc_reset_content()}p.wc_variations_image_update(t);if(!t.variation_is_visible){g.html(m);p.find('input[name="variation_id"], input.variation_id').val("").change()}else{g.html(n({variation:t}));p.find('input[name="variation_id"], input.variation_id').val(t.variation_id).change()}if(t.is_sold_individually==="yes"){q.find("input.qty").val("1").attr("min","1").attr("max","");q.hide()}else{q.find("input.qty").attr("min",t.min_qty).attr("max",t.max_qty);q.show()}if(!t.is_purchasable||!t.is_in_stock||!t.variation_is_visible){s=false}if(d.trim(g.text())){g.slideDown(200).trigger("show_variation",[t,s])}else{g.show().trigger("show_variation",[t,s])}}).on("check_variations",function(q,r,z){if(i){return}var w=true,v=false,x={},y=d(this),u=y.find(".reset_variatio