1'use strict'; 2 3(function($) { 4 var woosb_timeout = null; 5 6 $(function() { 7 if ($('.woosb-wrap').length) { 8 $('.woosb-wrap').each(function() { 9 woosb_init($(this), 'ready'); 10 }); 11 } 12 }); 13 14 $(document).on('woosq_loaded', function() { 15 // product bundles in quick view popup 16 woosb_init($('#woosq-popup .woosb-wrap'), 'woosq'); 17 }); 18 19 $(document).on('woovr_selected', function(e, selected, variations) { 20 var $wrap = variations.closest('.woosb-wrap'); 21 var $product = variations.closest('.woosb-product'); 22 23 if ($product.length) { 24 var _id = selected.attr('data-id'); 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 var _availability = selected.attr('data-availability'); 32 33 if (_purchasable === 'yes' && _id >= 0) { 34 // change data 35 $product.attr('data-id', _id); 36 $product.attr('data-price', _price); 37 38 // change price 39 woosb_change_price($product, _price, _regular_price, _price_html); 40 41 // change attributes 42 $product.attr('data-attrs', _attrs.replace(/\/$/, '')); 43 } else { 44 // reset data 45 $product.attr('data-id', 0); 46 $product.attr('data-price', $product.data('o_price')); 47 $product.attr('data-attrs', ''); 48 49 // reset price 50 $product.find('.woosb-price-ori').show(); 51 $product.find('.woosb-price-new').html('').hide(); 52 } 53 54 // change image 55 if (_image_src && _image_src !== '') { 56 $product.find('.woosb-thumb-ori').hide(); 57 $product.find('.woosb-thumb-new'). 58 html('<img src="' + _image_src + '"/>'). 59 show(); 60 } else { 61 $product.find('.woosb-thumb-ori').show(); 62 $product.find('.woosb-thumb-new').html('').hide(); 63 } 64 65 // change availability 66 if (_availability && _availability !== '') { 67 $product.find('.woosb-availability').html(_availability).show(); 68 } else { 69 $product.find('.woosb-availability').html('').hide(); 70 } 71 72 // reset sku, weight & dimensions 73 if (typeof wc_reset_content === 'function') { 74 $('.product_meta .sku').wc_reset_content(); 75 $('.product_weight, .woocommerce-product-attributes-item--weight .woocommerce-product-attributes-item__value'). 76 wc_reset_content(); 77 $('.product_dimensions, .woocommerce-product-attributes-item--dimensions .woocommerce-product-attributes-item__value'). 78 wc_reset_content(); 79 } 80 } 81 82 woosb_init($wrap, 'woovr_selected'); 83 }); 84 85 $(document).on('found_variation', function(e, t) { 86 var $wrap = $(e['target']).closest('.woosb-wrap'); 87 var $product = $(e['target']).closest('.woosb-product'); 88 89 if ($product.length) { 90 if (t['woosb_image'] !== undefined && t['woosb_image'] !== '') { 91 // change image 92 $product.find('.woosb-thumb-ori').hide(); 93 $product.find('.woosb-thumb-new').html(t['woosb_image']).show(); 94 } else { 95 $product.find('.woosb-thumb-ori').show(); 96 $product.find('.woosb-thumb-new').html('').hide(); 97 } 98 99 if (t['price_html'] !== undefined && t['price_html'] !== '' && 100 t['display_price'] !== undefined && t['display_price'] !== '') { 101 woosb_change_price($product, t['display_price'], 102 t['display_regular_price'], t['price_html']); 103 } 104 105 if (t['variation_description'] !== undefined) { 106 $product.find('.woosb-variation-description'). 107 html(t['variation_description']). 108 show(); 109 } else { 110 $product.find('.woosb-variation-description').html('').hide(); 111 } 112 113 if (t['is_purchasable']) { 114 // change the price 115 if (woosb_vars.bundled_price_from === 'regular_price' && 116 t['display_regular_price'] !== undefined) { 117 $product.attr('data-price', t['display_regular_price']); 118 } else { 119 $product.attr('data-price', t['display_price']); 120 } 121 122 // change stock notice 123 if (t['is_in_stock']) { 124 $wrap.next('p.stock').show(); 125 $product.attr('data-id', t['variation_id']); 126 } else { 127 $wrap.next('p.stock').hide(); 128 $product.attr('data-id', 0); 129 } 130 131 // change availability 132 if (t['availability_html'] && t['availability_html'] !== '') { 133 $product.find('.woosb-availability'). 134 html(t['availability_html']). 135 show(); 136 } else { 137 $product.find('.woosb-availability').html('').hide(); 138 } 139 140 // change attributes 141 var attrs = {}; 142 143 $product.find('select[name^="attribute_"]').each(function() { 144 var attr_name = $(this).attr('name'); 145 146 attrs[attr_name] = $(this).val(); 147 }); 148 149 $product.attr('data-attrs', JSON.stringify(attrs)); 150 } 151 152 if (woosb_vars.change_image === 'no') { 153 // prevent changing the main image 154 $(e['target']).closest('.variations_form').trigger('reset_image'); 155 } 156 157 // reset sku, weight & dimensions 158 if (typeof wc_reset_content === 'function') { 159 $('.product_meta .sku').wc_reset_content(); 160 $('.product_weight, .woocommerce-product-attributes-item--weight .woocommerce-product-attributes-item__value'). 161 wc_reset_content(); 162 $('.product_dimensions, .woocommerce-product-attributes-item--dimensions .woocommerce-product-attributes-item__value'). 163 wc_reset_content(); 164 } 165 166 $(document).trigger('woosb_found_variation', [$product, t]); 167 168 woosb_init($wrap, 'found_variation'); 169 } 170 }); 171 172 $(document).on('reset_data', function(e) { 173 var $wrap = $(e['target']).closest('.woosb-wrap'); 174 var $product = $(e['target']).closest('.woosb-product'); 175 176 if ($product.length) { 177 // reset thumb 178 $product.find('.woosb-thumb-new').hide(); 179 $product.find('.woosb-thumb-ori').show(); 180 181 // reset price 182 $product.find('.woosb-price-new').hide(); 183 $product.find('.woosb-price-ori').show(); 184 185 // reset availability 186 $product.find('.woosb-availability').html('').hide(); 187 188 // reset desc 189 $product.find('.woosb-variation-description').html('').hide(); 190 191 // reset data 192 $product.attr('data-id', 0); 193 $product.attr('data-price', $product.data('o_price')); 194 $product.attr('data-attrs', ''); 195 196 $(document).trigger('woosb_reset_data', [$product]); 197 198 woosb_init($wrap, 'reset_data'); 199 } 200 }); 201 202 $(document). 203 on('click touch', 204 '.woosb-quantity-input-plus, .woosb-quantity-input-minus', 205 function() { 206 // get values 207 var $qty = $(this).closest('.woosb-quantity').find('.woosb-qty'); 208 209 if (!$qty.length) { 210 $qty = $(this).closest('.woosb-quantity').find('.qty'); 211 } 212 213 var val = parseFloat($qty.val()), 214 max = parseFloat($qty.attr('max')), 215 min = parseFloat($qty.attr('min')), step = $qty.attr('step'); 216 217 // format values 218 if (!val || val === '' || val === 'NaN') { 219 val = 0; 220 } 221 222 if (max === '' || max === 'NaN') { 223 max = ''; 224 } 225 226 if (min === '' || min === 'NaN') { 227 min = 0; 228 } 229 230 if (step === 'any' || step === '' || step === undefined || 231 parseFloat(step) === 'NaN') { 232 step = 1; 233 } else { 234 step = parseFloat(step); 235 } 236 237 // change the value 238 if ($(this).is('.woosb-quantity-input-plus')) { 239 if (max && (max == val || val > max)) { 240 $qty.val(max); 241 } else { 242 $qty.val((val + step).toFixed(woosb_decimal_places(step))); 243 } 244 } else { 245 if (min && (min == val || val < min)) { 246 $qty.val(min); 247 } else if (val > 0) { 248 $qty.val((val - step).toFixed(woosb_decimal_places(step))); 249 } 250 } 251 252 // trigger change event 253 $qty.trigger('change'); 254 }); 255 256 $(document).on('click touch', '.single_add_to_cart_button', function(e) { 257 var $this = $(this); 258 259 if ($this.hasClass('woosb-disabled')) { 260 e.preventDefault(); 261 } 262 }); 263 264 if ($('.woosb-qty').length) {
265 $(document).on('change', '.woosb-qty', function() { 266 var $this = $(this); 267 268 woosb_check_qty($this); 269 }); 270 271 $(document).on('keyup', '.woosb-qty', function() { 272 var $this = $(this); 273 274 if (woosb_timeout != null) clearTimeout(woosb_timeout); 275 woosb_timeout = setTimeout(woosb_check_qty, 1000, $this); 276 }); 277 } else { 278 $(document).on('change', '.woosb-quantity .qty', function() { 279 var $this = $(this); 280 281 woosb_check_qty($this); 282 }); 283 284 $(document).on('keyup', '.woosb-quantity .qty', function() { 285 var $this = $(this); 286 287 if (woosb_timeout != null) clearTimeout(woosb_timeout); 288 woosb_timeout = setTimeout(woosb_check_qty, 1000, $this); 289 }); 290 } 291})(jQuery); 292 293function woosb_init($wrap, context = null) { 294 woosb_check_ready($wrap, context); 295 woosb_save_ids($wrap, context); 296 297 jQuery(document).trigger('woosb_init', [$wrap, context]); 298} 299 300function woosb_check_ready($wrap) { 301 var qty = 0; 302 var total = 0; 303 var total_sale = 0; 304 var is_selection = false; 305 var selection_name = ''; 306 var is_unpurchasable = false; 307 var unpurchasable_name = ''; 308 var is_empty = true; 309 var is_min = false; 310 var is_max = false; 311 var is_total_min = false; 312 var is_total_max = false; 313 var wid = $wrap.attr('data-id'); 314 var $products = $wrap.find('.woosb-products'); 315 var $alert = $wrap.find('.woosb-alert'); 316 var $ids = jQuery('.woosb-ids-' + wid); 317 var $btn = $ids.closest('form.cart').find('.single_add_to_cart_button'); 318 var price_suffix = $products.attr('data-price-suffix'); 319 var $total = $wrap.find('.woosb-total'); 320 var $count = $wrap.find('.woosb-count'); 321 var $price = jQuery('.woosb-price-' + wid); 322 var $woobt = jQuery('.woobt-wrap-' + wid); 323 var total_woobt = parseFloat($woobt.length ? $woobt.attr('data-total') : 0); 324 var discount = parseFloat($products.attr('data-discount')); 325 var discount_amount = parseFloat($products.attr('data-discount-amount')); 326 var fixed_price = $products.attr('data-fixed-price') === 'yes'; 327 var has_optional = $products.attr('data-optional') === 'yes'; 328 var has_variables = $products.attr('data-variables') === 'yes'; 329 var exclude_unpurchasable = $products.attr('data-exclude-unpurchasable') === 330 'yes'; 331 var saved = ''; 332 var is_discount = discount > 0 && discount < 100; 333 var is_discount_amount = discount_amount > 0; 334 var qty_min = parseFloat($products.attr('data-min')); 335 var qty_max = parseFloat($products.attr('data-max')); 336 var total_min = parseFloat($products.attr('data-total-min')); 337 var total_max = parseFloat($products.attr('data-total-max')); 338 var fix = Math.pow(10, Number(woosb_vars.price_decimals) + 1); 339 340 if (!$products.length || (!has_variables && !has_optional)) { 341 // don't need to do anything - already calculated in PHP 342 return; 343 } 344 345 // calculate price 346 347 if (!fixed_price) { 348 $products.find('.woosb-product').each(function() { 349 var $this = jQuery(this); 350 351 if ($this.hasClass('woosb-product-unpurchasable') && 352 exclude_unpurchasable) { 353 // don't count this product 354 return; 355 } 356 357 if (parseFloat($this.attr('data-price')) > 0) { 358 var _qty = parseFloat($this.attr('data-qty')); 359 var _price = parseFloat($this.attr('data-price')); 360 361 total += woosb_round(_price, woosb_vars.price_decimals) * _qty; 362 363 if (!is_discount_amount && is_discount) { 364 _price *= (100 - discount) / 100; 365 } 366 367 _price = Math.round(_price * fix) / fix; 368 total_sale += woosb_round(_price, woosb_vars.price_decimals) * _qty; 369 } 370 }); 371 372 if (is_discount_amount && discount_amount < total) { 373 total_sale = total - discount_amount; 374 saved = woosb_format_price(discount_amount); 375 } else if (is_discount) { 376 saved = woosb_round(discount, 2) + '%'; 377 } else { 378 total_sale = total; 379 } 380 381 var total_html = woosb_price_html(total, total_sale); 382 var total_all_html = woosb_price_html(total + total_woobt, 383 total_sale + total_woobt); 384 385 if (saved !== '') { 386 total_html += ' <small class="woocommerce-price-suffix">' + 387 woosb_vars.saved_text.replace('[d]', saved) + '</small>'; 388 } 389 390 // change the bundle total 391 $total.html('<span class="woosb-total-label">' + woosb_vars.price_text + 392 '</span> <span class="woosb-total-value">' + total_html + price_suffix + 393 '</span>'). 394 slideDown(); 395 jQuery(document). 396 trigger('woosb_change_total', [$total, total_html, price_suffix]); 397 398 if (woosb_vars.change_price !== 'no') { 399 // change the main price 400 401 if (woosb_vars.change_price === 'yes_custom' && 402 woosb_vars.price_selector != null && woosb_vars.price_selector !== 403 '') { 404 $price = jQuery(woosb_vars.price_selector); 405 } 406 407 if ($woobt.length) { 408 // woobt
409 $price.html(total_all_html + price_suffix); 410 } else { 411 if (typeof $price.attr('data-o_price') === 'undefined') { 412 $price.attr('data-o_price', woosb_encode_entities($price.html())); 413 } 414 415 $price.html(total_html + price_suffix); 416 } 417 } 418 419 if ($woobt.length) { 420 // woobt 421 $woobt.find('.woobt-products'). 422 attr('data-product-price-html', total_html); 423 $woobt.find('.woobt-product-this'). 424 attr('data-price', total_sale). 425 attr('data-regular-price', total); 426 427 woobt_init($woobt); 428 } 429 430 jQuery(document). 431 trigger('woosb_calc_price', 432 [total_sale, total, total_html, price_suffix, $wrap]); 433 } 434 435 // check ready 436 437 $products.find('.woosb-product').each(function() { 438 var $this = jQuery(this); 439 440 if (parseFloat($this.attr('data-qty')) > 0) { 441 is_empty = false; 442 qty += parseFloat($this.attr('data-qty')); 443 444 if (parseInt($this.attr('data-id')) === 0) { 445 is_selection = true; 446 447 if (selection_name === '') { 448 selection_name = $this.attr('data-name'); 449 } 450 } 451 452 if ($this.hasClass('woosb-product-optional') && 453 $this.hasClass('woosb-product-unpurchasable')) { 454 is_unpurchasable = true; 455 456 if (unpurchasable_name === '') { 457 unpurchasable_name = $this.attr('data-name'); 458 } 459 } 460 } 461 }); 462 463 if (has_optional) { 464 // check min 465 if (qty_min > 0 && qty < qty_min) { 466 is_min = true; 467 } 468 469 // check max 470 if (qty_max > 0 && qty > qty_max) { 471 is_max = true; 472 } 473 474 $count.html('<span class="woosb-count-label">' + woosb_vars.selected_text + 475 '</span> <span class="woosb-count-value">' + qty + '</span>'). 476 slideDown(); 477 jQuery(document). 478 trigger('woosb_change_count', [$count, qty, qty_min, qty_max]); 479 } 480 481 if (!fixed_price) { 482 // check total min 483 if (total_min > 0 && total_sale < total_min) { 484 is_total_min = true; 485 } 486 487 // check total max 488 if (total_max > 0 && total_sale > total_max) { 489 is_total_max = true; 490 } 491 } 492 493 if (is_selection || is_unpurchasable || is_empty || is_min || is_max || 494 is_total_min || is_total_max) { 495 $btn.addClass('woosb-disabled'); 496 497 if (is_selection) { 498 $alert.html(woosb_vars.alert_selection.replace('[name]', 499 '<strong>' + selection_name + '</strong>')).slideDown(); 500 } else if (is_unpurchasable) { 501 $alert.html(woosb_vars.alert_unpurchasable.replace('[name]', 502 '<strong>' + unpurchasable_name + '</strong>')).slideDown(); 503 } else if (is_empty) { 504 $alert.html(woosb_vars.alert_empty).slideDown(); 505 } else if (is_min) { 506 $alert.html(woosb_vars.alert_min.replace('[min]', qty_min). 507 replace('[selected]', qty)).slideDown(); 508 } else if (is_max) { 509 $alert.html(woosb_vars.alert_max.replace('[max]', qty_max). 510 replace('[selected]', qty)).slideDown(); 511 } else if (is_total_min) { 512 $alert.html(woosb_vars.alert_total_min.replace('[min]', 513 woosb_format_price(total_min)). 514 replace('[total]', woosb_format_price(total_sale))).slideDown(); 515 } else if (is_total_max) { 516 $alert.html(woosb_vars.alert_total_max.replace('[max]', 517 woosb_format_price(total_max)). 518 replace('[total]', woosb_format_price(total_sale))).slideDown(); 519 } 520 521 jQuery(document).trigger('woosb_check_ready', [ 522 false, 523 is_selection, 524 is_unpurchasable, 525 is_empty, 526 is_min, 527 is_max, 528 is_total_min, 529 is_total_max, 530 $wrap]); 531 } else { 532 $alert.html('').slideUp(); 533 $btn.removeClass('woosb-disabled'); 534 535 // ready 536 jQuery(document).trigger('woosb_check_ready', [ 537 true, 538 is_selection, 539 is_unpurchasable, 540 is_empty, 541 is_min, 542 is_max, 543 is_total_min, 544 is_total_max, 545 $wrap]); 546 } 547} 548 549function woosb_save_ids($wrap) { 550 var ids = Array(); 551 var wid = $wrap.attr('data-id'); 552 var $ids = jQuery('.woosb-ids-' + wid); 553 var $products = $wrap.find('.woosb-products'); 554 555 $products.find('.woosb-product').each(function() { 556 var $this = jQuery(this); 557 var id = parseInt($this.attr('data-id')); 558 var key = $this.attr('data-key'); 559 var qty = parseFloat($this.attr('data-qty')); 560 var attrs = $this.attr('data-attrs'); 561 562 if (id > 0 && qty > 0) { 563 if (attrs !== undefined) { 564 attrs = encodeURIComponent(attrs); 565 } else { 566 attrs = ''; 567 } 568 569 ids.push(id + '/' + key + '/' + qty + '/' + attrs); 570 } 571 }); 572 573 $ids.val(ids.join(',')); 574 575 jQuery(document).trigger('woosb_save_ids', [ids, $wrap]); 576} 577 578function woosb_check_qty($qty) { 579 var $wrap = $qty.closest('.woosb-wrap'); 580 var qty = parseFloat($qty.val()); 581 var min = parseFloat($qty.attr('min')); 582 var max = parseFloat($qty.attr('max')); 583 584 if (qty === '' || isNaN(qty)) { 585 qty = 0; 586 } 587 588 if (!isNaN(min) && qty < min) { 589 qty = min; 590 } 591 592 if (!isNaN(max) && qty > max) { 593 qty = max; 594 } 595 596 $qty.val(qty); 597 $qty.closest('.woosb-product').attr('data-qty', qty); 598 599 // change subtotal 600 if (woosb_vars.bundled_price === 'subtotal' || woosb_vars.bundled_price === 601 'subtotal_under_name') { 602 var $products = $wrap.find('.woosb-products'); 603 var $product = $qty.closest('.woosb-product'); 604 var price_suffix = $product.attr('data-price-suffix'); 605 var ori_price = parseFloat($product.attr('data-price')); 606 var qty = parseFloat($product.attr('data-qty')); 607 608 $product.find('.woosb-price-ori').hide(); 609 610 if (parseFloat($products.attr('data-discount')) > 0 && 611 $products.attr('data-fixed-price') === 'no') { 612 var new_price = woosb_round( 613 (ori_price * (100 - parseFloat($products.attr('data-discount')))) / 614 100, woosb_vars.price_decimals); 615 616 $product.find('.woosb-price-new'). 617 html(woosb_price_html(ori_price * qty, new_price * qty) +
618 price_suffix). 619 show(); 620 } else { 621 $product.find('.woosb-price-new'). 622 html(woosb_price_html(ori_price * qty) + price_suffix). 623 show(); 624 } 625 } 626 627 jQuery(document).trigger('woosb_check_qty', [qty, $qty]); 628 629 woosb_init($wrap, 'woosb_check_qty'); 630} 631 632function woosb_change_price($product, price, regular_price, price_html) { 633 var $products = $product.closest('.woosb-products'); 634 var price_suffix = $product.attr('data-price-suffix'); 635 var qty = parseFloat($product.attr('data-qty')); 636 var new_price_html = ''; 637 638 // hide ori price 639 $product.find('.woosb-price-ori').hide(); 640 641 // calculate new price 642 if (woosb_vars.bundled_price === 'subtotal' || woosb_vars.bundled_price === 643 'subtotal_under_name') { 644 var ori_price = parseFloat(price); 645 646 if (woosb_vars.bundled_price_from === 'regular_price' && regular_price !== 647 undefined) { 648 ori_price = parseFloat(regular_price); 649 } 650 651 var new_price = ori_price; 652 653 if (parseFloat($products.attr('data-discount')) > 0) { 654 new_price = woosb_round( 655 (ori_price * (100 - parseFloat($products.attr('data-discount')))) / 656 100, woosb_vars.price_decimals); 657 } 658 659 new_price_html = woosb_price_html(ori_price * qty, new_price * qty) + 660 price_suffix; 661 } else { 662 if (parseFloat($products.attr('data-discount')) > 0) { 663 var ori_price = parseFloat(price); 664 665 if (woosb_vars.bundled_price_from === 'regular_price' && regular_price !== 666 undefined) { 667 ori_price = parseFloat(regular_price); 668 } 669 670 var new_price = woosb_round( 671 (ori_price * (100 - parseFloat($products.attr('data-discount')))) / 672 100, woosb_vars.price_decimals); 673 674 new_price_html = woosb_price_html(ori_price, new_price) + price_suffix; 675 } else { 676 if (woosb_vars.bundled_price_from === 'regular_price' && regular_price !== 677 undefined) { 678 new_price_html = woosb_price_html(regular_price) + price_suffix; 679 } else if (price_html !== '') { 680 new_price_html = price_html; 681 } 682 } 683 } 684 685 $product.find('.woosb-price-new').html(new_price_html).show(); 686 jQuery(document).trigger('woosb_change_price', [$product, new_price_html]); 687} 688 689function woosb_round(value, decimals) { 690 return Number(Math.round(value + 'e' + decimals) + 'e-' + decimals); 691} 692 693function woosb_format_money(number, places, symbol, thousand, decimal) { 694 number = number || 0; 695 places = !isNaN(places = Math.abs(places)) ? places : 2; 696 symbol = symbol !== undefined ? symbol : '$'; 697 thousand = thousand !== undefined ? thousand : ','; 698 decimal = decimal !== undefined ? decimal : '.'; 699 700 var negative = number < 0 ? '-' : '', 701 i = parseInt(number = Math.abs(+number || 0).toFixed(places), 10) + '', 702 j = 0; 703 704 if (i.length > 3) { 705 j = i.length % 3; 706 } 707 708 if (woosb_vars.trim_zeros === '1') { 709 return symbol + negative + (j ? i.substr(0, j) + thousand : '') + 710 i.substr(j).replace(/(\d{3})(?=\d)/g, '$1' + thousand) + 711 (places && (parseFloat(number) > parseFloat(i)) ? decimal + 712 Math.abs(number - i). 713 toFixed(places). 714 slice(2). 715 replace(/(\d*?[1-9])0+$/g, '$1') : ''); 716 } else { 717 return symbol + negative + (j ? i.substr(0, j) + thousand : '') + 718 i.substr(j).replace(/(\d{3})(?=\d)/g, '$1' + thousand) + 719 (places ? decimal + Math.abs(number - i).toFixed(places).slice(2) : ''); 720 } 721} 722 723function woosb_format_price(price) { 724 var price_html = '<span class="woocommerce-Price-amount amount">'; 725 var price_formatted = woosb_format_money(price, woosb_vars.wc_price_decimals, 726 '', woosb_vars.wc_price_thousand_separator, 727 woosb_vars.wc_price_decimal_separator); 728 729 switch (woosb_vars.wc_price_format) { 730 case '%1$s%2$s': 731 //left 732 price_html += '<span class="woocommerce-Price-currencySymbol">' + 733 woosb_vars.wc_currency_symbol + '</span>' + price_formatted; 734 break; 735 case '%1$s %2$s': 736 //left with space 737 price_html += '<span class="woocommerce-Price-currencySymbol">' + 738 woosb_vars.wc_currency_symbol + '</span> ' + price_formatted; 739 break; 740 case '%2$s%1$s': 741 //right 742 price_html += price_formatted + 743 '<span class="woocommerce-Price-currencySymbol">' + 744 woosb_vars.wc_currency_symbol + '</span>'; 745 break; 746 case '%2$s %1$s': 747 //right with space 748 price_html += price_formatted + 749 ' <span class="woocommerce-Price-currencySymbol">' + 750 woosb_vars.wc_currency_symbol + '</span>'; 751 break; 752 default: 753 //default 754 price_html += '<span class="woocommerce-Price-currencySymbol">' + 755 woosb_vars.wc_currency_symbol + '</span> ' + price_formatted; 756 } 757 758 price_html += '</span>'; 759 760 return price_html; 761} 762 763function woosb_price_html(regular_price, sale_price) { 764 var price_html = ''; 765 766 if (parseFloat(woosb_round(sale_price, woosb_vars.wc_price_decimals)) < 767 parseFloat(woosb_round(regular_price, woosb_vars.wc_price_decimals))) { 768 price_html = '<del>' + woosb_format_price(regular_price) + '</del> <ins>' + 769 woosb_format_price(sale_price) + '</ins>'; 770 } else { 771 price_html = woosb_format_price(regular_price); 772 } 773 774 return price_html; 775} 776 777function woosb_decimal_places(num) { 778 var match = ('' + num).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/); 779 780 if (!match) { 781 return 0; 782 } 783 784 return Math.max(0, // Number of digits right of decimal point. 785 (match[1] ? match[1].length : 0) - // Adjust for scientific notation. 786 (match[2] ? +match[2] : 0)); 787} 788 789function woosb_encode_entities(str) { 790 return String(str). 791 replace(/&/g, '&'). 792 replace(/</g, '<'). 793 replace(/>/g, '>'). 794 replace(/"/g, '"'); 795} 796 797function woosb_decode_entities(str) { 798 var textArea = document.createElement('textarea'); 799 textArea.innerHTML = str; 800 return textArea.value; 801}
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.