1/* 2 * Tickets Variable Product Javascript 3 * @version: 1.4.1 4 */ 5 6 7//* Variations Plugin 8(function (e, t, n, r) { 9e.fn.wc_variation_form = function () { 10 e.fn.wc_variation_form.find_matching_variations = function (t, n) { 11 var r = []; 12 for (var i = 0; i < t.length; i++) { 13 var s = t[i], 14 o = s.variation_id; 15 e.fn.wc_variation_form.variations_match(s.attributes, n) && r.push(s) 16 } 17 return r 18 }; 19 e.fn.wc_variation_form.variations_match = function (e, t) { 20 var n = !0; 21 for (attr_name in e) { 22 var i = e[attr_name], 23 s = t[attr_name]; 24 i !== r && s !== r && i.length != 0 && s.length != 0 && i != s && (n = !1) 25 } 26 return n 27 }; 28 29 this.unbind("check_variations update_variation_values found_variation"); 30 this.find(".reset_variations").unbind("click"); 31 this.find(".variations select").unbind("change focusin"); 32 return this.on("click", ".reset_variations", function (t) { 33 e(this).closest("form.variations_form").find(".variations select").val("").change(); 34 var n = e(this).closest(".product").find(".sku"), 35 r = e(this).closest(".product").find(".product_weight"), 36 i = e(this).closest(".product").find(".product_dimensions"); 37 n.attr("data-o_sku") && n.text(n.attr("data-o_sku")); 38 r.attr("data-o_weight") && r.text(r.attr("data-o_weight")); 39 i.attr("data-o_dimensions") && i.text(i.attr("data-o_dimensions")); 40 return !1 41 }).on("change", ".variations select", function (t) { 42 43 $variation_form = e(this).closest("form.variations_form"); 44 $variation_form.find("input[name=variation_id]").val("").change(); 45 $variation_form.trigger("woocommerce_variation_select_change").trigger("check_variations", ["", !1]); 46 e(this).blur(); 47 e().uniform && e.isFunction(e.uniform.update) && e.uniform.update() 48 }).on("focusin", ".variations select", function (t) { 49 $variation_form = e(this).closest("form.variations_form"); 50 $variation_form.trigger("woocommerce_variation_select_focusin").trigger("check_variations", [e(this).attr("name"), !0]) 51 }).on("check_variations", function (n, r, i) { 52 var s = !0, 53 o = !1, 54 u = !1, 55 a = {}, 56 f = e(this), 57 l = f.find(".reset_variations"); 58 f.find(".variations select").each(function () { 59 e(this).val().length == 0 ? s = !1 : o = !0; 60 if (r && e(this).attr("name") == r) { 61 s = !1; 62 a[e(this).attr("name")] = "" 63 } else { 64 value = e(this).val(); 65 a[e(this).attr("name")] = value 66 } 67 }); 68 var c = parseInt(f.data("product_id")), 69 h = f.data("product_variations"); 70 h || (h = t.product_variations[c]); 71 h || (h = t.product_variations); 72 h || (h = t["product_variations_" + c]); 73 var p = e.fn.wc_variation_form.find_matching_variations(h, a); 74 if (s) { 75 var d = p.pop(); 76 if (d) { 77 f.find("input[name=variation_id]").val(d.variation_id).change(); 78 f.trigger("found_variation", [d]) 79 } else { 80 f.find(".variations select").val(""); 81 i || f.trigger("reset_image"); 82 alert(woocommerce_params.i18n_no_matching_variations_text) 83 } 84 } else { 85 f.trigger("update_variation_values", [p]); 86 i || f.trigger("reset_image"); 87 r || f.find(".single_variation_wrap").slideUp("200") 88 } 89 o ? l.css("visibility") == "hidden" && l.css("visibility", "visible").hide().fadeIn() : l.css("visibility", "hidden") 90 }).on("reset_image", function (t) { 91 var n = e(this).closest(".product"), 92 r = n.find("div.images img:eq(0)"), 93 i = n.find("div.images a.zoom:eq(0)"), 94 s = r.attr("data-o_src"), 95 o = r.attr("data-o_title"), 96 u = i.attr("data-o_href"); 97 s && r.attr("src", s); 98 u && i.attr("href", u); 99 if (o) { 100 r.attr("alt", o).attr("title", o); 101 i.attr("title", o) 102 } 103 }).on("update_variation_values", function (t, n) { 104 $variation_form = e(this).closest("form.variations_form"); 105 $variation_form.find(".variations select").each(function (t, r) { 106 current_attr_select = e(r); 107 current_attr_select.data("attribute_options") || current_attr_select.data("attribute_options", current_attr_select.find("option:gt(0)").get()); 108 current_attr_select.find("option:gt(0)").remove(); 109 current_attr_select.append(current_attr_select.data("attribute_options")); 110 current_attr_select.find("option:gt(0)").removeClass("active"); 111 var i = current_attr_select.attr("name"); 112 113 for (num in n) 114 if (typeof n[num] != "undefined") { 115 var s = n[num].attributes; 116 for (attr_name in s) { 117 var o = s[attr_name]; 118 if (attr_name == i) if (o) { 119 o = e("<div/>").html(o).text(); 120 o = o.replace(/'/g, "\\'"); 121 o = o.replace(/"/g, '\\"'); 122 current_attr_select.find('option[value="' + o + '"]').addClass("active") 123 } else current_attr_select.find("option:gt(0)").addClass("active") 124 } 125 } 126 current_attr_select.find("option:gt(0):not(.active)").remove() 127 }); 128 $variation_form.trigger("woocommerce_update_variation_values") 129 }).on("found_variation", function (t, n) { 130 131 var r = e(this), 132 i = e(this).closest(".product"), 133 s = i.find("div.images img:eq(0)"), 134 o = i.find("div.images a.zoom:eq(0)"), 135 u = s.attr("data-o_src"), 136 a = s.attr("data-o_title"), 137 f = o.attr("data-o_href"), 138 l = n.image_src, 139 c = n.image_link, 140 h = n.image_title; 141 r.find(".variations_button").show(); 142 r.find(".single_variation").html(n.price_html + n.availability_html); 143 if (!u) { 144 u = s.attr("src") ? s.attr("src") : ""; 145 s.attr("data-o_src", u) 146 } 147 if (!f) { 148 f = o.attr("href") ? o.attr("href") : ""; 149 o.attr("data-o_href", f) 150 } 151 if (!a) { 152 a = s.attr("title") ? s.attr("title") : ""; 153 s.attr("data-o_title", a) 154 } 155 if (l && l.length > 1) { 156 s.attr("src", l).attr("alt", h).attr("title", h); 157 o.attr("href", c).attr("title", h) 158 } else { 159 s.attr("src", u).attr("alt", a).attr("title", a); 160 o.attr("href", f).attr("title", a) 161 } 162 var p = r.find(".single_variation_wrap"), 163 d = i.find(".product_meta").find(".sku"), 164 v = i.find(".product_weight"), 165 m = i.find(".product_dimensions"); 166 d.attr("data-o_sku") || d.attr("data-o_sku", d.text()); 167 v.attr("data-o_weight") || v.attr("data-o_weight", v.text()); 168 m.attr("data-o_dimensions") || m.attr("data-o_dimensions", m.text()); 169 n.sku ? d.text(n.sku) : d.text(d.attr("data-o_sku")); 170 171 n.weight ? v.text(n.weight) : v.text(v.attr("data-o_weight")); 172 n.dimensions ? m.text(n.dimensions) : m.text(m.attr("data-o_dimensions")); 173 p.find(".quantity").show(); 174 !n.is_in_stock && !n.backorders_allowed && r.find(".variations_button").hide(); 175 176 n.min_qty ? 177 p.find("input[name=quantity]").attr("min", n.min_qty).val(n.min_qty) : 178 p.find("input[name=quantity]").removeAttr("min"); 179 n.max_qty ? 180 p.find("input[name=quantity]").attr("max", n.max_qty) : 181 p.find("input[name=quantity]").removeAttr("max"); 182 183 if (n.is_sold_individually == "yes") { 184 p.find("input[name=quantity]").val("1"); 185 p.find(".quantity").hide() 186 } 187 p.slideDown("200").trigger("show_variation", [n]) 188 }); 189 190 /** 191 * Initial states and loading 192 */ 193 jQuery('form.variations_form .variations select').change(); 194 195 /** 196 * Helper functions for variations 197 */ 198 199 // Search for matching variations for given set of attributes 200 function find_matching_variations(product_variations, settings) { 201 var matching = []; 202 203 for (var i = 0; i < product_variations.length; i++) { 204 var variation = product_variations[i]; 205 var variation_id = variation.variation_id; 206 207 if (variations_match(variation.attributes, settings)) { 208 matching.push(variation); 209 } 210 } 211 return matching; 212 } 213 214 // Check if two arrays of attributes match 215 function variations_match(attrs1, attrs2) { 216 var match = true; 217 for (attr_name in attrs1) { 218 var val1 = attrs1[attr_name]; 219 var val2 = attrs2[attr_name]; 220 if (val1 !== undefined && val2 !== undefined && val1.length != 0 && val2.length != 0 && val1 != val2) { 221 match = false;
222 } 223 } 224 return match; 225 } 226 227}; 228 229 230// when clicked on order now button run custom variations function 231 jQuery(document).on('click', '.evotx_show_variations',function(){ 232 233 var O = jQuery(this); 234 235 O.parent().hide(); 236 var _this_form = O.parent().siblings('.variations_form'); 237 238 _this_form.slideDown(); 239 240 _this_form.wc_variation_form(); 241 242 setTimeout(function(){ 243 vars = O.data('defv'); 244 245 _this_form.find('.variations select').each(function(){ 246 sO = jQuery(this); 247 sF = sO.attr('id'); 248 if( sF in vars){ 249 sO.find('option[value="'+ vars[sF] +'"]').prop('select',true); 250 }else{ 251 sO.find('option:eq(2)').prop('select',true); 252 } 253 254 sO.change(); 255 }); 256 },200); 257 258 259 }); 260 261 262 263 //e("form.variations_form").wc_variation_form(); 264 //e("form.variations_form .variations select").change() 265})(jQuery, window, document); // JavaScript Document
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.