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