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

1 line
3.3 KiB
JavaScript
Raw Normal View History

jQuery(document).ready(function(e){function t(e,t){var n=!0;for(name in e){var r=e[name],i=t[name];r.length!=0&&i.length!=0&&r!=i&&(n=!1)}return n}function n(e){var n=[];for(var r=0;r<product_variations.length;r++){var i=product_variations[r],s=i.variation_id;t(i.attributes,e)&&n.push(i)}return n}function r(t){e(".variations select").each(function(n,r){current_attr_select=e(r);current_attr_select.find("option:gt(0)").attr("disabled","disabled");var i=current_attr_select.attr("name");for(num in t){var s=t[num].attributes;for(attr_name in s){var o=s[attr_name];if(attr_name==i)if(o){o=e("<div/>").html(o).text();o=o.replace(/'/g,"\\'");o=o.replace(/"/g,'\\"');current_attr_select.find('option[value="'+o+'"]').removeAttr("disabled")}else current_attr_select.find("option").removeAttr("disabled")}}});e(document).trigger("woocommerce_update_variation_values")}function i(t){var n=e("div.images img:eq(0)"),r=e("div.images a.zoom:eq(0)"),i=e(n).attr("data-o_src"),s=e(r).attr("data-o_href"),o=t.image_src,u=t.image_link;e(".variations_button").show();e(".single_variation").html(t.price_html+t.availability_html);i||e(n).attr("data-o_src",e(n).attr("src"));s||e(r).attr("data-o_href",e(r).attr("href"));if(o&&o.length>1){e(n).attr("src",o);e(r).attr("href",u)}else{e(n).attr("src",i);e(r).attr("href",s)}t.sku?e(".product_meta").find(".sku").text(t.sku):e(".product_meta").find(".sku").text("");e(".single_variation_wrap").find(".quantity").show();t.min_qty?e(".single_variation_wrap").find("input[name=quantity]").attr("data-min",t.min_qty).val(t.min_qty):e(".single_variation_wrap").find("input[name=quantity]").removeAttr("data-min");t.max_qty?e(".single_variation_wrap").find("input[name=quantity]").attr("data-max",t.max_qty):e(".single_variation_wrap").find("input[name=quantity]").removeAttr("data-max");if(t.is_sold_individually=="yes"){e(".single_variation_wrap").find("input[name=quantity]").val("1");e(".single_variation_wrap").find(".quantity").hide()}e(".single_variation_wrap").slideDown("200").trigger("variationWrapShown").trigger("show_variation")}function s(t,s){var u=!0,a=!1,f=!1,l={};e(".variations select").each(function(){if(t&&e(this).attr("name")==t){u=!1;l[e(this).attr("name")]=""}else{e(this).val().length==0?u=!1:a=!0;value=e(this).val().replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/'/g,"&#039;").replace(/</g,"&lt;").replace(/>/g,"&gt;");l[e(this).attr("name")]=value}});var c=n(l);if(u){var h=c.pop();if(h){e("form input[name=variation_id]").val(h.variation_id).change();i(h)}else{e(".variations select").val("");s||o()}}else{r(c);s||o()}a?e(".reset_variations").css("visibility")=="hidden"&&e(".reset_variations").css("visibility","visible").hide().fadeIn():e(".reset_variations").css("visibility","hidden")}function o(){var t=e("div.images img:eq(0)"),n=e("div.images a.zoom:eq(0)"),r=e(t).attr("data-o_src"),i=e(n).attr("data-o_href");if(r&&i){e(t).attr("src",r);e(n).attr("href",i)}}e(".reset_variations").click(function(){e(".variations select").val("").change();return!1}).css("visibility","hidden");e(".variations select").change(function(){e("form input[name=variation_id]").val("").change();e(".single_variation_wrap").hide();e(".single_variation").text("");s("",!1);e(this).blur();e().uniform&&e.isFunction(e.uniform.update)&&e.uniform.update()}).bind("focusin",function(){s(e(this).attr("name"),!0)}).change()});