1 "use strict"; 2 3jQuery(document).on("ready", function () { 4 jQuery(".product-type-wooco").each(function () { 5 wooco_init(jQuery(this)); 6 }); 7 8 jQuery(".sidebar-main").on( 9 "click", 10 ".wooco-item-child .input-text", 11 function (event) { 12 jQuery(".wooco-item-child .input-text").prop("readonly", true); 13 } 14 ); 15}); 16 17jQuery(document).on("found_variation", function (e, t) { 18 var $wooco_wrap = jQuery(e["target"]).closest(".product-type-wooco"); 19 var $wooco_products = jQuery(e["target"]).closest(".wooco-products"); 20 var $wooco_product = jQuery(e["target"]).closest(".wooco-product"); 21 22 if ($wooco_product.length) { 23 if (t["image"]["url"] && t["image"]["srcset"]) { 24 // change image 25 $wooco_product.find(".wooco-thumb-ori").hide(); 26 $wooco_product 27 .find(".wooco-thumb-new") 28 .html( 29 '<img src="' + 30 t["image"]["url"] + 31 '" srcset="' + 32 t["image"]["srcset"] + 33 '"/>' 34 ) 35 .show(); 36 } 37 if (t["price_html"]) { 38 // change price 39 $wooco_product.find(".wooco-price-ori").hide(); 40 $wooco_product.find(".wooco-price-new").html(t["price_html"]).show(); 41 } 42 if (t["is_purchasable"]) { 43 // change stock notice 44 if (t["is_in_stock"]) { 45 $wooco_products.next("p.stock").show(); 46 $wooco_product.attr("data-id", t["variation_id"]); 47 $wooco_product.attr("data-price", t["display_price"]); 48 } else { 49 $wooco_products.next("p.stock").hide(); 50 $wooco_product.attr("data-id", 0); 51 $wooco_product.attr("data-price", 0); 52 } 53 54 // change availability text 55 jQuery(e["target"]).closest(".variations_form").find("p.stock").remove(); 56 if (t["availability_html"] != "") { 57 jQuery(e["target"]) 58 .closest(".variations_form") 59 .append(t["availability_html"]); 60 } 61 } 62 if (t["variation_description"] != "") { 63 $wooco_product 64 .find(".wooco-variation-description") 65 .html(t["variation_description"]) 66 .show(); 67 } else { 68 $wooco_product.find(".wooco-variation-description").html("").hide(); 69 } 70 71 if (wooco_vars.change_image == "no") { 72 // prevent changing the main image 73 jQuery(e["target"]).closest(".variations_form").trigger("reset_image"); 74 } 75 76 wooco_init($wooco_wrap); 77 } 78}); 79 80jQuery(document).on("reset_data", function (e) { 81 var $wooco_wrap = jQuery(e["target"]).closest(".product-type-wooco"); 82 var $wooco_product = jQuery(e["target"]).closest(".wooco-product"); 83 84 if ($wooco_product.length) { 85 // reset thumb 86 $wooco_product.find(".wooco-thumb-new").hide(); 87 $wooco_product.find(".wooco-thumb-ori").show(); 88 89 // reset price 90 $wooco_product.find(".wooco-price-new").hide(); 91 $wooco_product.find(".wooco-price-ori").show(); 92 93 // reset stock 94 jQuery(e["target"]).closest(".variations_form").find("p.stock").remove(); 95 96 // reset desc 97 $wooco_product.find(".wooco-variation-description").html("").hide(); 98 99 // reset id 100 $wooco_product.attr("data-id", 0); 101 $wooco_product.attr("data-price", 0); 102 103 wooco_init($wooco_wrap); 104 } 105}); 106 107jQuery(document).on("click touch", ".single_add_to_cart_button", function (e) { 108 var $this = jQuery(this); 109 var $wooco_products = $this.closest("wooco-products"); 110 111 if ($this.hasClass("wooco-disabled")) { 112 if ($this.hasClass("wooco-selection")) { 113 alert(wooco_vars.alert_selection); 114 } else if ($this.hasClass("wooco-empty")) { 115 alert(wooco_vars.alert_empty); 116 } else if ($this.hasClass("wooco-min")) { 117 alert( 118 wooco_vars.alert_min.replace("[min]", $wooco_products.attr("data-min")) 119 ); 120 } else if ($this.hasClass("wooco-max")) { 121 alert( 122 wooco_vars.alert_max.replace("[max]", $wooco_products.attr("data-max")) 123 ); 124 } 125 e.preventDefault(); 126 } 127}); 128 129jQuery(document).on("keyup change", ".wooco-qty input", function () { 130 var $this = jQuery(this); 131 var $wooco_wrap = $this.closest(".product-type-wooco"); 132 var qty = parseInt($this.val()); 133 var min_qty = parseInt($this.attr("min")); 134 var max_qty = parseInt($this.attr("max")); 135 136 if (!isNaN(min_qty) && qty < min_qty) { 137 qty = min_qty; 138 } 139 140 if (!isNaN(max_qty) && qty > max_qty) { 141 qty = max_qty; 142 } 143 144 $this.val(qty); 145 $this.closest(".wooco-product").attr("data-qty", qty); 146 147 wooco_init($wooco_wrap); 148}); 149 150jQuery(document).on("woosq_loaded", function () { 151 // product bundles in quick view popup 152 wooco_init(jQuery("#woosq-popup .product-type-wooco")); 153}); 154jQuery(document).ready(function ($) { 155 // Target WooCommerce quantity input 156 var $this = $("form.cart input.qty"); 157 var qty = parseInt($this.val()); 158 159 // Target wooco wrap (adjust selector if needed) 160 var $wooco_wrap = $(".wooco_wrap"); 161 162 if ($wooco_wrap.length > 0) { 163 wooco_init($wooco_wrap); 164 } 165}); 166function wooco_init($wooco_wrap) { 167 var total = 0; 168 var is_selection = false;
169 var is_empty = true; 170 var is_min = false; 171 var is_max = false; 172 173 var $wooco_products = $wooco_wrap.find(".wooco-products"); 174 var $wooco_btn = $wooco_wrap.find(".single_add_to_cart_button"); 175 176 $wooco_products.find(".wooco-product").each(function () { 177 var $this = jQuery(this); 178 if ($this.attr("data-qty") > 0 && $this.attr("data-id") == 0) { 179 is_selection = true; 180 } 181 if ($this.attr("data-qty") > 0) { 182 is_empty = false; 183 total += parseInt($this.attr("data-qty")); 184 } 185 }); 186 187 // check min 188 if ( 189 $wooco_products.attr("data-optional") == "yes" && 190 $wooco_products.attr("data-min") && 191 total < parseInt($wooco_products.attr("data-min")) 192 ) { 193 is_min = true; 194 } 195 196 // check max 197 if ( 198 $wooco_products.attr("data-optional") == "yes" && 199 $wooco_products.attr("data-max") && 200 total > parseInt($wooco_products.attr("data-max")) 201 ) { 202 is_max = true; 203 } 204 205 if (is_selection || is_empty || is_min || is_max) { 206 $wooco_btn.addClass("wooco-disabled"); 207 if (is_selection) { 208 $wooco_btn.addClass("wooco-selection"); 209 } else { 210 $wooco_btn.removeClass("wooco-selection"); 211 } 212 if (is_empty) { 213 $wooco_btn.addClass("wooco-empty"); 214 } else { 215 $wooco_btn.removeClass("wooco-empty"); 216 } 217 if (is_min) { 218 $wooco_btn.addClass("wooco-min"); 219 } else { 220 $wooco_btn.removeClass("wooco-min"); 221 } 222 if (is_max) { 223 $wooco_btn.addClass("wooco-max"); 224 } else { 225 $wooco_btn.removeClass("wooco-max"); 226 } 227 } else { 228 $wooco_btn.removeClass( 229 "wooco-disabled wooco-selection wooco-empty wooco-min wooco-max" 230 ); 231 } 232 233 wooco_calc_price($wooco_wrap); 234 wooco_save_ids($wooco_wrap); 235} 236 237function wooco_calc_price($wooco_wrap) { 238 var total = 0; 239 var total_html = ""; 240 241 var $wooco_products = $wooco_wrap.find(".wooco-products"); 242 var $wooco_total = $wooco_wrap.find(".wooco-total"); 243 244 $wooco_products.find(".wooco-product").each(function () { 245 var $this = jQuery(this); 246 if ($this.attr("data-price") > 0) { 247 total += $this.attr("data-price") * $this.attr("data-qty"); 248 } 249 }); 250 if ( 251 $wooco_products.attr("data-discount") > 0 && 252 $wooco_products.attr("data-discount") < 100 253 ) { 254 total = (total * (100 - $wooco_products.attr("data-discount"))) / 100; 255 } 256 var total_formatted = wooco_format_money( 257 total, 258 wooco_vars.price_decimals, 259 "", 260 wooco_vars.price_thousand_separator, 261 wooco_vars.price_decimal_separator 262 ); 263 switch (wooco_vars.price_format) { 264 case "%1$s%2$s": 265 //left 266 total_html += wooco_vars.currency_symbol + "" + total_formatted; 267 break; 268 case "%1$s %2$s": 269 //left with space 270 total_html += wooco_vars.currency_symbol + " " + total_formatted; 271 break; 272 case "%2$s%1$s": 273 //right 274 total_html += total_formatted + "" + wooco_vars.currency_symbol; 275 break; 276 case "%2$s %1$s": 277 //right with space 278 total_html += total_formatted + " " + wooco_vars.currency_symbol; 279 break; 280 default: 281 //default 282 total_html += wooco_vars.currency_symbol + "" + total_formatted; 283 } 284 if ( 285 parseFloat($wooco_products.attr("data-discount")) > 0 && 286 parseFloat($wooco_products.attr("data-discount")) < 100 287 ) { 288 var saved = wooco_round(parseFloat($wooco_products.attr("data-discount"))); 289 total_html += " (" + wooco_vars.price_saved + " " + saved + "%)"; 290 } 291 $wooco_total.html(wooco_vars.price_text + " " + total_html).slideDown(); 292 jQuery(document).trigger("wooco_calc_price", [ 293 total, 294 total_formatted, 295 total_html, 296 ]); 297} 298 299function wooco_save_ids($wooco_wrap) { 300 var wooco_ids = Array(); 301 var $wooco_products = $wooco_wrap.find(".wooco-products"); 302 var $wooco_ids = $wooco_wrap.find(".wooco-ids"); 303 304 $wooco_products.find(".wooco-product").each(function () { 305 var $this = jQuery(this); 306 if ($this.attr("data-id") > 0 && $this.attr("data-qty") > 0) { 307 wooco_ids.push($this.attr("data-id") + "/" + $this.attr("data-qty")); 308 } 309 }); 310 311 $wooco_ids.val(wooco_ids.join(",")); 312} 313 314function wooco_round(num) { 315 return +(Math.round(num + "e+2") + "e-2"); 316} 317 318function wooco_format_money(number, places, symbol, thousand, decimal) { 319 number = number || 0; 320 places = !isNaN((places = Math.abs(places))) ? places : 2; 321 symbol = symbol !== undefined ? symbol : "$"; 322 thousand = thousand || ","; 323 decimal = decimal || "."; 324 var negative = number < 0 ? "-" : "", 325 i = parseInt((number = Math.abs(+number || 0).toFixed(places)), 10) + "", 326 j = 0; 327 if (i.length > 3) { 328 j = i.length % 3; 329 } 330 return ( 331 symbol + 332 negative + 333 (j ? i.substr(0, j) + thousand : "") + 334 i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thousand) + 335 (places 336 ? decimal + 337 Math.abs(number - i) 338 .toFixed(places) 339 .slice(2) 340 : "") 341 ); 342}
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.