1'use strict'; 2 3(function($) { 4 var woofc_timeout = null; 5 6 $(function() { 7 // Reload the cart 8 if (woofc_vars.reload == 'yes') { 9 woofc_cart_reload(); 10 } 11 }); 12 13 // Quick view 14 $(document). 15 on('click touch', '#woofc-area .woosq-link, #woofc-area .woosq-btn', 16 function(e) { 17 woofc_hide_cart(); 18 e.preventDefault(); 19 }); 20 21 // Auto show 22 $(document.body). 23 on('added_to_cart', function(e, fragments, cart_hash, $button) { 24 if ($('.woofc-checkout-form').length && 25 !$('.woofc-checkout-form .woocommerce-checkout').length) { 26 var data = { 27 action: 'woofc_get_checkout_form', 28 }; 29 30 $.post(woofc_vars.ajax_url, data, function(response) { 31 $('.woofc-checkout-form').html(response); 32 33 if (woofc_vars.wc_checkout_js !== '') { 34 $.getScript(woofc_vars.wc_checkout_js); 35 } 36 }); 37 } 38 39 if (jQuery('.woofc-checkout-area').length && 40 (woofc_vars.instant_checkout === 'yes')) { 41 jQuery(document.body). 42 trigger('update_checkout', {update_shipping_method: false}); 43 } 44 45 if (woofc_vars.auto_show === 'yes') { 46 setTimeout(function() { 47 if (woofc_vars.instant_checkout_open === 'yes') { 48 woofc_show_cart('checkout'); 49 } else { 50 woofc_show_cart(); 51 } 52 }, 100); 53 } 54 55 if ($button && $button.closest('.woofc-save-for-later').length) { 56 // refresh again 57 $(document.body).trigger('wc_fragment_refresh'); 58 } 59 }); 60 61 $(document.body).on('wc_fragments_loaded', function() { 62 woofc_cart_loaded(); 63 }); 64 65 $(document.body).on('wc_fragments_refreshed', function() { 66 woofc_cart_loaded(); 67 }); 68 69 // Reload cart/checkout 70 $(document.body).on('woofc_cart_reload', function() { 71 if ((woofc_vars.is_cart == '1') && $('form.woocommerce-cart-form').length) { 72 $(document.body).trigger('wc_update_cart'); 73 } 74 75 if ((woofc_vars.is_checkout == '1') && 76 $('form.woocommerce-checkout').length) { 77 jQuery(document.body). 78 trigger('update_checkout', {update_shipping_method: false}); 79 } 80 }); 81 82 // Manual show 83 if (woofc_vars.manual_show != '') { 84 $(document).on('click touch', woofc_vars.manual_show, function(e) { 85 woofc_toggle_cart(); 86 e.preventDefault(); 87 }); 88 } 89 90 // Qty minus & plus 91 $(document). 92 on('click touch', '.woofc-item-qty-plus, .woofc-item-qty-minus', 93 function() { 94 // get values 95 var $qty = $(this).closest('.woofc-item-qty').find('.qty'), 96 val = parseFloat($qty.val()), 97 max = parseFloat($qty.attr('max')), 98 min = parseFloat($qty.attr('min')), step = $qty.attr('step'); 99 100 // format values 101 if (!val || val === '' || val === 'NaN') { 102 val = 0; 103 } 104 105 if (max === '' || max === 'NaN') { 106 max = ''; 107 } 108 109 if (min === '' || min === 'NaN') { 110 min = 0; 111 } 112 113 if (step === 'any' || step === '' || step === undefined || 114 parseFloat(step) === 'NaN') { 115 step = 1; 116 } else { 117 step = parseFloat(step); 118 } 119 120 // change the value 121 if ($(this).is('.woofc-item-qty-plus')) { 122 if (max && (max === val || val > max)) { 123 $qty.val(max); 124 } else { 125 $qty.val((val + step).toFixed(woofc_decimal_places(step))); 126 } 127 } else { 128 if (val - step <= 0) { 129 // remove item 130 if ((woofc_vars.confirm_remove === 'yes')) { 131 if (confirm(woofc_vars.confirm_remove_text)) { 132 woofc_remove_item($qty.closest('.woofc-item')); 133 } 134 } else { 135 woofc_remove_item($qty.closest('.woofc-item')); 136 } 137 138 return false; 139 } 140 141 if (min && (min === val || val < min)) { 142 $qty.val(min); 143 } else if (val > 0) { 144 $qty.val((val - step).toFixed(woofc_decimal_places(step))); 145 } 146 } 147 148 // trigger change event 149 $qty.trigger('change'); 150 }); 151 152 // Qty on change
153 $(document).on('change', '.woofc-area .qty', function() { 154 var item_key = $(this).closest('.woofc-item').attr('data-key'); 155 var item_qty = $(this).val(); 156 157 woofc_update_qty(item_key, item_qty); 158 }); 159 160 // Qty validate 161 $(document).on('keyup', '.woofc-area .qty', function() { 162 var $this = $(this); 163 164 if ($this.closest('.woopq-quantity-input').length) { 165 // checked in WPC Product Quantity 166 return; 167 } 168 169 if (woofc_timeout != null) clearTimeout(woofc_timeout); 170 woofc_timeout = setTimeout(woofc_check_qty, 1000, $this); 171 }); 172 173 // Remove item 174 $(document).on('click touch', '.woofc-area .woofc-item-remove', function() { 175 if (woofc_vars.confirm_remove === 'yes') { 176 if (confirm(woofc_vars.confirm_remove_text)) { 177 woofc_remove_item($(this).closest('.woofc-item')); 178 } 179 } else { 180 woofc_remove_item($(this).closest('.woofc-item')); 181 } 182 }); 183 184 $(document).on('click touch', '.woofc-overlay', function() { 185 woofc_hide_cart(); 186 }); 187 188 $(document).on('click touch', '.woofc-close', function() { 189 woofc_hide_cart(); 190 }); 191 192 $(document).on('click touch', '.woofc-continue-url', function() { 193 var url = $(this).attr('data-url'); 194 195 woofc_hide_cart(); 196 197 if (url !== '') { 198 window.location.href = url; 199 } 200 }); 201 202 $(document).on('click touch', '.woofc-empty-cart', function() { 203 var data = { 204 action: 'woofc_empty_cart', security: woofc_vars.nonce, 205 }; 206 207 if (woofc_vars.confirm_empty === 'yes') { 208 if (confirm(woofc_vars.confirm_empty_text)) { 209 woofc_cart_loading(); 210 211 $.post(woofc_vars.ajax_url, data, function(response) { 212 woofc_cart_reload(); 213 $(document.body).trigger('woofc_cart_emptied'); 214 }); 215 } 216 } else { 217 woofc_cart_loading(); 218 219 $.post(woofc_vars.ajax_url, data, function(response) { 220 woofc_cart_reload(); 221 $(document.body).trigger('woofc_cart_emptied'); 222 }); 223 } 224 }); 225 226 // Count button 227 $(document).on('click touch', '.woofc-count', function(e) { 228 woofc_toggle_cart(); 229 230 e.preventDefault(); 231 }); 232 233 // Menu item 234 $(document).on('click touch', '.woofc-menu-item a', function(e) { 235 if (woofc_vars.cart_url != '') { 236 window.location.href = woofc_vars.cart_url; 237 } else { 238 woofc_toggle_cart(); 239 } 240 241 e.preventDefault(); 242 }); 243 244 // Cart 245 $(document).on('click touch', '.woofc-cart, .woofc-btn', function(e) { 246 woofc_toggle_cart(); 247 248 e.preventDefault(); 249 }); 250 251 // Cart link 252 $(document).on('click touch', '.woofc-cart-link a', function(e) { 253 if (woofc_vars.cart_url != '') { 254 window.location.href = woofc_vars.cart_url; 255 } else { 256 woofc_toggle_cart(); 257 } 258 259 e.preventDefault(); 260 }); 261 262 // Checkout 263 $(document).on('click touch', '.woofc-back', function(e) { 264 e.preventDefault(); 265 266 $('.woofc-checkout-area').addClass('woofc-hide'); 267 $('body').removeClass('woofc-show-checkout'); 268 $('.woofc-cart-area').removeClass('woofc-hide'); 269 270 woofc_slick(); 271 }); 272 273 $(document).on('click touch', '.woofc-action-checkout', function(e) { 274 if ((woofc_vars.instant_checkout === 'yes') && 275 $('.woofc-checkout-area').length) { 276 e.preventDefault(); 277 woofc_show_checkout(); 278 } 279 }); 280 281 $(document).on('click touch', '.woofc-area #place_order', function(e) { 282 setTimeout(function() { 283 $('.woofc-area-mid'). 284 scrollTop($('.woofc-area-mid').scrollTop() + 285 $('.woofc-checkout-form').position().top); 286 }, 1000); 287 }); 288 289 $(document).on('updated_checkout', function(e) { 290 if ($('body').hasClass('woofc-show-checkout')) { 291 $('.woofc-cart-area').addClass('woofc-hide'); 292 $('.woofc-checkout-area').removeClass('woofc-hide'); 293 } 294 295 woofc_slick(); 296 woofc_perfect_scrollbar(); 297 }); 298 299 // Coupon 300 $(document).on('click touch', '.woofc-coupon-check', function() { 301 var coupon_code = $('.woofc-coupon-code').val(); 302 303 if (coupon_code == '') { 304 $('.woofc-coupon-code').focus(); 305 } else { 306 woofc_cart_loading(); 307 308 var data = { 309 action: 'woofc_apply_coupon', 310 coupon_code: coupon_code, 311 security: woofc_vars.nonce, 312 }; 313 314 $.post(woofc_vars.ajax_url, data, function(response) { 315 woofc_cart_reload(); 316 }); 317 } 318 }); 319 320 $(document).on('keypress', '.woofc-coupon-code', function(e) { 321 if (e.keyCode == 13) { 322 var coupon_code = $('.woofc-coupon-code').val(); 323 324 if (coupon_code !== '') { 325 woofc_cart_loading(); 326 327 var data = { 328 action: 'woofc_apply_coupon', 329 coupon_code: coupon_code, 330 security: woofc_vars.nonce, 331 }; 332 333 $.post(woofc_vars.ajax_url, data, function(response) { 334 woofc_cart_reload(); 335 }); 336 } 337 } 338 }); 339 340 $(document).on('click touch', '.woofc-coupon-remove', function() { 341 woofc_cart_loading(); 342 343 var coupon_code = $(this). 344 closest('.woofc-coupon-added'). 345 attr('data-code'); 346 var data = { 347 action: 'woofc_remove_coupon', 348 coupon_code: coupon_code, 349 security: woofc_vars.nonce, 350 }; 351 352 $.post(woofc_vars.ajax_url, data, function(response) { 353 woofc_cart_reload(); 354 });
355 }); 356 357 $(document).on('click touch', '.woofc-undo a', function(e) { 358 e.preventDefault(); 359 woofc_cart_loading(); 360 361 var undo_key = $('body').attr('woofc-undo-key'); 362 var data = { 363 action: 'woofc_undo_remove', 364 item_key: undo_key, 365 security: woofc_vars.nonce, 366 }; 367 368 $.post(woofc_vars.ajax_url, data, function(response) { 369 woofc_cart_reload(); 370 }); 371 372 $('body').attr('woofc-undo-key', ''); 373 $('body').attr('woofc-undo-name', ''); 374 }); 375 376 $(document).on('click touch', '.woofc-shipping', function(e) { 377 $(this).toggleClass('woofc-shipping-open'); 378 $('.woofc-shipping-area').toggleClass('woofc-shipping-area-open'); 379 }); 380 381 $(document).on('change', 'input.woofc-shipping-method', function(e) { 382 e.preventDefault(); 383 e.stopImmediatePropagation(); 384 woofc_cart_loading(); 385 386 var shipping_methods = []; 387 388 $('select.shipping_method, :input[name^=woofc_shipping_method][type=radio]:checked, :input[name^=shipping_method][type=hidden]'). 389 each(function() { 390 shipping_methods[$(this).data('index')] = $(this).val(); 391 }); 392 393 var data = { 394 action: 'woofc_update_shipping_method', 395 shipping_methods: shipping_methods, 396 }; 397 398 $.post(woofc_vars.ajax_url, data, function(response) { 399 woofc_cart_reload(); 400 }); 401 }); 402 403 $(document). 404 on('submit', '.woofc-area form.woocommerce-shipping-calculator', 405 function(e) { 406 e.preventDefault(); 407 e.stopImmediatePropagation(); 408 woofc_cart_loading(); 409 410 var $form = $(this); 411 412 $('<input />'). 413 attr('type', 'hidden'). 414 attr('name', 'calc_shipping'). 415 attr('value', '1'). 416 appendTo($form); 417 418 var formData = $form.serializeArray(); 419 var data = { 420 action: 'woofc_calculate_shipping', 421 }; 422 423 $(formData).each(function(index, obj) { 424 data[obj.name] = obj.value; 425 }); 426 427 $.post(woofc_vars.ajax_url, data, function(response) { 428 woofc_cart_reload(); 429 }); 430 }); 431})(jQuery); 432 433function woofc_decimal_places(num) { 434 var match = ('' + num).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/); 435 436 if (!match) { 437 return 0; 438 } 439 440 return Math.max(0, // Number of digits right of decimal point. 441 (match[1] ? match[1].length : 0) 442 // Adjust for scientific notation. 443 - (match[2] ? +match[2] : 0)); 444} 445 446var isLoadingUpdate = false; 447function woofc_update_qty(cart_item_key, cart_item_qty) { 448 if (isLoadingUpdate) { 449 console.log('Already loading....'); 450 return; 451 } 452 453 isLoadingUpdate = true; 454 455 woofc_cart_loading(); 456 457 var data = { 458 action: 'woofc_update_qty', 459 cart_item_key: cart_item_key, 460 cart_item_qty: cart_item_qty, 461 security: woofc_vars.nonce, 462 }; 463 464 jQuery.post(woofc_vars.wc_ajax_url.replace('%%endpoint%%', 'woofc_update_qty'), data, function(response) { 465 // Nortvi to fix Ajax add to cart and then click + in mini cart 466 // jQuery( document.body ).trigger( 'added_to_cart', [ response.fragments, response.cart_hash, '' ] ); 467 468 woofc_cart_reload(); 469 470 jQuery(document.body). 471 trigger('woofc_update_qty', [cart_item_key, cart_item_qty]); 472 }).always(function() { 473 isLoadingUpdate = false; 474 }); 475} 476 477function woofc_remove_item($item) { 478 var cart_item_key = $item.attr('data-key'); 479 var cart_item_name = $item.attr('data-name'); 480 481 woofc_cart_loading(); 482 483 var data = { 484 action: 'woofc_remove_item', 485 cart_item_key: cart_item_key, 486 security: woofc_vars.nonce, 487 }; 488 489 jQuery.post(woofc_vars.wc_ajax_url.replace('%%endpoint%%', 'woofc_remove_item'), data, function(response) { 490 if (!response || !response.fragments) { 491 return; 492 } 493 494 jQuery(document.body). 495 trigger('removed_from_cart', [response.fragments, response.cart_hash]); 496 497 jQuery('body').attr('woofc-undo-key', cart_item_key); 498 jQuery('body').attr('woofc-undo-name', cart_item_name); 499 500 woofc_cart_reload(false); 501 502 jQuery(document.body). 503 trigger('woofc_remove_item', [cart_item_key, cart_item_name, response]); 504 }); 505} 506 507function woofc_cart_loading() { 508 jQuery('.woofc-inner').addClass('woofc-inner-loading'); 509 jQuery('.woofc-count'). 510 addClass('woofc-count-loading'). 511 removeClass('woofc-count-shake'); 512 513 jQuery(document.body).trigger('woofc_cart_loading'); 514} 515 516function woofc_cart_reload(loadFragments = true) { 517 if (loadFragments) { 518 jQuery(document.body).trigger('wc_fragment_refresh'); 519 } 520 521 jQuery(document.body).trigger('woofc_cart_reload'); 522 523 if (jQuery('.woofc-checkout-area').length && 524 (woofc_vars.instant_checkout === 'yes')) { 525 jQuery(document.body). 526 trigger('update_checkout', {update_shipping_method: false}); 527 } 528} 529 530function woofc_cart_loaded() { 531 jQuery('.woofc-inner').removeClass('woofc-inner-loading'); 532 jQuery('.woofc-count'). 533 removeClass('woofc-count-loading'). 534 addClass('woofc-count-shake'); 535 536 if ((woofc_vars.undo_remove == 'yes') && 537 (jQuery('body').attr('woofc-undo-key') != undefined) && 538 (jQuery('body').attr('woofc-undo-key') != '')) {
539 var undo_name = 'Item'; 540 541 if ((jQuery('body').attr('woofc-undo-name') != undefined) && 542 (jQuery('body').attr('woofc-undo-name') != '')) { 543 undo_name = '"' + jQuery('body').attr('woofc-undo-name') + '"'; 544 } 545 546 jQuery('.woofc-cart-area .woofc-area-mid').find('.woofc-undo').remove(); 547 jQuery('.woofc-cart-area .woofc-area-mid'). 548 prepend('<div class="woofc-undo"><div class="woofc-undo-inner">' + 549 woofc_vars.removed_text.replace('%s', undo_name) + ' <a href="#">' + 550 woofc_vars.undo_remove_text + '</a></div></div>'); 551 } 552 553 woofc_slick(); 554 woofc_perfect_scrollbar(); 555 jQuery(document.body).trigger('woofc_cart_loaded'); 556} 557 558function woofc_perfect_scrollbar() { 559 if (woofc_vars.scrollbar === 'yes') { 560 jQuery('.woofc-area .woofc-area-mid'). 561 perfectScrollbar({suppressScrollX: true, theme: 'wpc'}); 562 } 563} 564 565function woofc_slick() { 566 if (woofc_vars.slick === 'yes') { 567 if (jQuery('.woofc-suggested-product').length > 1) { 568 if (jQuery('.woofc-suggested-products').hasClass('slick-initialized')) { 569 // unslick first 570 jQuery('.woofc-suggested-products').slick('unslick'); 571 } 572 573 // init slick 574 jQuery('.woofc-suggested-products'). 575 slick(JSON.parse(woofc_vars.slick_params)); 576 } 577 578 // save for later 579 if (jQuery('.woofc-save-for-later .woosl-product').length > 1) { 580 if (jQuery('.woofc-save-for-later .woosl-products'). 581 hasClass('slick-initialized')) { 582 // unslick first 583 jQuery('.woofc-save-for-later .woosl-products').slick('unslick'); 584 } 585 586 // init slick 587 jQuery('.woofc-save-for-later .woosl-products'). 588 slick(JSON.parse(woofc_vars.slick_params)); 589 } 590 } 591} 592 593function woofc_show_cart(view = 'cart') { 594 jQuery('body').addClass('woofc-show'); 595 596 if (view === 'checkout') { 597 woofc_show_checkout(); 598 } 599 600 jQuery(document.body).trigger('woofc_show_cart'); 601} 602 603function woofc_hide_cart() { 604 jQuery('body').removeClass('woofc-show woofc-show-checkout'); 605 606 jQuery(document.body).trigger('woofc_hide_cart'); 607} 608 609function woofc_toggle_cart() { 610 if (jQuery('body').hasClass('woofc-show')) { 611 woofc_hide_cart(); 612 } else { 613 woofc_show_cart(); 614 } 615 616 jQuery(document.body).trigger('woofc_toggle_cart'); 617} 618 619function woofc_show_checkout() { 620 jQuery('.woofc-cart-area').addClass('woofc-hide'); 621 jQuery('body').addClass('woofc-show-checkout'); 622 jQuery('.woofc-checkout-area').removeClass('woofc-hide'); 623} 624 625function woofc_check_qty($qty) { 626 var is_remove = false; 627 var val = parseFloat($qty.val()); 628 var min = parseFloat($qty.attr('min')); 629 var max = parseFloat($qty.attr('max')); 630 var step = parseFloat($qty.attr('step')); 631 var fix = Math.pow(10, Number(woofc_decimal_places(step)) + 1); 632 633 if ((val === '') || isNaN(val)) { 634 val = 0; 635 } 636 637 if ((min === '') || isNaN(min)) { 638 min = 0; 639 } 640 641 if ((step === '') || isNaN(step)) { 642 step = 1; 643 } 644 645 var remainder = woofc_float_remainder(val, step); 646 647 if (remainder >= 0) { 648 val = Math.round((val - remainder) * fix) / fix; 649 } 650 651 if (val < min || val <= 0) { 652 is_remove = true; 653 val = min; 654 } 655 656 if (!isNaN(max) && (val > max)) { 657 val = max; 658 } 659 660 $qty.val(val); 661 662 if (is_remove) { 663 if ((woofc_vars.confirm_remove === 'yes')) { 664 if (confirm(woofc_vars.confirm_remove_text)) { 665 woofc_remove_item($qty.closest('.woofc-item')); 666 } 667 } else { 668 woofc_remove_item($qty.closest('.woofc-item')); 669 } 670 } 671} 672 673function woofc_decimal_places(num) { 674 var match = ('' + num).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/); 675 676 if (!match) { 677 return 0; 678 } 679 680 return Math.max(0, // Number of digits right of decimal point. 681 (match[1] ? match[1].length : 0) 682 // Adjust for scientific notation. 683 - (match[2] ? +match[2] : 0)); 684} 685 686function woofc_float_remainder(val, step) { 687 var valDecCount = (val.toString().split('.')[1] || '').length; 688 var stepDecCount = (step.toString().split('.')[1] || '').length; 689 var decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount; 690 var valInt = parseInt(val.toFixed(decCount).replace('.', '')); 691 var stepInt = parseInt(step.toFixed(decCount).replace('.', '')); 692 return (valInt % stepInt) / Math.pow(10, decCount); 693}
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.