1'use strict'; 2 3(function($) { 4 $(function() { 5 if (!$('.woobt-wrap').length) { 6 return; 7 } 8 9 $('.woobt-wrap').each(function() { 10 woobt_check_position($(this)); 11 woobt_init($(this)); 12 }); 13 }); 14 15 $(document).on('woosq_loaded', function() { 16 woobt_init($('#woosq-popup').find('.woobt-wrap')); 17 }); 18 19 $(document).on('woovr_selected', function(e, selected, variations) { 20 var $wrap = variations.closest('.woobt-wrap'); 21 var $products = variations.closest('.woobt-products'); 22 var $product = variations.closest('.woobt-product'); 23 var id = selected.attr('data-id'); 24 var sku = selected.attr('data-sku'); 25 var weight = selected.attr('data-weight'); 26 var dimensions = selected.attr('data-dimensions'); 27 var order = $product.attr('data-order'); 28 var pricing = $products.attr('data-pricing'); 29 var price_html = selected.attr('data-pricehtml'); 30 var display_price = selected.attr('data-price'); 31 var price = selected.attr('data-price'); 32 var regular_price = selected.attr('data-regular-price'); 33 var purchasable = selected.attr('data-purchasable'); 34 var attrs = selected.attr('data-attrs'); 35 var woobt_image = selected.attr('data-woobt_image'); 36 37 if (pricing == 'regular_price') { 38 price = regular_price; 39 } 40 41 if ($product.length) { 42 if (purchasable === 'yes') { 43 // change data 44 $product.attr('data-id', id); 45 $product.attr('data-price', price); 46 $product.attr('data-regular-price', regular_price); 47 48 // change image 49 if (woobt_image !== undefined && woobt_image !== '') { 50 var $img = $wrap.find('.woobt-img-order-' + order); 51 52 if ($img.length) { 53 $img.html(woobt_image); 54 } 55 } else { 56 var $img = $wrap.find('.woobt-img-order-' + order); 57 58 if ($img.length) { 59 $img.html($img.attr('data-img')); 60 } 61 } 62 63 // change price 64 var new_price = $product.attr('data-new-price'); 65 66 $product.find('.woobt-price-ori').hide(); 67 68 if (new_price != '100%') { 69 if (isNaN(new_price)) { 70 new_price = price * parseFloat(new_price) / 100; 71 } 72 73 $product.find('.woobt-price-new'). 74 html(woobt_price_html(display_price, new_price)).show(); 75 } else { 76 $product.find('.woobt-price-new').html(price_html).show(); 77 } 78 79 // change attributes 80 $product.attr('data-attrs', attrs.replace(/\/$/, '')); 81 82 // change separate add to cart 83 if ($product.hasClass('woobt-product-this')) { 84 $products.attr('data-product-id', id); 85 $wrap.find('.variation_id').attr('value', id); 86 } 87 } else { 88 // reset data 89 $product.attr('data-id', 0); 90 $product.attr('data-attrs', ''); 91 $product.attr('data-price', 0); 92 $product.attr('data-regular-price', 0); 93 94 // reset price 95 $product.find('.woobt-price-ori').show(); 96 $product.find('.woobt-price-new').html('').hide(); 97 98 // reset separate add to cart 99 if ($product.hasClass('woobt-product-this')) { 100 $products.attr('data-product-id', 0); 101 $wrap.find('.variation_id').attr('value', 0); 102 } 103 104 // reset image 105 var $img = $wrap.find('.woobt-img-order-' + order); 106 107 if ($img.length) { 108 $img.html($img.attr('data-img')); 109 } 110 } 111 112 // prevent changing SKU / weight / dimensions 113 $('.product_meta .sku').html($products.attr('data-product-sku')); 114 $('.product_weight, .woocommerce-product-attributes-item--weight .woocommerce-product-attributes-item__value'). 115 html($products.attr('data-product-weight')); 116 $('.product_dimensions, .woocommerce-product-attributes-item--dimensions .woocommerce-product-attributes-item__value'). 117 html($products.attr('data-product-dimensions')); 118 } else { 119 var pid = variations.closest('.variations_form').attr('data-product_id'); 120 121 $wrap = $('.woobt-wrap-' + pid); 122 $products = $('.woobt-products-' + pid); 123 124 if (id > 0) { 125 $products.attr('data-product-id', id); 126 127 $products.find('.woobt-product-this').attr('data-price', price); 128 $products.find('.woobt-product-this'). 129 attr('data-regular-price', regular_price); 130 131 if (price_html !== '') { 132 // change this price 133 $products.find('.woobt-product-this .woobt-price-ori').hide(); 134 $products.find('.woobt-product-this .woobt-price-new'). 135 html(price_html). 136 show(); 137 } 138 139 if (woobt_image !== undefined && woobt_image !== '') { 140 // change this image 141 $wrap.find('.woobt-img-order-' + order).html(woobt_image); 142 } 143 144 $products.attr('data-product-sku', sku); 145 $products.attr('data-product-weight', weight); 146 $products.attr('data-product-dimensions', dimensions); 147 } else { 148 // reset 149 $products.attr('data-product-id', 0); 150 151 $products.find('.woobt-product-this').attr('data-price', 0); 152 $products.find('.woobt-product-this').attr('data-regular-price', 0); 153 154 $products.find('.woobt-product-this .woobt-price-new').hide(); 155 $products.find('.woobt-product-this .woobt-price-ori').show(); 156 157 var $img = $wrap.find('.woobt-img-order-' + order); 158 159 if ($img.length) { 160 $img.html($img.attr('data-img')); 161 } 162 163 $products.attr('data-product-sku', 164 $products.attr('data-product-o_sku')); 165 $products.attr('data-product-weight', 166 $products.attr('data-product-o_weight')); 167 $products.attr('data-product-dimensions', 168 $products.attr('data-product-o_dimensions')); 169 } 170 } 171 172 woobt_init($wrap); 173 }); 174 175 $(document).on('found_variation', function(e, t) { 176 var $wrap = $(e['target']).closest('.woobt-wrap'); 177 var $products = $(e['target']).closest('.woobt-products'); 178 var $product = $(e['target']).closest('.woobt-product'); 179 var atc_button = $wrap.attr('data-atc-button'); 180 var pricing = $products.attr('data-pricing'); 181 var price_html = t['price_html']; 182 var display_price = t['display_price']; 183 var display_regular_price = t['display_regular_price']; 184 var order = $product.attr('data-order'); 185 var pid = $(e['target']). 186 closest('.variations_form'). 187 attr('data-product_id'); 188 189 if (pricing == 'regular_price') { 190 display_price = display_regular_price; 191 } 192 193 if ($product.length) { 194 if ($product.hasClass('woobt-product-together')) { 195 var new_price = $product.attr('data-new-price'); 196 197 if (new_price !== '100%') { 198 if (isNaN(new_price)) { 199 new_price = display_price * parseFloat(new_price) / 100; 200 } 201 202 $product.find('.woobt-price-ori').hide(); 203 $product.find('.woobt-price-new'). 204 html(woobt_price_html(display_price, new_price)).show(); 205 } else if (price_html !== '') { 206 $product.find('.woobt-price-ori').hide(); 207 $product.find('.woobt-price-new').html(price_html).show(); 208 } 209 } else { 210 $products.attr('data-product-id', t['variation_id']); 211 212 if (price_html !== '') { 213 $product.find('.woobt-price-ori').hide(); 214 $product.find('.woobt-price-new').html(price_html).show(); 215 } 216 } 217 218 $product.attr('data-price', display_price); 219 $product.attr('data-regular-price', display_regular_price); 220 221 if (t['is_purchasable'] && t['is_in_stock']) { 222 $product.attr('data-id', t['variation_id']); 223 224 if ($product.hasClass('woobt-product-this')) { 225 $wrap.find('.variation_id').attr('value', t['variation_id']); 226 } 227 228 // change attributes 229 var attrs = {}; 230 231 $product.find('select[name^="attribute_"]').each(function() { 232 var attr_name = $(this).attr('name'); 233 234 attrs[attr_name] = $(this).val(); 235 }); 236 237 $product.attr('data-attrs', JSON.stringify(attrs)); 238 } else { 239 $product.attr('data-id', 0); 240 $product.attr('data-attrs', ''); 241 242 if ($product.hasClass('woobt-product-this')) { 243 $wrap.find('.variation_id').attr('value', 0); 244 } 245 } 246 247 // change availability 248 if (t['availability_html'] && t['availability_html'] !== '') { 249 $product.find('.woobt-availability'). 250 html(t['availability_html']).show(); 251 } else { 252 $product.find('.woobt-availability').html('').hide(); 253 } 254 255 // prevent changing SKU / weight / dimensions 256 $('.product_meta .sku').html($products.attr('data-product-sku')); 257 $('.product_weight, .woocommerce-product-attributes-item--weight .woocommerce-product-attributes-item__value'). 258 html($products.attr('data-product-weight')); 259 $('.product_dimensions, .woocommerce-product-attributes-item--dimensions .woocommerce-product-attributes-item__value'). 260 html($products.attr('data-product-dimensions')); 261 262 if (woobt_vars.change_image === 'no') { 263 // prevent changing the main image 264 $wrap.find('.variations_form').trigger('reset_image'); 265 $('form.variations_form'). 266 wc_variations_image_update($wrap.data('variation')); 267 } 268 269 // change image 270 if (t['woobt_image'] !== undefined && t['woobt_image'] !== '') { 271 var $img = $wrap.find('.woobt-img-order-' + order); 272 273 if ($img.length) { 274 $img.html(t['woobt_image']); 275 } 276 } else { 277 var $img = $wrap.find('.woobt-img-order-' + order); 278 279 if ($img.length) { 280 $img.html($img.attr('data-img')); 281 } 282 } 283 } else { 284 if ($(e['target']).closest('.woosb-product').length || 285 $(e['target']).closest('.woosg-product').length || 286 $(e['target']).closest('.woofs-product').length) { 287 return; 288 } 289 290 $wrap = $('.woobt-wrap-' + pid); 291 atc_button = $wrap.attr('data-atc-button'); 292 $wrap.data('variation', t); 293 294 if (atc_button === 'main') {
295 $products = $('.woobt-products-' + pid); 296 $products.attr('data-product-sku', t['sku']); 297 $products.attr('data-product-id', t['variation_id']); 298 $products.attr('data-product-weight', t['weight_html']); 299 $products.attr('data-product-dimensions', t['dimensions_html']); 300 301 if (t['price_html'] !== '') { 302 $products.attr('data-product-price-html', t['price_html']); 303 } 304 305 if ($products.find('.woobt-product-this').length) { 306 $products.find('.woobt-product-this'). 307 attr('data-id', t['variation_id']); 308 $products.find('.woobt-product-this'). 309 attr('data-price', display_price); 310 $products.find('.woobt-product-this'). 311 attr('data-regular-price', display_regular_price); 312 313 if (price_html !== '') { 314 // change this price 315 $products.find('.woobt-product-this .woobt-price-ori').hide(); 316 $products.find('.woobt-product-this .woobt-price-new'). 317 html(price_html).show(); 318 } 319 320 // change this image 321 if (t['woobt_image'] !== undefined && t['woobt_image'] !== '') { 322 var $img_0 = $wrap.find('.woobt-img-order-0'); 323 324 if ($img_0.length) { 325 $img_0.html(t['woobt_image']); 326 } 327 } else { 328 var $img_0 = $wrap.find('.woobt-img-order-0'); 329 330 if ($img_0.length) { 331 $img_0.html($img_0.attr('data-img')); 332 } 333 } 334 } 335 } 336 } 337 338 woobt_init($wrap); 339 }); 340 341 $(document).on('reset_data', function(e) { 342 var $wrap = $(e['target']).closest('.woobt-wrap'); 343 var atc_button = $wrap.attr('data-atc-button'); 344 var $products = $(e['target']).closest('.woobt-products'); 345 var $product = $(e['target']).closest('.woobt-product'); 346 var order = $product.attr('data-order'); 347 348 if ($product.length) { 349 $product.attr('data-id', 0); 350 $product.attr('data-attrs', ''); 351 352 // prevent changing the main image 353 $('form.variations_form'). 354 wc_variations_image_update($wrap.data('variation')); 355 356 // reset stock 357 $(e['target']).closest('.variations_form').find('p.stock').remove(); 358 359 // reset SKU / weight / dimensions 360 $('.product_meta .sku').html($products.attr('data-product-sku')); 361 $('.product_weight, .woocommerce-product-attributes-item--weight .woocommerce-product-attributes-item__value'). 362 html($products.attr('data-product-weight')); 363 $('.product_dimensions, .woocommerce-product-attributes-item--dimensions .woocommerce-product-attributes-item__value'). 364 html($products.attr('data-product-dimensions')); 365 366 // reset availability 367 $product.find('.woobt-availability').html('').hide(); 368 369 // reset price 370 $product.find('.woobt-price-new').hide(); 371 $product.find('.woobt-price-ori').show(); 372 373 if ($product.hasClass('woobt-product-this')) { 374 $products.attr('data-product-id', 0); 375 } 376 377 // reset image 378 var $img = $wrap.find('.woobt-img-order-' + order); 379 380 if ($img.length) { 381 $img.html($img.attr('data-img')); 382 } 383 } else { 384 if ($(e['target']).closest('.woosb-product').length || 385 $(e['target']).closest('.woosg-product').length || 386 $(e['target']).closest('.woofs-product').length) { 387 return; 388 } 389 390 var pid = $(e['target']). 391 closest('.variations_form'). 392 attr('data-product_id'); 393 394 $wrap = $('.woobt-wrap-' + pid); 395 atc_button = $wrap.attr('data-atc-button'); 396 $wrap.removeData('variation'); 397 398 if (atc_button === 'main') { 399 $products = $('.woobt-products-' + pid); 400 $products.attr('data-product-id', 0); 401 $products.attr('data-product-sku', 402 $products.attr('data-product-o_sku')); 403 $products.attr('data-product-weight', 404 $products.attr('data-product-o_weight')); 405 $products.attr('data-product-dimensions', 406 $products.attr('data-product-o_dimensions')); 407 $products.attr('data-product-price-html', 408 $products.attr('data-product-o_price-html')); 409 410 // change this price 411 $products.find('.woobt-product-this').attr('data-id', 0); 412 413 // reset this image 414 var $img_0 = $wrap.find('.woobt-img-order-0'); 415 416 if ($img_0.length) { 417 $img_0.html($img_0.attr('data-img')); 418 } 419 } 420 } 421 422 woobt_init($wrap); 423 }); 424 425 $(document). 426 on('click touch', 427 '.woobt-quantity-input-plus, .woobt-quantity-input-minus', 428 function() { 429 // get values 430 var $qty = $(this).closest('.woobt-quantity').find('.woobt-qty'); 431 432 if (!$qty.length) { 433 $qty = $(this).closest('.woobt-quantity').find('.qty'); 434 } 435 436 var val = parseFloat($qty.val()), 437 max = parseFloat($qty.attr('max')), 438 min = parseFloat($qty.attr('min')), step = $qty.attr('step'); 439 440 // format values 441 if (!val || val === '' || val === 'NaN') { 442 val = 0; 443 } 444 445 if (max === '' || max === 'NaN') { 446 max = ''; 447 } 448 449 if (min === '' || min === 'NaN') { 450 min = 0; 451 } 452 453 if (step === 'any' || step === '' || step === undefined || 454 parseFloat(step) === 'NaN') { 455 step = 1; 456 } else { 457 step = parseFloat(step); 458 } 459 460 // change the value 461 if ($(this).is('.woobt-quantity-input-plus')) { 462 if (max && (max == val || val > max)) { 463 $qty.val(max); 464 } else { 465 $qty.val((val + step).toFixed(woobt_decimal_places(step))); 466 } 467 } else { 468 if (min && (min == val || val < min)) { 469 $qty.val(min); 470 } else if (val > 0) { 471 $qty.val((val - step).toFixed(woobt_decimal_places(step))); 472 } 473 } 474 475 // trigger change event 476 $qty.trigger('change'); 477 }); 478 479 $(document). 480 on('click touch', '.single_add_to_cart_button:not(.wpcbn-btn)', 481 function(e) { 482 if ($(this).hasClass('woobt-disabled')) { 483 e.preventDefault(); 484 } 485 }); 486
487 $(document).on('change', '.woobt-checkbox', function() { 488 var $wrap = $(this).closest('.woobt-wrap'); 489 var selection = $wrap.attr('data-selection'); 490 491 if (selection === 'single') { 492 $wrap.find('.woobt-checkbox'). 493 not('.woobt-checkbox-this'). 494 not(this). 495 prop('checked', false); 496 } 497 498 woobt_init($wrap); 499 }); 500 501 $(document).on('change keyup mouseup', '.woobt-this-qty', function() { 502 var val = $(this).val(); 503 var pid = $(this).closest('.woobt-wrap').attr('data-id'); 504 var $ids = $('.woobt-ids-' + pid); 505 var $form = $ids.closest('form.cart').length ? 506 $ids.closest('form.cart') : 507 $ids.closest('.woobt-form'); 508 509 $(this).closest('.woobt-product-this').attr('data-qty', val); 510 511 $form.find('input[name="quantity"]').val(val).trigger('change'); 512 }); 513 514 $(document). 515 on('change keyup mouseup', '.woobt-qty, .woobt-quantity .qty', 516 function() { 517 var $this = $(this); 518 var $wrap = $this.closest('.woobt-wrap'); 519 var $product = $this.closest('.woobt-product'); 520 var $checkbox = $product.find('.woobt-checkbox'); 521 var val = parseFloat($this.val()); 522 523 if ($checkbox.prop('checked')) { 524 var min = parseFloat($this.attr('min')); 525 var max = parseFloat($this.attr('max')); 526 527 if (val < min) { 528 $this.val(min); 529 } 530 531 if (val > max) { 532 $this.val(max); 533 } 534 535 $product.attr('data-qty', $this.val()); 536 537 woobt_init($wrap); 538 } 539 }); 540 541 $(document).on('change', 'form.cart .qty', function() { 542 var $this = $(this); 543 var qty = parseFloat($this.val()); 544 545 if ($this.hasClass('woobt-qty') || 546 $this.closest('.woobt-quantity').length) { 547 return; 548 } 549 550 if (!$this.closest('form.cart').find('.woobt-ids').length) { 551 return; 552 } 553 554 var wrap_id = $this.closest('form.cart').find('.woobt-ids').attr('data-id'); 555 var $wrap = $('.woobt-wrap-' + wrap_id); 556 var $products = $wrap.find('.woobt-products'); 557 var optional = $products.attr('data-optional'); 558 var sync_qty = $products.attr('data-sync-qty'); 559 560 $products.find('.woobt-product-this').attr('data-qty', qty); 561 562 if ((optional !== 'on') && (sync_qty === 'on')) { 563 $products.find('.woobt-product-together').each(function() { 564 var _qty = parseFloat($(this).attr('data-o_qty')) * qty; 565 566 $(this).attr('data-qty', _qty); 567 $(this).find('.woobt-qty-num .woobt-qty').html(_qty); 568 }); 569 } 570 571 woobt_init($wrap); 572 }); 573 574 $(document). 575 on('click touch', '.woobt-form .single_add_to_cart_button', function(e) { 576 e.preventDefault(); 577 var $btn = $(this); 578 var $form = $btn.closest('.woobt-form'); 579 var $wrap = $btn.closest('.woobt-wrap'); 580 // variable product 581 var data = {}; 582 var attrs = {}; 583 584 $btn.removeClass('added').addClass('loading'); 585 586 $wrap.find('.woobt-product-this select[name^=attribute]'). 587 each(function() { 588 var attribute = $(this).attr('name'); 589 var attribute_value = $(this).val(); 590 591 attrs[attribute] = attribute_value; 592 }); 593 594 data.action = 'woobt_add_all_to_cart'; 595 data.quantity = $form.find('input[name="quantity"]').val(); 596 data.product_id = $form.find('input[name="product_id"]').val(); 597 data.variation_id = $form.find('input[name="variation_id"]').val(); 598 data.woobt_ids = $form.find('input[name="woobt_ids"]').val(); 599 data.variation = attrs; 600 601 $.post(woobt_vars.ajax_url, data, function(response) { 602 if (!response) { 603 return; 604 } 605 606 if (response.error && response.product_url) { 607 window.location = response.product_url; 608 return; 609 } 610 611 if ((typeof wc_add_to_cart_params !== 'undefined') && 612 (wc_add_to_cart_params.cart_redirect_after_add === 'yes')) { 613 window.location = wc_add_to_cart_params.cart_url; 614 return; 615 } 616 617 $btn.removeClass('loading'); 618 $(document.body). 619 trigger('added_to_cart', 620 [response.fragments, response.cart_hash, $btn]); 621 }); 622 }); 623})(jQuery); 624 625function woobt_init($wrap) { 626 woobt_check_ready($wrap); 627 woobt_calc_price($wrap); 628 woobt_save_ids($wrap); 629
630 if (woobt_vars.counter !== 'hide') { 631 woobt_update_count($wrap); 632 } 633 634 jQuery(document).trigger('woobt_init', [$wrap]); 635} 636 637function woobt_check_position($wrap) { 638 var pid = $wrap.attr('data-id'); 639 var position = $wrap.attr('data-position'); 640 var atc_button = $wrap.attr('data-atc-button'); 641 var $products = $wrap.find('.woobt-products'); 642 var $ids = jQuery('.woobt-ids-' + pid); 643 644 if ((position === 'before') && 645 (atc_button === 'main') && 646 ($products.attr('data-product-type') === 'variable') && 647 ($products.attr('data-variables') === 'no' || 648 woobt_vars.variation_selector === 'woovr')) { 649 $products.closest('.woobt-wrap').insertAfter($ids); 650 } 651 652 jQuery(document).trigger('woobt_check_position', [$wrap]); 653} 654 655function woobt_check_ready($wrap) { 656 var pid = $wrap.attr('data-id'); 657 var $products = $wrap.find('.woobt-products'); 658 var $alert = $wrap.find('.woobt-alert'); 659 var $ids = jQuery('.woobt-ids-' + pid); 660 var $form = $ids.closest('.woobt-form').length ? 661 $ids.closest('.woobt-form') : 662 $ids.closest('form.cart'); 663 var $btn = $form.find('.single_add_to_cart_button:not(.wpcbn-btn)'); 664 var is_selection = false; 665 var selection_name = ''; 666 667 $products.find('.woobt-product').each(function() { 668 var $this = jQuery(this); 669 var $images = $this.closest('.woobt-wrap').find('.woobt-images'); 670 var _checked = $this.find('.woobt-checkbox').prop('checked'); 671 var _id = parseInt($this.attr('data-id')); 672 var _qty = parseInt($this.attr('data-qty')); 673 var _pid = parseInt($this.attr('data-pid')); 674 var _order = parseInt($this.attr('data-order')); 675 676 if ($this.hasClass('woobt-hide-this')) { 677 return true; 678 } 679 680 if (!_checked) { 681 $this.addClass('woobt-hide'); 682 683 if ($images.length) { 684 $images.find('.woobt-image-order-' + _order). 685 addClass('woobt-image-hide'); 686 } 687 } else { 688 $this.removeClass('woobt-hide'); 689 690 if ($images.length) { 691 $images.find('.woobt-image-order-' + _order). 692 removeClass('woobt-image-hide'); 693 } 694 } 695 696 if (_checked && (_id == 0) && (_qty > 0)) { 697 is_selection = true; 698 699 if (selection_name === '') { 700 selection_name = $this.attr('data-name'); 701 } 702 } 703 }); 704 705 if (is_selection) { 706 $btn.addClass('woobt-disabled woobt-selection'); 707 $alert.html(woobt_vars.alert_selection.replace('[name]', 708 '<strong>' + selection_name + '</strong>')).slideDown(); 709 710 jQuery(document).trigger('woobt_check_ready', [false, is_selection, $wrap]); 711 } else { 712 $btn.removeClass('woobt-disabled woobt-selection'); 713 $alert.html('').slideUp(); 714 715 // ready 716 jQuery(document).trigger('woobt_check_ready', [true, is_selection, $wrap]); 717 } 718} 719 720function woobt_calc_price($wrap) { 721 var pid = $wrap.attr('data-id'); 722 var atc_button = $wrap.attr('data-atc-button'); 723 var $additional = $wrap.find('.woobt-additional'); 724 var $total = $wrap.find('.woobt-total'); 725 var $products = $wrap.find('.woobt-products'); 726 var $product_this = $products.find('.woobt-product-this'); 727 var count = 0, total = 0; 728 var additional_html = '', total_html = ''; 729 var discount = parseFloat($products.attr('data-discount')); 730 var ori_price_suffix = $products.attr('data-product-price-suffix'); 731 var ori_price = parseFloat($product_this.attr('data-price')); 732 var ori_price_regular = parseFloat($product_this.attr('data-regular-price')); 733 var ori_qty = parseFloat($product_this.attr('data-qty')); 734 var total_ori = ori_price * ori_qty; 735 var total_ori_regular = ori_price_regular * ori_qty; 736 var $price = jQuery('.woobt-price-' + pid); 737 var show_price = $products.attr('data-show-price'); 738 var fix = Math.pow(10, Number(woobt_vars.price_decimals) + 1); 739 740 if ((woobt_vars.change_price === 'yes_custom') && 741 (woobt_vars.price_selector != null) && 742 (woobt_vars.price_selector !== '')) { 743 $price = jQuery(woobt_vars.price_selector); 744 } 745 746 $products.find('.woobt-product-together').each(function() { 747 var $this = jQuery(this); 748 var _checked = $this.find('.woobt-checkbox').prop('checked'); 749 var _id = parseInt($this.attr('data-id')); 750 var _qty = parseFloat($this.attr('data-qty')); 751 var _price = $this.attr('data-new-price'); 752 var _price_suffix = $this.attr('data-price-suffix'); 753 var _sale_price = parseFloat($this.attr('data-price')); 754 var _regular_price = parseFloat($this.attr('data-regular-price')); 755 var _total_ori = 0, _total_ori_regular = 0, _total = 0; 756 757 _total_ori = _qty * _sale_price; 758 _total_ori_regular = _qty * _sale_price; 759 760 if (isNaN(_price)) { 761 // is percent 762 if (_price == '100%') { 763 _total_ori = _qty * _regular_price; 764 _total_ori_regular = _qty * _regular_price; 765 _total = _qty * _sale_price; 766 } else { 767 _total = _total_ori * parseFloat(_price) / 100; 768 } 769 } else { 770 _total = _qty * _price; 771 } 772 773 if (show_price === 'total') { 774 $this.find('.woobt-price-ori').hide(); 775 $this.find('.woobt-price-new'). 776 html(woobt_price_html(_total_ori, _total) + _price_suffix
776). 777 show(); 778 } 779 780 // calc total 781 if (_checked && (_qty > 0) && (_id > 0)) { 782 count++; 783 total += _total; 784 total_ori_regular += _total_ori_regular; 785 } 786 }); 787 788 total = Math.round(total * fix) / fix; 789 790 if ($product_this.length) { 791 var _id = parseInt($product_this.attr('data-id')); 792 var _qty = parseFloat($product_this.attr('data-qty')); 793 794 if (_qty > 0 && _id > 0) { 795 var _price_suffix = $product_this.attr('data-price-suffix'); 796 var _sale_price = parseFloat($product_this.attr('data-price')); 797 var _regular_price = parseFloat($product_this.attr('data-regular-price')); 798 var _total_ori = 0, _total_ori_regular = 0, _total = 0; 799 800 if (show_price !== 'total') { 801 _qty = 1; 802 } 803 804 _total_ori_regular = _qty * _regular_price; 805 _total_ori = _qty * _regular_price; 806 _total = _qty * _sale_price; 807 808 if (total > 0 && parseFloat($product_this.attr('data-id')) > 0) { 809 var _price = $product_this.attr('data-new-price'); 810 811 _total_ori = _qty * _sale_price; 812 813 if (isNaN(_price)) { 814 // is percent 815 if (_price !== '100%') { 816 _total = _total_ori * parseFloat(_price) / 100; 817 } 818 } else { 819 _total = _qty * _price; 820 } 821 } 822 823 $product_this.find('.woobt-price-ori').hide(); 824 $product_this.find('.woobt-price-new'). 825 html(woobt_price_html(_total_ori_regular, _total) + _price_suffix). 826 show(); 827 } else { 828 $product_this.find('.woobt-price-new').hide(); 829 $product_this.find('.woobt-price-ori').show(); 830 } 831 } 832 833 if (count > 0) { 834 if (isNaN(discount)) { 835 discount = 0; 836 } 837 838 total_ori = total_ori * (100 - discount) / 100 + total; 839 840 $additional.html( 841 woobt_vars.additional_price_text + ' ' + woobt_format_price(total) + 842 ori_price_suffix). 843 slideDown(); 844 $total.html( 845 woobt_vars.total_price_text + ' ' + woobt_format_price(total_ori) + 846 ori_price_suffix). 847 slideDown(); 848 } else { 849 $additional.html('').slideUp(); 850 $total.html('').slideUp(); 851 } 852 853 // change the main price 854 if ((woobt_vars.change_price !== 'no') && 855 (atc_button !== 'separate')) { 856 if (parseInt($products.attr('data-product-id')) > 0 && count > 0) { 857 $price.html( 858 woobt_price_html(total_ori_regular, total_ori) + ori_price_suffix); 859 } else { 860 $price.html($products.attr('data-product-price-html')); 861 } 862 } 863 864 jQuery(document). 865 trigger('woobt_calc_price', [total, total_ori, total_ori_regular]); 866 867 if ($wrap.find('.woobt-wrap').length) { 868 $wrap.find('.woobt-wrap').attr('data-total', total); 869 } else { 870 $wrap.attr('data-total', total); 871 } 872} 873 874function woobt_save_ids($wrap) { 875 var pid = $wrap.attr('data-id'); 876 var $products = $wrap.find('.woobt-products'); 877 var sync_qty = $products.attr('data-sync-qty'); 878 var $ids = jQuery('.woobt-ids-' + pid); 879 var items = []; 880 881 $products.find('.woobt-product-together').each(function() { 882 var $this = jQuery(this); 883 var checked = $this.find('.woobt-checkbox').prop('checked'); 884 var id = parseInt($this.attr('data-id')); 885 var key = $this.data('key'); 886 var qty = parseFloat($this.attr('data-qty')); 887 var qty_ori = parseFloat($this.attr('data-o_qty')); 888 var attrs = $this.attr('data-attrs'); 889 890 if (checked && (qty > 0) && (id > 0)) { 891 if (attrs !== undefined) { 892 attrs = encodeURIComponent(attrs); 893 } else { 894 attrs = ''; 895 } 896 897 if (sync_qty === 'on') { 898 items.push(id + '/' + key + '/' + qty_ori + '/' + attrs); 899 } else { 900 items.push(id + '/' + key + '/' + qty + '/' + attrs); 901 } 902 } 903 }); 904 905 if (items.length > 0) { 906 $ids.val(items.join(',')); 907 } else { 908 $ids.val(''); 909 } 910} 911 912function woobt_update_count($wrap) { 913 var pid = $wrap.attr('data-id'); 914 var $products = $wrap.find('.woobt-products'); 915 var $ids = jQuery('.woobt-ids-' + pid); 916 var $form = $ids.closest('form.cart').length ? 917 $ids.closest('form.cart') : 918 $ids.closest('.woobt-form'); 919 var $btn = $form.find('.single_add_to_cart_button:not(.wpcbn-btn)'); 920 var qty = 0; 921 var num = 0; 922 923 $products.find('.woobt-product').each(function() { 924 var $this = jQuery(this); 925 var _checked = $this.find('.woobt-checkbox').prop('checked'); 926 var _id = parseInt($this.attr('data-id')); 927 var _qty = parseFloat($this.attr('data-qty')); 928 929 if (_checked && (_qty > 0) && (_id > 0)) { 930 qty += _qty; 931 num++; 932 } 933 }); 934 935 if (num > 1) {
936 if (woobt_vars.counter === 'individual') { 937 if ($btn.find('.woobt-count').length) { 938 $btn.find('.woobt-count').text(num); 939 } else { 940 $btn.append('<span class="woobt-count">' + num + '</span>'); 941 } 942 } else { 943 if ($btn.find('.woobt-count').length) { 944 $btn.find('.woobt-count').text(qty); 945 } else { 946 $btn.append('<span class="woobt-count">' + qty + '</span>'); 947 } 948 } 949 } else { 950 $btn.find('.woobt-count').remove(); 951 } 952 953 jQuery(document.body).trigger('woobt_update_count', [num, qty]); 954} 955 956function woobt_format_money(number, places, symbol, thousand, decimal) { 957 number = number || 0; 958 places = !isNaN(places = Math.abs(places)) ? places : 2; 959 symbol = symbol !== undefined ? symbol : '$'; 960 thousand = thousand !== undefined ? thousand : ','; 961 decimal = decimal !== undefined ? decimal : '.'; 962 963 var negative = number < 0 ? '-' : '', 964 i = parseInt(number = Math.abs(+number || 0).toFixed(places), 10) + '', 965 j = 0; 966 967 if (i.length > 3) { 968 j = i.length % 3; 969 } 970 971 if (woobt_vars.trim_zeros === '1') { 972 return symbol + negative + (j ? i.substr(0, j) + thousand : '') + 973 i.substr(j).replace(/(\d{3})(?=\d)/g, '$1' + thousand) + 974 (places && (parseFloat(number) > parseFloat(i)) ? 975 decimal + Math.abs(number - i). 976 toFixed(places). 977 slice(2). 978 replace(/(\d*?[1-9])0+$/g, '$1') : 979 ''); 980 } else { 981 return symbol + negative + (j ? i.substr(0, j) + thousand : '') + 982 i.substr(j).replace(/(\d{3})(?=\d)/g, '$1' + thousand) + 983 (places ? decimal + Math.abs(number - i).toFixed(places).slice(2) : ''); 984 } 985} 986 987function woobt_format_price(total) { 988 var total_html = '<span class="woocommerce-Price-amount amount">'; 989 var total_formatted = woobt_format_money(total, woobt_vars.price_decimals, '', 990 woobt_vars.price_thousand_separator, woobt_vars.price_decimal_separator); 991 992 switch (woobt_vars.price_format) { 993 case '%1$s%2$s': 994 // left 995 total_html += '<span class="woocommerce-Price-currencySymbol">' + 996 woobt_vars.currency_symbol + '</span>' + total_formatted; 997 break; 998 case '%1$s %2$s': 999 // left with space 1000 total_html += '<span class="woocommerce-Price-currencySymbol">' + 1001 woobt_vars.currency_symbol + '</span> ' + total_formatted; 1002 break; 1003 case '%2$s%1$s': 1004 // right 1005 total_html += total_formatted + 1006 '<span class="woocommerce-Price-currencySymbol">' + 1007 woobt_vars.currency_symbol + '</span>'; 1008 break; 1009 case '%2$s %1$s': 1010 // right with space 1011 total_html += total_formatted + 1012 ' <span class="woocommerce-Price-currencySymbol">' + 1013 woobt_vars.currency_symbol + '</span>'; 1014 break; 1015 default: 1016 // default 1017 total_html += '<span class="woocommerce-Price-currencySymbol">' + 1018 woobt_vars.currency_symbol + '</span> ' + total_formatted; 1019 } 1020 1021 total_html += '</span>'; 1022 1023 return total_html; 1024} 1025 1026function woobt_price_html(regular_price, sale_price) { 1027 var price_html = ''; 1028 1029 if (parseFloat(woobt_round(sale_price)) < 1030 parseFloat(woobt_round(regular_price))) { 1031 price_html = '<del>' + woobt_format_price(regular_price) + '</del> <ins>' + 1032 woobt_format_price(sale_price) + '</ins>'; 1033 } else { 1034 price_html = woobt_format_price(regular_price); 1035 } 1036 1037 return price_html; 1038} 1039 1040function woobt_decimal_places(num) { 1041 var match = ('' + num).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/); 1042 1043 if (!match) { 1044 return 0; 1045 } 1046 1047 return Math.max(0, // Number of digits right of decimal point. 1048 (match[1] ? match[1].length : 0) 1049 // Adjust for scientific notation. 1050 - (match[2] ? +match[2] : 0)); 1051} 1052 1053function woobt_round(value) { 1054 return Number(Math.round(value + 'e' + woobt_vars.price_decimals) + 'e-' + 1055 woobt_vars.price_decimals); 1056}
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.