1'use strict'; 2 3(function ($) { 4 $(function () { 5 if ($('.woosg-wrap').length) { 6 $('.woosg-wrap').each(function () { 7 woosg_init($(this)); 8 }); 9 } 10 }); 11 12 $(document).on('woosq_loaded', function () { 13 // WPC Smart Quick View 14 woosg_init($('#woosq-popup .woosg-wrap')); 15 }); 16 17 $(document).on('woovr_selected', function (e, selected, variations) { 18 // WPC Variations Radio Buttons 19 var $wrap = variations.closest('.woosg-wrap'); 20 var $product = variations.closest('.woosg-product'); 21 22 if ($product.length) { 23 var _id = selected.attr('data-id'); 24 var _sku = selected.attr('data-sku'); 25 var _price = selected.attr('data-price'); 26 var _regular_price = selected.attr('data-regular-price'); 27 var _price_html = selected.attr('data-pricehtml'); 28 var _image_src = selected.attr('data-imagesrc'); 29 var _purchasable = selected.attr('data-purchasable'); 30 var _attrs = selected.attr('data-attrs'); 31 32 if (_purchasable === 'yes') { 33 // change data 34 $product.attr('data-id', _id); 35 $product.attr('data-price', _price); 36 $product.attr('data-regular-price', _regular_price); 37 38 // change image 39 $product.find('.woosg-thumb-ori').hide(); 40 $product.find('.woosg-thumb-new').html('<img src="' + _image_src + '"/>').show(); 41 42 // change price 43 $product.find('.woosg-price-ori').hide(); 44 $product.find('.woosg-price-new').html(_price_html).show(); 45 46 // change attributes 47 $product.attr('data-attrs', _attrs.replace(/\/$/, '')); 48 49 // change add to cart button 50 $product.find('.add_to_cart_button').attr('data-product_id', _id).attr('data-product_sku', _sku).attr('data-quantity', $product.attr('data-qty')).removeClass('product_type_variable').addClass('product_type_simple ajax_add_to_cart').html(woosg_vars.add_to_cart); 51 52 // single add-to-cart 53 if ($product.find('.woosg-atc').length) { 54 $product.find('.woosg-atc [name="variation_id"]').val(_id); 55 $product.find('.woosg_single_add_to_cart_button').prop('disabled', false).removeClass('woosg-disabled'); 56 57 let attrs = $.parseJSON(_attrs); 58 59 $.each(attrs, function (key, val) { 60 $product.find('.woosg-atc input[name="' + key + '"]').val(val); 61 }); 62 } 63 } else { 64 // reset data 65 $product.attr('data-id', 0); 66 $product.attr('data-price', 0); 67 $product.attr('data-regular-price', 0); 68 $product.attr('data-attrs', ''); 69 70 // reset image 71 $product.find('.woosg-thumb-new').html('').hide(); 72 $product.find('.woosg-thumb-ori').show(); 73 74 // reset price 75 $product.find('.woosg-price-ori').show(); 76 $product.find('.woosg-price-new').html('').hide(); 77 78 // reset availability 79 $product.find('.woosg-availability').html('').hide(); 80 81 // reset add to cart button 82 $product.find('.add_to_cart_button').attr('data-product_id', 0).attr('data-product_sku', '').removeClass('product_type_simple ajax_add_to_cart').addClass('product_type_variable').html(woosg_vars.select_options); 83 84 // single add-to-cart 85 if ($product.find('.woosg-atc').length) { 86 $product.find('.woosg-atc [name="variation_id"]').val(0); 87 $product.find('.woosg_single_add_to_cart_button').prop('disabled', true).addClass('woosg-disabled'); 88 $product.find('.woosg-atc input[name^="attribute_"]').val(''); 89 } 90 } 91 92 // reset sku, weight & dimensions 93 $('.product_meta .sku').wc_reset_content(); 94 $('.product_weight, .woocommerce-product-attributes-item--weight .woocommerce-product-attributes-item__value').wc_reset_content(); 95 $('.product_dimensions, .woocommerce-product-attributes-item--dimensions .woocommerce-product-attributes-item__value').wc_reset_content(); 96 } 97 98 if ($wrap.length) { 99 woosg_init($wrap); 100 } 101 }); 102 103 $(document).on('click touch', '.single_add_to_cart_button', function (e) { 104 var $this = $(this); 105 106 if ($this.hasClass('woosg-disabled')) { 107 e.preventDefault(); 108 } 109 }); 110
111 $(document).on('change', '.woosg-checkbox', function () { 112 var $this = $(this); 113 var $wrap = $this.closest('.woosg-wrap'); 114 115 if ($this.prop('checked')) { 116 $this.closest('.woosg-product').attr('data-qty', 1); 117 } else { 118 $this.closest('.woosg-product').attr('data-qty', 0); 119 } 120 121 woosg_init($wrap); 122 }); 123 124 $(document).on('keyup change', '.woosg-quantity .woosg-qty', function () { 125 var $this = $(this); 126 var $wrap = $this.closest('.woosg-wrap'); 127 var qty = parseFloat($this.val()); 128 var min = parseFloat($this.closest('.woosg-quantity').attr('data-min')); 129 var max = parseFloat($this.closest('.woosg-quantity').attr('data-max')); 130 131 if ((qty > 0) && (qty < min)) { 132 qty = min; 133 $this.val(qty); 134 } 135 136 if ((max > 0) && (qty > max)) { 137 qty = max; 138 $this.val(qty); 139 } 140 141 $this.closest('.woosg-product').attr('data-qty', qty); 142 $this.closest('.woosg-product').find('.add_to_cart_button').attr('data-quantity', qty); 143 144 woosg_init($wrap); 145 }); 146 147 $(document).on('change', '.woosg-quantity input[type=radio]', function () { 148 var $this = $(this); 149 var $wrap = $this.closest('.woosg-wrap'); 150 var qty = parseFloat($this.val()); 151 var min = parseFloat($this.closest('.woosg-quantity').attr('data-min')); 152 153 if ((qty > 0) && (qty < min)) { 154 qty = min; 155 $this.val(qty); 156 } 157 158 $this.closest('.woosg-product').attr('data-qty', qty); 159 160 woosg_init($wrap); 161 }); 162 163 $(document).on('click touch', '.woosg-quantity-plus, .woosg-quantity-minus', 164 function () { 165 // get values 166 var $qty = $(this).closest('.woosg-quantity').find('.woosg-qty').length ? $(this).closest('.woosg-quantity').find('.woosg-qty') : $(this).closest('.woosg-quantity').find('.qty'); 167 168 var val = parseFloat($qty.val()), 169 max = parseFloat($qty.attr('max')), 170 min = parseFloat($qty.attr('min')), step = $qty.attr('step'); 171 172 // format values 173 if (!val || val === '' || val === 'NaN') { 174 val = 0; 175 } 176 177 if (max === '' || max === 'NaN') { 178 max = ''; 179 } 180 181 if (min === '' || min === 'NaN') { 182 min = 0; 183 } 184 185 if (step === 'any' || step === '' || step === undefined || 186 parseFloat(step) === 'NaN') { 187 step = 1; 188 } else { 189 step = parseFloat(step); 190 } 191 192 // change the value 193 if ($(this).is('.woosg-quantity-plus')) { 194 if (max && (max == val || val > max)) { 195 $qty.val(max); 196 } else { 197 $qty.val((val + step).toFixed(woosg_decimal_places(step))); 198 } 199 } else { 200 if (min && (min == val || val < min)) { 201 $qty.val(min); 202 } else if (val > 0) { 203 $qty.val((val - step).toFixed(woosg_decimal_places(step))); 204 } 205 } 206 207 // trigger change event 208 $qty.trigger('change'); 209 }); 210})(jQuery); 211 212function woosg_init($wrap) { 213 var wid = $wrap.attr('data-id'); 214 var is_selection = false; 215 var selection_name = ''; 216 var is_empty = true; 217 var $products = $wrap.find('.woosg-products'); 218 var $alert = $wrap.find('.woosg-alert'); 219 var $ids = jQuery('.woosg-ids-' + wid); 220 var $btn = $ids.closest('form.cart').find('.single_add_to_cart_button:not(.woosg_single_add_to_cart_button)'); 221 222 if ($products.hasClass('woosg-show-atc-each') || 223 $products.hasClass('woosg-show-atc-no')) { 224 return; 225 } 226 227 $products.find('.woosg-product').each(function () { 228 var $this = jQuery(this); 229 230 if (($this.attr('data-qty') > 0) && ($this.attr('data-id') == 0)) { 231 is_selection = true; 232 233 if (selection_name === '') { 234 selection_name = $this.attr('data-name'); 235 } 236 } 237 238 if ($this.attr('data-qty') > 0) { 239 is_empty = false;
240 } 241 }); 242 243 if (is_selection || is_empty) { 244 $btn.addClass('woosg-disabled'); 245 246 if (is_selection) { 247 $alert.html(woosg_vars.alert_selection.replace('[name]', 248 '<strong>' + selection_name + '</strong>')).slideDown(); 249 } else if (is_empty) { 250 $alert.html(woosg_vars.alert_empty).slideDown(); 251 } 252 253 jQuery(document).trigger('woosg_check_ready', [false, is_selection, is_empty, $wrap]); 254 } else { 255 $alert.html('').slideUp(); 256 $btn.removeClass('woosg-disabled'); 257 258 // ready 259 jQuery(document).trigger('woosg_check_ready', [true, is_selection, is_empty, $wrap]); 260 } 261 262 woosg_carousel($wrap); 263 woosg_calc_price($wrap); 264 woosg_save_ids($wrap); 265 266 jQuery(document).trigger('woosg_init', [$wrap]); 267} 268 269function woosg_carousel($wrap) { 270 if (!$wrap.hasClass('woosg-carousel-initialized')) { 271 let slides = 2; 272 let carousel = JSON.parse(woosg_vars.carousel_params); 273 274 if ($wrap.hasClass('woosg-wrap-layout-carousel-2') || 275 $wrap.hasClass('woosg-wrap-layout-carousel-3') || 276 $wrap.hasClass('woosg-wrap-layout-carousel-4')) { 277 if ($wrap.hasClass('woosg-wrap-layout-carousel-3')) { 278 slides = 3; 279 } else if ($wrap.hasClass('woosg-wrap-layout-carousel-4')) { 280 slides = 4; 281 } 282 283 if (slides > $wrap.find('.woosg-product').length) { 284 slides = $wrap.find('.woosg-product').length; 285 } 286 287 carousel.slidesToShow = slides; 288 carousel.slidesToScroll = slides; 289 290 $wrap.addClass('woosg-carousel-initialized').find('.woosg-products').slick(carousel); 291 jQuery(document).trigger('woosg_carousel', [$wrap]); 292 } 293 } 294} 295 296function woosg_calc_price($wrap) { 297 var total = 0; 298 var total_regular = 0; 299 var wid = $wrap.attr('data-id'); 300 var $woobt = jQuery('.woobt-wrap-' + wid); 301 var $woofs = jQuery('.woofs-wrap-' + wid); 302 var $price = jQuery('.woosg-price-' + wid); 303 var $products = $wrap.find('.woosg-products'); 304 var $total = $wrap.find('.woosg-total'); 305 var suffix = $products.attr('data-price-suffix'); 306 307 // main price 308 total = parseFloat($products.attr('data-price')); 309 total_regular = parseFloat($products.attr('data-regular-price')); 310 311 $products.find('.woosg-product').each(function () { 312 var $this = jQuery(this); 313 var price = parseFloat($this.attr('data-price')); 314 var regular_price = parseFloat($this.attr('data-regular-price')); 315 var qty = parseFloat($this.attr('data-qty')); 316 var wpcpq = $this.data('wpcpq'); 317 318 if ((price > 0) && (regular_price > 0) && (qty > 0)) { 319 // price by quantity 320 if ((wpcpq.tiers !== undefined) && wpcpq.tiers.length) { 321 var tiers = wpcpq.tiers.sort( 322 (a, b) => (parseFloat(a.quantity) < parseFloat(b.quantity)) 323 ? 1 324 : ((parseFloat(b.quantity) < parseFloat(a.quantity)) ? -1 : 0)); 325 326 for (let tier of tiers) { 327 if (qty >= parseFloat(tier.quantity)) { 328 if (/\%$/gm.test(tier.price)) { 329 price = parseFloat(tier.price.replace('%', '')) * price / 100; 330 } else { 331 price = parseFloat(tier.price); 332 } 333 334 break; 335 } 336 } 337 338 // update product price 339 var price_html = woosg_price_html(regular_price, price); 340 341 $this.find('.woosg-price-ori').hide(); 342 $this.find('.woosg-price-new').html(price_html).show(); 343 } 344 345 total += price * qty; 346 total_regular += regular_price * qty; 347 } 348 }); 349 350 var total_html = woosg_price_html(total_regular, total) + suffix; 351 352 $total.html(woosg_vars.total_text + ' ' + total_html).slideDown(); 353 354 if (woosg_vars.change_price !== 'no') { 355 // change the main price 356 if ((woosg_vars.change_price === 'yes_custom') && 357 (woosg_vars.price_selector !== null) && 358 (woosg_vars.price_selector !== '')) { 359 $price = jQuery(woosg_vars.price_selector); 360 } 361 362 $price.html(total_html); 363 } 364 365 if ($woobt.length) { 366 $woobt.find('.woobt-products').attr('data-product-price-html', total_html); 367 $woobt.find('.woobt-product-this').attr('data-price', total).attr('data-regular-price', total_regular); 368 369 woobt_init($woobt); 370 } 371 372 if ($woofs.length) { 373 $woofs.find('.woofs-products').attr('data-product-price', total); 374 $woofs.find('.woofs-products').attr('data-product-regular-price', total_regular); 375 376 woofs_init($woofs); 377 } 378 379 jQuery(document).trigger('woosg_calc_price', [total, total_regular, total_html, $wrap]); 380} 381 382function woosg_save_ids($wrap) { 383 var ids = Array(); 384 var wid = $wrap.attr('data-id'); 385 var $products = $wrap.find('.woosg-products'); 386 var $ids = jQuery('.woosg-ids-' + wid); 387 388 $products.find('.woosg-product').each(function () { 389 var $this = jQuery(this); 390 var id = parseInt($this.attr('data-id')); 391 var qty = parseFloat($this.attr('data-qty')); 392 var attrs = $this.attr('data-attrs'); 393 394 if ((id > 0) && (qty > 0)) { 395 if (attrs != undefined) { 396 attrs = encodeURIComponent(attrs); 397 } else { 398 attrs = ''; 399 } 400 401 ids.push(id + '/' + qty + '/' + attrs); 402 } 403 }); 404 405 $ids.val(ids.join(',')); 406 jQuery(document).trigger('woosg_save_ids', [ids, $wrap]); 407} 408 409function woosg_decimal_places(num) { 410 var match = ('' + num).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/); 411 412 if (!match) { 413 return 0; 414 } 415 416 return Math.max(0, // Number of digits right of decimal point. 417 (match[1] ? match[1].length : 0) 418 // Adjust for scientific notation. 419 - (match[2] ? +match[2] : 0)); 420} 421 422function woosg_format_money(number, places, symbol, thousand, decimal) { 423 number = number || 0; 424 places = !isNaN(places = Math.abs(places)) ? places : 2; 425 symbol = symbol !== undefined ? symbol : '$'; 426 thousand = thousand !== undefined ? thousand : ','; 427 decimal = decimal !== undefined ? decimal : '.'; 428 429 var negative = number < 0 ? '-' : '', 430 i = parseInt(number = Math.abs(+number || 0).toFixed(places), 10) + '', 431 j = 0; 432 433 if (i.length > 3) { 434 j = i.length % 3; 435 } 436 437 if (woosg_vars.trim_zeros === '1') { 438 return symbol + negative + (j ? i.substr(0, j) + thousand : '') + 439 i.substr(j).replace(/(\d{3})(?=\d)/g, '$1' + thousand) + 440 (places && (parseFloat(number) > parseFloat(i)) ? decimal + 441 Math.abs(number - i).toFixed(places).slice(2).replace(/(\d*?[1-9])0+$/g, '$1') : ''); 442 } else { 443 return symbol + negative + (j ? i.substr(0, j) + thousand : '') + 444 i.substr(j).replace(/(\d{3})(?=\d)/g, '$1' + thousand) + 445 (places ? decimal + Math.abs(number - i).toFixed(places).slice(2) : ''); 446 } 447} 448 449function woosg_format_price(price) { 450 var price_html = '<span class="woocommerce-Price-amount amount">'; 451 var price_formatted = woosg_format_money(price, woosg_vars.price_decimals, '', 452 woosg_vars.price_thousand_separator, woosg_vars.price_decimal_separator); 453 454 switch (woosg_vars.price_format) { 455 case '%1$s%2$s': 456 //left 457 price_html += '<span class="woocommerce-Price-currencySymbol">' + 458 woosg_vars.currency_symbol + '</span>' + price_formatted; 459 break; 460 case '%1$s %2$s': 461 //left with space 462 price_html += '<span class="woocommerce-Price-currencySymbol">' + 463 woosg_vars.currency_symbol + '</span> ' + price_formatted; 464 break; 465 case '%2$s%1$s': 466 //right 467 price_html += price_formatted + 468 '<span class="woocommerce-Price-currencySymbol">' + 469 woosg_vars.currency_symbol + '</span>'; 470 break; 471 case '%2$s %1$s': 472 //right with space 473 price_html += price_formatted + 474 ' <span class="woocommerce-Price-currencySymbol">' + 475 woosg_vars.currency_symbol + '</span>'; 476 break; 477 default: 478 //default 479 price_html += '<span class="woocommerce-Price-currencySymbol">' + 480 woosg_vars.currency_symbol + '</span>' + price_formatted; 481 } 482 483 price_html += '</span>'; 484 485 return price_html; 486} 487 488function woosg_price_html(regular_price, sale_price) { 489 var price_html = ''; 490 491 if (parseFloat(woosg_round(sale_price)) < 492 parseFloat(woosg_round(regular_price))) { 493 price_html = '<del>' + woosg_format_price(regular_price) + '</del> <ins>' + 494 woosg_format_price(sale_price) + '</ins>'; 495 } else { 496 price_html = woosg_format_price(regular_price); 497 } 498 499 return price_html; 500} 501 502function woosg_round(value) { 503 return Number(Math.round(value + 'e' + woosg_vars.price_decimals) + 'e-' + 504 woosg_vars.price_decimals); 505}
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.