https://skylox.com/wp-content/plugins/wpc-composite-products-premium/assets/js/frontend.js?ver=7.6.7
1'use strict'; 2 3(function ($) { 4 var $gallery = null; 5 var gallery_loading = false; 6 7 $(function () { 8 if ($('.wooco-wrap').length) { 9 wooco_init_selector(); 10 11 $('.wooco-wrap').each(function () { 12 wooco_init($(this), 'loaded'); 13 }); 14 } 15 }); 16 17 $(document).on('woosq_loaded', function () { 18 // composite products in quick view popup 19 if ($('#woosq-popup .wooco-wrap').length) { 20 wooco_init_selector(); 21 wooco_init($('#woosq-popup .wooco-wrap'), 'woosq_loaded'); 22 } 23 }); 24 25 $(document).on('wooco_save_ids', function (e, ids, $wrap, context, $selected) { 26 const block_ui_params = { 27 message: null, overlayCSS: { 28 background: '#fff', opacity: 0.6, 29 }, 30 }; 31 32 if ((wooco_vars.change_image === 'yes') && (context === 'loaded' || context === 'on_select' || context === 'on_click')) { 33 var product_id = $wrap.data('id'); 34 var $all_gallery = $(wooco_vars.gallery_selector); 35 var $main_gallery = $(wooco_vars.main_gallery_selector); 36 37 if ($all_gallery.length && $main_gallery.length) { 38 if (!ids.length) { 39 $(document).find('.woocommerce-product-gallery--wooco').unblock().hide(); 40 $main_gallery.unblock().show(); 41 } else { 42 var key = btoa(ids.toString()).replace(/[^a-zA-Z0-9]/g, ''); 43 var $key_gallery = $('.woocommerce-product-gallery--wooco-' + key); 44 45 if ($key_gallery.length) { 46 $all_gallery.unblock().hide(); 47 $key_gallery.unblock().show(); 48 } else { 49 $all_gallery.block(block_ui_params); 50 51 if (gallery_loading && ($gallery != null)) { 52 $gallery.abort(); 53 } 54 55 var data = { 56 action: 'wooco_load_gallery', 57 nonce: wooco_vars.nonce, 58 product_id: product_id, 59 key: key, 60 ids: ids, 61 }; 62 63 gallery_loading = true; 64 65 $gallery = $.post(wooco_vars.wc_ajax_url.toString().replace('%%endpoint%%', 'wooco_load_gallery'), data, function (response) { 66 if (response.gallery) { 67 var $wooco_gallery = $(response.gallery); 68 69 $all_gallery.unblock().hide(); 70 $wooco_gallery.insertAfter($main_gallery); 71 $(document).trigger('wooco_gallery_loaded', product_id, key, ids); 72 73 $wooco_gallery.imagesLoaded(function () { 74 $wooco_gallery.wc_product_gallery(); 75 76 // scroll to selected image 77 if ($selected) { 78 var selected_image = $selected.data('image_gallery'); 79 var $gallery_nav = $wooco_gallery.find('.flex-control-nav'); 80 81 if ($gallery_nav.length && (selected_image !== undefined) && (selected_image !== '')) { 82 var $scroll_image = $gallery_nav.find('li img[src="' + selected_image + '"]'); 83 84 if ($scroll_image.length) { 85 window.setTimeout(function () { 86 $scroll_image.trigger('click'); 87 $(window).trigger('resize'); 88 }, 100); 89 } 90 } 91 } 92 93 $(document).trigger('wooco_gallery_images_loaded', product_id, key, ids); 94 }); 95 } else { 96 $all_gallery.unblock(); 97 } 98 99 gallery_loading = false;
100 }); 101 } 102 } 103 } 104 } 105 }); 106 107 $(document).on('click touch', '.single_add_to_cart_button', function (e) { 108 if ($(this).hasClass('wooco-disabled')) { 109 if (wooco_vars.show_alert === 'change') { 110 wooco_show_alert($(this).closest('.wooco-wrap')); 111 } 112 113 e.preventDefault(); 114 } 115 }); 116 117 $(document).on('click touch', '.wooco-plus, .wooco-minus', function () { 118 // get values 119 var $qty = $(this).closest('.wooco-qty-wrap').find('.wooco_qty').length ? $(this).closest('.wooco-qty-wrap').find('.wooco_qty') : $(this).closest('.wooco-qty-wrap').find('.qty'), 120 val = parseFloat($qty.val()), max = parseFloat($qty.attr('max')), min = parseFloat($qty.attr('min')), 121 step = $qty.attr('step'); 122 123 // format values 124 if (!val || val === '' || val === 'NaN') { 125 val = 0; 126 } 127 128 if (max === '' || max === 'NaN') { 129 max = ''; 130 } 131 132 if (min === '' || min === 'NaN') { 133 min = 0; 134 } 135 136 if (step === 'any' || step === '' || step === undefined || parseFloat(step) === 'NaN') { 137 step = 1; 138 } else { 139 step = parseFloat(step); 140 } 141 142 // change the value 143 if ($(this).is('.wooco-plus')) { 144 if (max && (val >= max)) { 145 $qty.val(max); 146 } else { 147 $qty.val((val + step).toFixed(wooco_decimal_places(step))); 148 } 149 } else { 150 if (min && (val <= min)) { 151 $qty.val(min); 152 } else if (val > 0) { 153 $qty.val((val - step).toFixed(wooco_decimal_places(step))); 154 } 155 } 156 157 // trigger change event 158 $qty.trigger('change'); 159 }); 160 161 $(document).on('keyup change', '.wooco_qty', function () { 162 var $this = $(this); 163 var $wrap = $this.closest('.wooco-wrap'); 164 var val = parseFloat($this.val()); 165 var min = parseFloat($this.attr('min')); 166 var max = parseFloat($this.attr('max')); 167 168 if ((val < min) || isNaN(val)) { 169 val = min; 170 $this.val(val); 171 } 172 173 if (val > max) { 174 val = max; 175 $this.val(val); 176 } 177 178 $this.closest('.wooco_component_product_selection_item').attr('data-qty', val); 179 $this.closest('.wooco_component_product').attr('data-qty', val); 180 181 wooco_init($wrap, 'update_qty'); 182 }); 183 184 $(document).on('change', '.wooco-checkbox', function () { 185 var $wrap = $(this).closest('.wooco-wrap'); 186 187 wooco_init($wrap, 'checked'); 188 }); 189 190 $(document).on('change', '.wooco_component_product_select', function () { 191 // check on select 192 var $this = $(this); 193 var $selection = $this.closest('.wooco_component_product_selection'); 194 var $component = $this.closest('.wooco_component_product'); 195 var $wrap = $this.closest('.wooco-wrap'); 196 var $selected = $('option:selected', this); 197 198 wooco_selected($selected, $selection, $component); 199 wooco_init($wrap, 'on_select', $selected); 200 }); 201 202 $(document).on('click touch', '.wooco_component_product_selection_item', function (e) { 203 if ($(e.target).closest('.wooco_component_product_selection_item_qty').length === 0 && !$(e.target).is('a, a *')) { 204 // check on select 205 var $this = $(this); 206 var $selection = $this.closest('.wooco_component_product_selection'); 207 var $component = $this.closest('.wooco_component_product'); 208 var $wrap = $this.closest('.wooco-wrap'); 209 210 if ($component.attr('data-multiple') === 'yes') { 211 // multiple selection 212 if ($this.hasClass('wooco_item_selected')) { 213 $this.removeClass('wooco_item_selected'); 214 wooco_deselect($this, $selection, $component); 215 } else { 216 $this.addClass('wooco_item_selected'); 217 wooco_selected($this, $selection, $component); 218 } 219 } else { 220 // single selection 221 if ($this.hasClass('wooco_item_selected')) { 222 // remove 223 $component.attr('data-id', '-1'); 224 $component.attr('data-price', ''); 225 $component.attr('data-price-html', ''); 226 $component.attr('data-regular-price', ''); 227 $this.removeClass('wooco_item_selected'); 228 wooco_deselect($this, $selection, $component); 229 } else { 230 $selection.find('.wooco_component_product_selection_item').removeClass('wooco_item_selected'); 231 $this.addClass('wooco_item_selected'); 232 wooco_selected($this, $selection, $component); 233 } 234 } 235 236 wooco_init($wrap, 'on_click', $this); 237 } 238 }); 239 240 $(document).on('select2:select', '.wooco_component_product_select', function (e) { 241 var $this = $(this); 242 var $selection = $this.closest('.wooco_component_product_selection'); 243 var $component = $this.closest('.wooco_component_product'); 244 var $wrap = $this.closest('.wooco-wrap'); 245 var $selected = $(e.params.data.element); 246 247 wooco_selected($selected, $selection, $component); 248 wooco_init($wrap, 'on_select', $selected); 249 }); 250})(jQuery); 251 252function wooco_init($wrap, context = null, $selected = null) { 253 if (context === 'loaded' || context === 'woosq_loaded') { 254 // update qty 255 if ($wrap.find('.wooco_qty').length) { 256 $wrap.find('.wooco_qty').trigger('change'); 257 } else { 258 $wrap.find('.qty').trigger('change'); 259 } 260 } 261 262 wooco_check_ready($wrap, context, $selected); 263 wooco_save_ids($wrap, context, $selected); 264 265 if (context === null || context === 'on_select' || context === wooco_vars.show_alert) { 266 wooco_show_alert($wrap, context, $selected); 267 } 268 269 jQuery(document).trigger('wooco_init', [$wrap, context, $selected]); 270} 271 272function wooco_check_ready($wrap, context = null, $selected = null) { 273 var wid = $wrap.attr('data-id'); 274 var $components = $wrap.find('.wooco-components'); 275 var $ids = jQuery('.wooco-ids-' + wid); 276 var $btn = $ids.closest('form.cart').find('.single_add_to_cart_button'); 277 var $alert = $wrap.find('.wooco-alert'); 278 var is_selection = false;
279 var c_name = ''; 280 var is_min = false; 281 var is_max = false; 282 var is_m_min = false; 283 var is_m_max = false; 284 var is_same = false; 285 var is_total_min = false; 286 var is_total_max = false; 287 var is_count = false; 288 var selected_products = []; 289 var allow_same = $components.attr('data-same'); 290 var qty = 0; 291 var m_min = 0; 292 var m_max = 10000; 293 var qty_min = parseFloat($components.attr('data-min')); 294 var qty_max = parseFloat($components.attr('data-max')); 295 var total_min = parseFloat($components.attr('data-total-min')); 296 var total_max = parseFloat($components.attr('data-total-max')); 297 var $total = $wrap.find('.wooco-total'); 298 var $count = $wrap.find('.wooco-count'); 299 var $price = jQuery('.wooco-price-' + wid); 300 var $woobt = jQuery('.woobt-wrap-' + wid); 301 var pricing = $components.attr('data-pricing'); 302 var price = wooco_format_number($components.attr('data-price')); 303 var regular_price = wooco_format_number($components.attr('data-regular-price')); 304 var percent = wooco_format_number($components.attr('data-percent')); 305 var total = 0; 306 var total_regular = 0; 307 308 if (!$components.length || !$components.find('.wooco_component_product').length) { 309 return; 310 } 311 312 // calculate price 313 314 if (pricing === 'only') { 315 total = price; 316 total_regular = regular_price; 317 } else { 318 // calc price 319 $components.find('.wooco_component_product').each(function () { 320 var $this = jQuery(this); 321 var $checkbox = $this.find('.wooco-checkbox'); 322 var _price = wooco_format_number($this.attr('data-price')); 323 var _regular_price = wooco_format_number($this.attr('data-regular-price')); 324 var _qty = wooco_format_number($this.attr('data-qty')); 325 var _multiple = $this.attr('data-multiple'); 326 327 if ($checkbox.length && !$checkbox.prop('checked')) { 328 return; 329 } 330 331 if (_multiple === 'yes') { 332 // multiple selection 333 334 $this.find('.wooco_item_selected').each(function () { 335 var $_this = jQuery(this); 336 var __price = wooco_format_number($_this.attr('data-price')); 337 var __regular_price = wooco_format_number($_this.attr('data-regular-price')); 338 var __qty = wooco_format_number($_this.attr('data-qty')); 339 340 if ((__price > 0) && (__qty > 0)) { 341 total += __price * __qty; 342 } 343 344 if ((__regular_price > 0) && (__qty > 0)) { 345 total_regular += __regular_price * __qty; 346 } 347 }); 348 } else { 349 // single selection 350 351 if ((_price > 0) && (_qty > 0)) { 352 total += _price * _qty; 353 } 354 355 if ((_regular_price > 0) && (_qty > 0)) { 356 total_regular += _regular_price * _qty; 357 } 358 } 359 }); 360 361 // discount 362 if ((percent > 0) && (percent < 100)) { 363 total = total * (100 - percent) / 100; 364 } 365 366 if (pricing === 'include') { 367 total += price; 368 total_regular += regular_price; 369 } 370 } 371 372 var total_html = wooco_price_html(total_regular, total); 373 374 if ((pricing !== 'only') && (percent > 0) && (percent < 100)) { 375 total_html += ' <small class="woocommerce-price-suffix">' + wooco_vars.saved_text.replace('[d]', percent + '%') + '</small>'; 376 } 377 378 $total.html(wooco_vars.total_text + ' ' + total_html).slideDown(); 379 380 if ((wooco_vars.change_price !== 'no') && (pricing !== 'only')) { 381 if ((wooco_vars.change_price === 'yes_custom') && (wooco_vars.price_selector !== null) && (wooco_vars.price_selector !== '')) { 382 $price = jQuery(wooco_vars.price_selector); 383 } 384 385 $price.html(total_html); 386 } 387 388 if ($woobt.length) { 389 $woobt.find('.woobt-products').attr('data-product-price-html', total_html); 390 $woobt.find('.woobt-product-this').attr('data-price', total).attr('data-regular-price', total_regular); 391 392 woobt_init($woobt); 393 } 394 395 jQuery(document).trigger('wooco_calc_price', [total, total_regular, total_html, $wrap, context, $selected]); 396 397 // check ready 398 399 $components.find('.wooco_component_product').each(function () { 400 var $this = jQuery(this); 401 var $checkbox = $this.find('.wooco-checkbox'); 402 var _selected = false;
403 var _name = $this.attr('data-name'); 404 var _id = parseInt($this.attr('data-id')); 405 var _qty = parseFloat($this.attr('data-qty')); 406 var _required = $this.attr('data-required'); 407 var _multiple = $this.attr('data-multiple'); 408 var _custom_qty = $this.attr('data-custom-qty'); 409 410 if ($checkbox.length && !$checkbox.prop('checked')) { 411 return; 412 } 413 414 if (_custom_qty === 'yes' || _multiple === 'yes') { 415 is_count = true; 416 } 417 418 if (_multiple === 'yes') { 419 // multiple selection 420 var _m_qty = 0; 421 var _m_min = parseFloat($this.attr('data-m-min')); 422 var _m_max = parseFloat($this.attr('data-m-max')); 423 424 $this.find('.wooco_item_selected').each(function () { 425 var $_this = jQuery(this); 426 var __id = parseInt($_this.attr('data-id')); 427 var __qty = parseFloat($_this.attr('data-qty')); 428 429 if (__id > 0) { 430 qty += __qty; 431 _m_qty += __qty; 432 _selected = true; 433 } 434 435 if (allow_same === 'no') { 436 if (selected_products.includes(__id)) { 437 is_same = true; 438 } else { 439 if (__id > 0) { 440 selected_products.push(__id); 441 } 442 } 443 } 444 }); 445 446 if (_m_qty < _m_min) { 447 is_m_min = true; 448 m_min = _m_min; 449 450 if (c_name === '') { 451 c_name = _name; 452 } 453 } 454 455 if (_m_qty > _m_max) { 456 is_m_max = true; 457 m_max = _m_max; 458 459 if (c_name === '') { 460 c_name = _name; 461 } 462 } 463 } else { 464 // single selection 465 466 if (_id > 0) { 467 qty += _qty; 468 _selected = true; 469 } 470 471 if (allow_same === 'no') { 472 if (selected_products.includes(_id)) { 473 is_same = true; 474 } else { 475 if (_id > 0) { 476 selected_products.push(_id); 477 } 478 } 479 } 480 } 481 482 if (!_selected && (_required === 'yes')) { 483 is_selection = true; 484 485 if (c_name === '') { 486 c_name = _name; 487 } 488 } 489 }); 490 491 if (is_count) { 492 $count.html('<span class="wooco-count-label">' + wooco_vars.selected_text + '</span> <span class="wooco-count-value">' + qty + '</span>').slideDown(); 493 jQuery(document).trigger('wooco_change_count', [$count, qty, qty_min, qty_max]); 494 } 495 496 if (qty < qty_min) { 497 is_min = true; 498 } 499 500 if (qty > qty_max) { 501 is_max = true; 502 } 503 504 if ((pricing !== 'only')) { 505 // check total min 506 if (total_min > 0 && total < total_min) { 507 is_total_min = true; 508 } 509 510 // check total max 511 if (total_max > 0 && total > total_max) { 512 is_total_max = true; 513 } 514 } 515 516 if (is_selection || is_min || is_max || is_m_min || is_m_max || is_same || is_total_min || is_total_max) { 517 $btn.addClass('wooco-disabled'); 518 $alert.addClass('alert-active'); 519 520 if (is_selection) { 521 $alert.addClass('alert-selection').html(wooco_vars.alert_selection.replace('[name]', '<strong>' + c_name + '</strong>')); 522 } else if (is_m_min) { 523 $alert.addClass('alert-min').html(wooco_vars.alert_m_min.replace('[min]', m_min).replace('[name]', '<strong>' + c_name + '</strong>')); 524 } else if (is_m_max) { 525 $alert.addClass('alert-max').html(wooco_vars.alert_m_max.replace('[max]', m_max).replace('[name]', '<strong>' + c_name + '</strong>')); 526 } else if (is_min) { 527 $alert.addClass('alert-min').html(wooco_vars.alert_min.replace('[min]', qty_min)); 528 } else if (is_max) { 529 $alert.addClass('alert-max').html(wooco_vars.alert_max.replace('[max]', qty_max)); 530 } else if (is_same) { 531 $alert.addClass('alert-same').html(wooco_vars.alert_same); 532 } else if (is_total_min) { 533 $alert.addClass('alert-total-min').html(wooco_vars.alert_total_min.replace('[min]', wooco_format_price(total_min)).replace('[total]', wo
533oco_format_price(total))); 534 } else if (is_total_max) { 535 $alert.addClass('alert-total-max').html(wooco_vars.alert_total_max.replace('[max]', wooco_format_price(total_max)).replace('[total]', wooco_format_price(total))); 536 } 537 538 $alert.slideDown(); 539 540 jQuery(document).trigger('wooco_check_ready', [false, is_selection, is_same, is_min, is_max, $wrap, context, $selected]); 541 } else { 542 $alert.removeClass('alert-active alert-selection alert-min alert-max alert-total-min alert-total-max').slideUp(300, function () { 543 $alert.html(''); 544 }); 545 $btn.removeClass('wooco-disabled'); 546 547 // ready 548 jQuery(document).trigger('wooco_check_ready', [true, is_selection, is_same, is_min, is_max, $wrap, context, $selected]); 549 } 550} 551 552function wooco_save_ids($wrap, context = null, $selected = null) { 553 var wid = $wrap.attr('data-id'); 554 var $components = $wrap.find('.wooco-components'); 555 var $ids = jQuery('.wooco-ids-' + wid); 556 var ids = Array(); 557 558 $components.find('.wooco_component_product').each(function () { 559 var $this = jQuery(this); 560 var $checkbox = $this.find('.wooco-checkbox'); 561 var key = $this.data('key'); 562 563 if ($checkbox.length && !$checkbox.prop('checked')) { 564 return; 565 } 566 567 if ($this.attr('data-multiple') === 'yes') { 568 // multiple selection 569 $this.find('.wooco_item_selected').each(function () { 570 var $_this = jQuery(this); 571 572 if (($_this.attr('data-id') > 0) && ($_this.attr('data-qty') > 0)) { 573 ids.push($_this.attr('data-id') + '/' + $_this.attr('data-qty') + '/' + key); 574 } 575 }); 576 } else { 577 // single selection 578 579 if (($this.attr('data-id') > 0) && ($this.attr('data-qty') > 0)) { 580 ids.push($this.attr('data-id') + '/' + $this.attr('data-qty') + '/' + key); 581 } 582 } 583 }); 584 585 $ids.val(ids.join(',')); 586 jQuery(document).trigger('wooco_save_ids', [ids, $wrap, context, $selected]); 587} 588 589function wooco_show_alert($wrap, context = null, $selected = null) { 590 var $alert = $wrap.find('.wooco-alert'); 591 592 if ($alert.hasClass('alert-active')) { 593 $alert.slideDown(); 594 } else { 595 $alert.slideUp(); 596 } 597 598 jQuery(document).trigger('wooco_show_alert', [$wrap, context, $selected]); 599} 600 601function wooco_init_selector() { 602 if (wooco_vars.selector === 'ddslick') { 603 jQuery('.wooco_component_product_select').each(function () { 604 var $this = jQuery(this); 605 var $selection = $this.closest('.wooco_component_product_selection'); 606 var $component = $this.closest('.wooco_component_product'); 607 var $wrap = $this.closest('.wooco-wrap'); 608 609 $selection.data('select', 0); 610 611 $this.ddslick({ 612 width: '100%', onSelected: function (data) { 613 var _select = $selection.data('select'); 614 var $selected = jQuery(data.original[0].children[data.selectedIndex]); 615 616 if (data.selectedData.value == '-1') { 617 if (!$selection.find('.dd-selected .dd-desc').length) { 618 $selection.find('.dd-selected').addClass('dd-option-without-desc'); 619 $selection.find('.dd-option-selected').addClass('dd-option-without-desc'); 620 } else { 621 $selection.find('.dd-selected').removeClass('dd-option-without-desc'); 622 $selection.find('.dd-option-selected').removeClass('dd-option-without-desc'); 623 } 624 } 625 626 // check empty desc 627 if (!$selection.hasClass('wooco-ddslick-checked-desc')) { 628 $selection.find('.dd-selected, .dd-option').each(function () { 629 if (!jQuery(this).find('.dd-desc').length) { 630 jQuery(this).addClass('dd-option-without-desc'); 631 } else { 632 jQuery(this).removeClass('dd-option-without-desc'); 633 } 634 }); 635 636 $selection.addClass('wooco-ddslick-checked-desc'); 637 } 638 639 // check disabled 640 if (!$selection.hasClass('wooco-ddslick-checked-disabled')) { 641 $selection.find('.dd-selected, .dd-option').each(function () {
642 if (parseInt(jQuery(this).find('.dd-option-value').val()) === 0) { 643 jQuery(this).addClass('dd-option-disabled'); 644 } else { 645 jQuery(this).removeClass('dd-option-disabled'); 646 } 647 }); 648 649 $selection.addClass('wooco-ddslick-checked-disabled'); 650 } 651 652 wooco_selected($selected, $selection, $component); 653 654 if (_select > 0) { 655 wooco_init($wrap, 'on_select', $selected); 656 } else { 657 // selected on init_selector 658 wooco_init($wrap, 'selected', $selected); 659 } 660 661 $selection.data('select', _select + 1); 662 }, 663 }); 664 }); 665 } else if (wooco_vars.selector === 'select2') { 666 jQuery('.wooco_component_product_select').each(function () { 667 var $this = jQuery(this); 668 var $selection = $this.closest('.wooco_component_product_selection'); 669 var $component = $this.closest('.wooco_component_product'); 670 var $wrap = $this.closest('.wooco-wrap'); 671 672 if ($this.val() !== '') { 673 var $default = jQuery('option:selected', this); 674 675 wooco_selected($default, $selection, $component); 676 wooco_init($wrap, 'selected', $default); 677 } 678 679 $this.select2({ 680 templateResult: wooco_select2_state, 681 width: '100%', 682 containerCssClass: 'wpc-select2-container', 683 dropdownCssClass: 'wpc-select2-dropdown', 684 }); 685 }); 686 } else { 687 jQuery('.wooco_component_product_select').each(function () { 688 // check on start 689 var $this = jQuery(this); 690 var $selection = $this.closest('.wooco_component_product_selection'); 691 var $component = $this.closest('.wooco_component_product'); 692 var $wrap = $this.closest('.wooco-wrap'); 693 var $selected = jQuery('option:selected', this); 694 695 wooco_selected($selected, $selection, $component); 696 wooco_init($wrap, 'selected', $selected); 697 }); 698 } 699 700 jQuery('.wooco_component_product_selection_item.wooco_item_selected').each(function () { 701 var $this = jQuery(this); 702 var $selection = $this.closest('.wooco_component_product_selection'); 703 var $component = $this.closest('.wooco_component_product'); 704 var $wrap = $this.closest('.wooco-wrap'); 705 706 wooco_selected($this, $selection, $component); 707 wooco_init($wrap, 'selected', $this); 708 }); 709} 710 711function wooco_selected($selected, $selection, $component) { 712 var id = $selected.attr('data-id'); 713 var pid = $selected.attr('data-pid'); 714 var price = $selected.attr('data-price'); 715 var purchasable = $selected.attr('data-purchasable'); 716 var regular_price = $selected.attr('data-regular-price'); 717 var link = $selected.attr('data-link'); 718 var image = '<img src="' + $selected.attr('data-imagesrc') + '"/>'; 719 var price_html = $selected.attr('data-price-html'); 720 var availability = $selected.attr('data-availability'); 721 var custom_qty = $component.attr('data-custom-qty'); 722 var qid = id; // product ID for quick view 723 724 if (purchasable === 'yes') { 725 $component.attr('data-id', id); 726 } else { 727 $component.attr('data-id', 0); 728 } 729 730 $component.attr('data-price', price); 731 $component.attr('data-price-html', price_html); 732 $component.attr('data-regular-price', regular_price); 733 734 if (custom_qty === 'yes') { 735 if ($selected.find('.wooco_qty').length) { 736 $component.attr('data-qty', $selected.find('.wooco_qty').val()); 737 } else if ($selected.find('.qty').length) { 738 $component.attr('data-qty', $selected.find('.qty').val()); 739 } 740 } 741 742 if ((wooco_vars.quickview_variation === 'parent') && pid) { 743 qid = pid; 744 } 745 746 if (wooco_vars.product_link !== 'no') { 747 $selection.find('.wooco_component_product_link').remove(); 748 if (link !== '') { 749 if (wooco_vars.product_link === 'yes_popup') { 750 $selection.append('<a class="wooco_component_product_link woosq-link" data-id="' + qid + '" data-context="wooco" href="' + link + '" target="_blank"> </a>'); 751 } else { 752 $selection.append('<a class="wooco_component_product_link" href="' + link + '" target="_blank"> </a>'); 753 } 754 } 755 } 756 757 $component.find('.wooco_component_product_image').html(image); 758 $component.find('.wooco_component_product_price').html(price_html); 759 $component.find('.wooco_component_product_availability').html(availability); 760 761 jQuery(document).trigger('wooco_selected', [$selected, $selection, $component]); 762} 763 764function wooco_deselect($selected, $selection, $component) { 765 jQuery(document).trigger('wooco_deselected', [$selected, $selection, $component]); 766} 767 768function wooco_select2_state(state) { 769 if (!state.id) { 770 return state.text; 771 } 772 773 var $state = {}; 774 775 if (jQuery(state.element).attr('data-imagesrc') !== '') { 776 $state = jQuery('<span class="image"><img src="' + jQuery(state.element).attr('data-imagesrc') + '"/></span><span class="info"><span class="name">' + state.text + '</span> <span class="desc">' + jQuery(state.element).attr('data-description') + '</span></span>'); 777 } else { 778 $state = jQuery('<span class="info"><span class="name">' + state.text + '</span> <span class="desc">' + jQuery(state.element).attr('data-description') + '</span></span>'); 779 } 780 781 return $state; 782} 783 784function wooco_round(value) { 785 return Number(Math.round(value + 'e' + wooco_vars.price_decimals) + 'e-' + wooco_vars.price_decimals); 786} 787 788function wooco_decimal_places(num) { 789 var match = ('' + num).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/); 790 791 if (!match) { 792 return 0; 793 } 794 795 return Math.max(0, // Number of digits right of decimal point. 796 (match[1] ? match[1].length : 0) 797 // Adjust for scientific notation. 798 - (match[2] ? +match[2] : 0)); 799} 800 801function wooco_format_money(number, places, symbol, thousand, decimal) { 802 number = number || 0; 803 places = !isNaN(places = Math.abs(places)) ? places : 2; 804 symbol = symbol !== undefined ? symbol : '$'; 805 thousand = thousand || ''; 806 decimal = decimal || ''; 807 808 var negative = number < 0 ? '-' : '', i = parseInt(number = Math.abs(+number || 0).toFixed(places), 10) + '', j = 0; 809 810 if (i.length > 3) { 811 j = i.length % 3; 812 } 813 814 if (wooco_vars.trim_zeros === '1') { 815 return symbol + negative + (j ? i.substr(0, j) + thousand : '') + i.substr(j).replace(/(\d{3})(?=\d)/g, '$1' + thousand) + (places && (parseFloat(number) > parseFloat(i)) ? decimal + Math.abs(number - i).toFixed(places).slice(2).replace(/(\d*?[1-9])0+$/g, '$1') : ''); 816 } else { 817 return symbol + negative + (j ? i.substr(0, j) + thousand : '') + i.substr(j).replace(/(\d{3})(?=\d)/g, '$1' + thousand) + (places ? decimal + Math.abs(number - i).toFixed(places).slice(2) : ''); 818 } 819} 820 821function wooco_format_number(number) { 822 return parseFloat(number.replace(/[^0-9.,]/g, '').replace(',', '.')); 823} 824 825function wooco_format_price(price) { 826 var price_html = '<span class="woocommerce-Price-amount amount">'; 827 var price_formatted = wooco_format_money(price, wooco_vars.price_decimals, '', wooco_vars.price_thousand_separator, wooco_vars.price_decimal_separator); 828 829 switch (wooco_vars.price_format) { 830 case '%1$s%2$s': 831 //left 832 price_html += '<span class="woocommerce-Price-currencySymbol">' + wooco_vars.currency_symbol + '</span>' + price_formatted; 833 break; 834 case '%1$s %2$s': 835 //left with space 836 price_html += '<span class="woocommerce-Price-currencySymbol">' + wooco_vars.currency_symbol + '</span> ' + price_formatted; 837 break; 838 case '%2$s%1$s': 839 //right 840 price_html += price_formatted + '<span class="woocommerce-Price-currencySymbol">' + wooco_vars.currency_symbol + '</span>'; 841 break; 842 case '%2$s %1$s': 843 //right with space 844 price_html += price_formatted + ' <span class="woocommerce-Price-currencySymbol">' + wooco_vars.currency_symbol + '</span>'; 845 break; 846 default: 847 //default 848 price_html += '<span class="woocommerce-Price-currencySymbol">' + wooco_vars.currency_symbol + '</span> ' + price_formatted; 849 } 850 851 price_html += '</span>'; 852 853 return price_html; 854} 855 856function wooco_price_html(regular_price, sale_price) { 857 var price_html = ''; 858 859 if (wooco_round(sale_price) !== wooco_round(regular_price)) { 860 if (wooco_round(sale_price) < wooco_round(regular_price)) { 861 price_html = '<del>' + wooco_format_price(regular_price) + '</del> <ins>' + wooco_format_price(sale_price) + '</ins>'; 862 } else { 863 price_html = wooco_format_price(sale_price); 864 } 865 } else { 866 price_html = wooco_format_price(regular_price); 867 } 868 869 return price_html; 870}
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.