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