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

4 lines
7.6 KiB
JavaScript
Raw Normal View History

/*!
* Variations Plugin
*/
2015-05-29 13:55:54 +00:00
!function(a,b,c,d){a.fn.wc_variation_form=function(){return a.fn.wc_variation_form.find_matching_variations=function(b,c){for(var d=[],e=0;e<b.length;e++){{var f=b[e];f.variation_id}a.fn.wc_variation_form.variations_match(f.attributes,c)&&d.push(f)}return d},a.fn.wc_variation_form.variations_match=function(a,b){var c=!0;for(var e in a)if(a.hasOwnProperty(e)){var f=a[e],g=b[e];f!==d&&g!==d&&0!==f.length&&0!==g.length&&f!==g&&(c=!1)}return c},a.fn.wc_variation_form.get_variation_description_html=function(a,b){var c,d=a.data("product_variations");return b>0&&(b--,d[b].hasOwnProperty("variation_description"))?c='<p class="woocommerce-variation-description woocommerce-variation-description-'+d[b].variation_id+'">'+d[b].variation_description+"</p>":""},this.unbind("check_variations update_variation_values found_variation"),this.find(".reset_variations").unbind("click"),this.find(".variations select").unbind("change focusin"),$form=this.on("click",".reset_variations",function(){a(this).closest(".variations_form").find(".variations select").val("").change();var b=a(this).closest(".product").find(".sku"),c=a(this).closest(".product").find(".product_weight"),d=a(this).closest(".product").find(".product_dimensions");return b.attr("data-o_sku")&&b.text(b.attr("data-o_sku")),c.attr("data-o_weight")&&c.text(c.attr("data-o_weight")),d.attr("data-o_dimensions")&&d.text(d.attr("data-o_dimensions")),!1}).on("change",".variations select",function(){var b=a(this).closest(".variations_form"),c=a.fn.wc_variation_form.get_variation_description_html(b,this.selectedIndex);b.find(".variations").next(".woocommerce-variation-description").remove(),c&&b.find(".variations").after(c),b.find("input.variation_id").length>0?b.find("input.variation_id").val("").change():b.find("input[name=variation_id]").val("").change(),b.trigger("woocommerce_variation_select_change").trigger("check_variations",["",!1]),a(this).blur(),a().uniform&&a.isFunction(a.uniform.update)&&a.uniform.update(),b.trigger("woocommerce_variation_has_changed")}).on("focusin touchstart",".variations select",function(){$variation_form=a(this).closest(".variations_form"),attribute_name="undefined"!=typeof a(this).data("attribute_name")?a(this).data("attribute_name"):a(this).attr("name"),$variation_form.trigger("woocommerce_variation_select_focusin").trigger("check_variations",[attribute_name,!0])}).on("check_variations",function(c,d,e){var f=!0,g=!1,h={},i=a(this),j=i.find(".reset_variations");i.find(".variations select").each(function(){attribute_name="undefined"!=typeof a(this).data("attribute_name")?a(this).data("attribute_name"):a(this).attr("name"),0===a(this).val().length?f=!1:g=!0,d&&attribute_name===d?(f=!1,h[attribute_name]=""):(value=a(this).val(),h[attribute_name]=value)});var k=parseInt(i.data("product_id")),l=i.data("product_variations");l||(l=b.product_variations.product_id),l||(l=b.product_variations),l||(l=b["product_variations_"+k]);var m=a.fn.wc_variation_form.find_matching_variations(l,h);if(f){var n=m.shift();n?($variation_input=i.find(i.find("input.variation_id").length>0?"input.variation_id":"input[name=variation_id]"),$variation_input.val(n.variation_id).change(),i.trigger("found_variation",[n])):(i.find(".variations select").val(""),e||i.trigger("reset_image"),alert(wc_add_to_cart_variation_params.i18n_no_matching_variations_text))}else i.trigger("update_variation_values",[m]),e||i.trigger("reset_image"),d||i.find(".single_variation_wrap").slideUp(200).trigger("hide_variation");g?"hidden"===j.css("visibility")&&j.css("visibility","visible").hide().fadeIn():(j.css("visibility","hidden"),$sku=a(this).closest(".product").find(".sku"),$sku.text($sku.attr("data-o_sku")))}).on("reset_image",function(){var b=a(this).closest(".product"),c=b.find("div.images img:eq(0)"),e=b.find("div.images a.zoom:eq(0)"),f=c.attr("data-o_src"),g=c.attr("data-o_title"),h=c.attr("data-o_title"),i=e.attr("data-o_href");f!==d&&c.attr("src",f),i!==d&&e.attr("href",i),g!==d&&(c.attr("title",g),e.attr("title",g)),h!==d&&c.attr("alt",h)}).on("update_variation_values",function(b,c){$variation_form=a