4 lines
7.0 KiB
JavaScript
4 lines
7.0 KiB
JavaScript
/*!
|
|
* Variations Plugin
|
|
*/
|
|
!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},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(){$variation_form=a(this).closest(".variations_form"),$variation_form.find("input.variation_id").length>0?$variation_form.find("input.variation_id").val("").change():$variation_form.find("input[name=variation_id]").val("").change(),$variation_form.trigger("woocommerce_variation_select_change").trigger("check_variations",["",!1]),a(this).blur(),a().uniform&&a.isFunction(a.uniform.update)&&a.uniform.update()}).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);g?"hidden"===j.css("visibility")&&j.css("visibility","visible").hide().fadeIn():j.css("visibility","hidden")}).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_alt"),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(this).closest(".variations_form"),$variation_form.find(".variations select").each(function(b,d){current_attr_select=a(d),current_attr_select.data("attribute_options")||current_attr_select.data("attribute_options",current_attr_select.find("option:gt(0)").get()),current_attr_select.find("option:gt(0)").remove(),current_attr_select.append(current_attr_select.data("attribute_options")),current_attr_select.find("option:gt(0)").removeClass("attached"),current_attr_select.find("option:gt(0)").removeClass("enabled"),current_attr_select.find("option:gt(0)").removeAttr("disabled"),current_attr_name="undefined"!=typeof current_attr_select.data("attribute_name")?current_attr_select.data("attribute_name"):current_attr_select.attr("name");for(var e in c)if("undefined"!=typeof c[e]){var f=c[e].attributes;for(var g in f)if(f.hasOwnProperty(g)){var h=f[g];g==current_attr_name&&(variation_active=c[e].variation_is_active?"enabled":"",h?(h=a("<div/>").html(h).text(),h=h.replace(/'/g,"\\'"),h=h.replace(/"/g,'\\"'),current_attr_select.find('option[value="'+h+'"]').addClass("attached "+variation_active)):current_attr_select.find("option:gt(0)").addClass("attached "+variation_active))}}current_attr_select.find("option:gt(0):not(.attached)").remove(),current_attr_select.find("option:gt(0):not(.enabled)").attr("disabled","disabled")}),$variation_form.trigger("woocommerce_update_variation_values")}).on("found_variation",function(b,c){var e=a(this),f=a(this).closest(".product"),g=f.find("div.images img:eq(0)"),h=f.find("div.images a.zoom:eq(0)"),i=g.attr("data-o_src"),j=g.attr("data-o_title"),k=g.attr("data-o_alt"),l=h.attr("data-o_href"),m=c.image_src,n=c.image_link,o=c.image_title,p=c.image_alt;e.find(".variations_button").show(),e.find(".single_variation").html(c.price_html+c.availability_html),i===d&&(i=g.attr("src")?g.attr("src"):"",g.attr("data-o_src",i)),l===d&&(l=h.attr("href")?h.attr("href"):"",h.attr("data-o_href",l)),j===d&&(j=g.attr("title")?g.attr("title"):"",g.attr("data-o_title",j)),k===d&&(k=g.attr("alt")?g.attr("alt"):"",g.attr("data-o_alt",k)),m&&m.length>1?(g.attr("src",m).attr("alt",p).attr("title",o),h.attr("href",n).attr("title",o)):(g.attr("src",i).attr("alt",k).attr("title",j),h.attr("href",l).attr("title",j));var q=e.find(".single_variation_wrap"),r=f.find(".product_meta").find(".sku"),s=f.find(".product_weight"),t=f.find(".product_dimensions");r.attr("data-o_sku")||r.attr("data-o_sku",r.text()),s.attr("data-o_weight")||s.attr("data-o_weight",s.text()),t.attr("data-o_dimensions")||t.attr("data-o_dimensions",t.text()),r.text(c.sku?c.sku:r.attr("data-o_sku")),s.text(c.weight?c.weight:s.attr("data-o_weight")),t.text(c.dimensions?c.dimensions:t.attr("data-o_dimensions")),q.find(".quantity").show(),c.is_purchasable&&c.is_in_stock&&c.variation_is_visible||e.find(".variations_button").hide(),c.variation_is_visible||e.find(".single_variation").html("<p>"+wc_add_to_cart_variation_params.i18n_unavailable_text+"</p>"),c.min_qty?q.find(".quantity input.qty").attr("min",c.min_qty).val(c.min_qty):q.find(".quantity input.qty").removeAttr("min"),c.max_qty?q.find(".quantity input.qty").attr("max",c.max_qty):q.find(".quantity input.qty").removeAttr("max"),"yes"===c.is_sold_individually&&(q.find(".quantity input.qty").val("1"),q.find(".quantity").hide()),q.slideDown(200).trigger("show_variation",[c])}),$form.trigger("wc_variation_form"),$form},a(function(){return"undefined"==typeof wc_add_to_cart_variation_params?!1:(a(".variations_form").wc_variation_form(),void a(".variations_form .variations select").change())})}(jQuery,window,document); |