https://bloggingify.com/store/wp-content/plugins/checkout-upsell-a…/assets/js/frontend.js?ver=2.2.10
1jQuery(function ($) { 2 3 let cuw_ajax_url = cuw_frontend.ajax_url; 4 let cuw_ajax_nonce = cuw_frontend.ajax_nonce; 5 let cuw_is_cart = (cuw_frontend.is_cart == '1'); 6 let cuw_is_checkout = (cuw_frontend.is_checkout == '1'); 7 let cuw_has_cart_block = (cuw_frontend.has_cart_block == '1'); 8 let cuw_has_checkout_block = (cuw_frontend.has_checkout_block == '1'); 9 let cuw_dynamic_offer_display_enabled = (cuw_frontend.dynamic_offer_display_enabled == '1'); 10 11 var cuw_page_action_performing = false; 12 13 /* Actions */ 14 window.cuw_actions = { 15 // add offer to cart 16 add_offer_to_cart: function (offer) { 17 let offer_id = offer.data('id'); 18 if (!offer_id) { 19 return; 20 } 21 22 $.ajax({ 23 type: 'post', 24 url: cuw_ajax_url, 25 async: true, 26 data: { 27 action: 'cuw_frontend_ajax', 28 method: 'add_offer_to_cart', 29 offer_id: offer_id, 30 quantity: offer.find('[name="quantity"]').val() || 1, 31 variation_id: offer.find('[name="variation_id"]').val() || 0, 32 variation_attributes: offer.find('[name="variation_id"]').data('chosen_attributes') || [], 33 location: offer.closest('.cuw-offers').data('location') || '', 34 nonce: cuw_ajax_nonce || '' 35 }, 36 beforeSend: function () { 37 cuw_spinner.show(offer); 38 offer.find('.cuw-offer :input').prop('disabled', true); 39 }, 40 success: function (response) { 41 if (response.success && response.data) { 42 jQuery(document.body).trigger('cuw_offer_added_to_cart', [response.data, offer]); 43 44 if (response.data.reload_page) { 45 location.reload(true); // to reload page if requires. 46 } 47 48 cuw_actions.update_fragments(); 49 50 if (response.data.cart_item_key) { 51 offer.data('cart_item_key', response.data.cart_item_key); 52 offer.addClass('cuw-offer-added'); 53 offer.find('.cuw-offer-cta-section .cuw-offer-cta-text').hide(); 54 offer.find('.cuw-offer-cta-section .cuw-offer-added-text').show(); 55 offer.find('.cuw-product-quantity, .cuw-product-variants').css('pointer-events', 'none'); 56 offer.find('.cuw-product-quantity, .cuw-product-variants').css('opacity', '0.8'); 57 } else { 58 offer.find('.cuw-checkbox').prop('checked', false); 59 } 60 61 if (response.data.remove_offer) { 62 if (response.data.notice) { 63 $(response.data.notice).insertBefore(offer); 64 } 65 offer.fadeOut(1000, function () { 66 $(this).remove(); 67 }); 68 } else { 69 cuw_spinner.hide(offer); 70 } 71 72 if (response.data.remove_all_offers) { 73 $('.cuw-offer').fadeOut(1000, function () { 74 $(this).remove(); 75 }); 76 } 77 } 78 offer.find('.cuw-offer :input').prop('disabled', false); 79 } 80 }); 81 }, 82 83 remove_offer_from_cart: function (offer) { 84 let key = offer.data('cart_item_key'); 85 if (!key) { 86 return; 87 } 88 89 $.ajax({ 90 type: 'post', 91 url: cuw_ajax_url, 92 async: true, 93 data: { 94 action: 'cuw_frontend_ajax', 95 method: 'remove_item_from_cart', 96 item_key: key, 97 nonce: cuw_ajax_nonce || '' 98 }, 99 beforeSend: function () { 100 cuw_spinner.show(offer); 101 }, 102 success: function (response) { 103 cuw_actions.update_fragments(); 104 if (response.data.item_removed) { 105 offer.removeClass('cuw-offer-added'); 106 offer.find('.cuw-offer-cta-section .cuw-offer-added-text').hide(); 107 offer.find('.cuw-offer-cta-section .cuw-offer-cta-text').show(); 108 offer.find('.cuw-product-quantity, .cuw-product-variants').css('pointer-events', 'all'); 109 offer.find('.cuw-product-quantity, .cuw-product-variants').css('opacity', '1.0'); 110 } 111 cuw_spinner.hide(offer); 112 }, 113 }); 114 }, 115 116 // perform action 117 perform_action: function (action) { 118 let params = action.data(); 119 params.checked = action.find('input[type=checkbox]').is(':checked'); 120 121 $.ajax({ 122 type: 'post', 123 url: cuw_ajax_url, 124 async: true, 125 data: { 126 action: 'cuw_frontend_ajax', 127 method: 'perform_action', 128 params: params, 129 nonce: cuw_ajax_nonce || '' 130 }, 131 beforeSend: function () { 132 cuw_spinner.show(action); 133 $('.cuw-action :input').prop('disabled', true); 134 }, 135 success: function (response) { 136 if (response.success && response.data) { 137 jQuery(document.body).trigger('cuw_action_performed', [response.data, action]); 138 139 if (response.data.reload_page) { 140 location.reload(true); // to reload page if requires. 141 } 142 143 if (response.data.trigger) { 144 jQuery(document.body).trigger(response.data.trigger, {}); 145 } 146 147 cuw_spinner.hide(action); 148 149 if (!response.data.remove) { 150 action.find('input[type=checkbox]').prop('checked', response.data.checked ? true : false); 151 action.data('lock', response.data.lock ? true : false); 152 } else { 153 action.remove(); 154 } 155 } 156 $('.cuw-action :input').prop('disabled', false); 157 } 158 }); 159 }, 160 161 // to perform post-purchase upsells action 162 perform_ppu_action: function (action) { 163 cuw_spinner.show($('#cuw-ppu-offer')); 164 $('#cuw-ppu-offer [name="cuw_ppu_action"]').val(action); 165 $('#cuw-ppu-offer').submit(); 166 }, 167 168 // add chosen products to cart 169 add_products_to_cart: function (section, choose_variants = false) { 170 if (choose_variants) { 171 let chosen_product_ids = []; 172 let chosen_variable_product_ids = []; 173 cuw_products.get_chosen_products(section).forEac
173h(function (product) { 174 chosen_product_ids.push(product.data('id')); 175 if (product.hasClass('is_variable')) { 176 chosen_variable_product_ids.push(product.data('id')); 177 } 178 }); 179 if (chosen_variable_product_ids.length > 0) { 180 let modal = section.find('.cuw-modal').first(); 181 modal.find('.cuw-product-row').each(function (index, row) { 182 if (chosen_product_ids.includes($(row).data('product_id'))) { 183 cuw_products.update_product_row(section, $(row)); 184 $(row).show(); 185 } else { 186 $(row).hide(); 187 } 188 }); 189 cuw_products.update_prices(section); 190 cuw_modal.show(modal); 191 } else { 192 this.add_products_to_cart(section, false); 193 } 194 } else { 195 cuw_spinner.show(section.find(".cuw-buy-section, .cuw-modal-content")); 196 $(document).trigger("cuw_add_to_cart_triggered", [section]); 197 section.find('form').submit(); 198 } 199 }, 200 201 // add product to cart 202 add_product_to_cart: function (section, product) { 203 let page = this.get_page(section); 204 205 $.ajax({ 206 type: 'post', 207 url: cuw_ajax_url, 208 async: true, 209 data: { 210 action: 'cuw_frontend_ajax', 211 method: 'add_product_to_cart', 212 campaign_id: section.data('campaign_id') || 0, 213 product_id: product.data('id') || 0, 214 quantity: product.find('[name="quantity"]').val() || 1, 215 variation_id: product.find('[name="variation_id"]').val() || 0, 216 variation_attributes: product.find('[name="variation_id"]').data('chosen_attributes') || [], 217 page: page, 218 cuw_source_id: section.data('cuw_source_id') || 0, 219 cuw_order_key: section.data('cuw_order_key') || '', 220 nonce: cuw_ajax_nonce || '' 221 }, 222 beforeSend: function () { 223 cuw_spinner.show(product); 224 product.find('.cuw-add-product-to-cart, .cuw-remove-item-from-cart').prop('disabled', true).css('opacity', 0.8); 225 }, 226 success: function (response) { 227 if (response.success && response.data) { 228 if (response.data.item_key && response.data.cart_subtotal) { 229 product.data('key', response.data.item_key); 230 cuw_products.update_inputs(product, false); 231 cuw_products.update_prices(section, response.data); 232 cuw_actions.update_fragments(page); 233 } 234 } 235 cuw_spinner.hide(product); 236 product.find('.cuw-add-product-to-cart, .cuw-remove-item-from-cart').prop('disabled', false).css('opacity', 1); 237 }, 238 }); 239 }, 240 241 // remove item from cart 242 remove_item_from_cart: function (section, product) { 243 let key = product.data('key'); 244 if (!key) { 245 return; 246 } 247 248 let page = this.get_page(section); 249 250 $.ajax({ 251 type: 'post', 252 url: cuw_ajax_url, 253 async: true, 254 data: { 255 action: 'cuw_frontend_ajax', 256 method: 'remove_item_from_cart', 257 item_key: key, 258 page: page, 259 nonce: cuw_ajax_nonce || '' 260 }, 261 beforeSend: function () { 262 cuw_spinner.show(product); 263 product.find('.cuw-add-product-to-cart, .cuw-remove-item-from-cart').prop('disabled', true).css('opacity', 0.8); 264 }, 265 success: function (response) { 266 if (response.success && response.data) { 267 if (response.data.item_removed && response.data.cart_subtotal) { 268 product.data('key', ''); 269 cuw_products.update_inputs(product, true); 270 cuw_products.update_prices(section, response.data); 271 cuw_actions.update_fragments(page); 272 } 273 } 274 cuw_spinner.hide(product); 275 product.find('.cuw-add-product-to-cart, .cuw-remove-item-from-cart').prop('disabled', false).css('opacity', 1); 276 }, 277 }); 278 }, 279 280 // add addon product to cart 281 add_addon_to_cart: function (section, product) { 282 let wrapper = product; 283 if (product.closest('.cart_item').length) { 284 wrapper = product.closest('.cart_item'); 285 } 286 287 $.ajax({ 288 type: 'post', 289 url: cuw_ajax_url, 290 async: true, 291 data: { 292 action: 'cuw_frontend_ajax', 293 method: 'add_addon_to_cart', 294 campaign_id: section.data('campaign_id') || 0, 295 product_id: product.data('id') || 0, 296 quantity: section.data('quantity') || 0, 297 variation_id: product.data('variant_id') || product.val() || 0, 298 main_item_key: section.data('main_item_key') || '', 299 nonce: cuw_ajax_nonce || "" 300 }, 301 beforeSend: function () { 302 cuw_spinner.show(wrapper); 303 }, 304 success: function (response) { 305 if (response.success && response.data && response.data.item_key) { 306 cuw_actions.update_fragments('cart'); 307 } 308 cuw_spinner.hide(wrapper); 309 }, 310 }); 311 }, 312 313 // remove addon item from cart 314 remove_addon_from_cart: function (section, product) { 315 let key = product.data('item_key'); 316 if (!key) { 317 return; 318 } 319 320 let wrapper = product; 321 if (product.closest('.cart_item').length) { 322 wrapper = product.closest('.cart_item'); 323 } 324 325 $.ajax({ 326 type: 'post', 327 url: cuw_ajax_url, 328 async: true, 329 data: { 330 action: 'cuw_frontend_ajax', 331 method: 'remove_addon_from_cart', 332 item_key: key, 333 nonce: cuw_ajax_nonce || "" 334 }, 335 beforeSend: function () { 336 cuw_spinner.show(wrapper); 337 }, 338 success: function (response) { 339 if (response.success && response.data) { 340 cuw_actions.update_fragments('cart'); 341 } 342 cuw_spinner.hide(wrapper); 343 product.data('lock', false); 344 }, 345 }); 346 }, 347 348 // change cart item variant 349 change_cart_item_variant: function (section, variant) { 350 let key = section.data('item_key'); 351 if (!key) { 352 return; 353 } 354 355 let wrapper = variant; 356 if (variant.closest('.cart_item').length > 0) { 357 wrapper = variant.closest('.cart_item'); 358 } 359 360 $.ajax({ 361 type: 'post', 362 url: cuw_ajax_url, 363 async: true, 364 data: { 365 action: 'cuw_frontend_ajax', 366 method: 'change_cart_item_variant', 367 item_key: key, 368 variation_id: variant.val() || 0, 369 nonce: cuw_ajax_nonce || "" 370 }, 371 beforeSend: function () { 372 cuw_spinner.show(wrapper); 373 }, 374 success: function (response) { 375 if (response.success && response.data) { 376 cuw_actions.update_fragments('cart'); 377 } 378 cuw_spinner.hide(wrapper); 379 }, 380 }); 381 }, 382 383 // to get page 384 get_page: function (section = null) { 385 let page = ''; 386 if (section !== null) { 387 page = section.data('page') ? section.data('page') : section.closest('.cuw-modal').data('page'); 388 } 389 return page; 390 }, 391 392 // to update page fragments 393 update_fragments: function (page = '') { 394 if (page === 'cart' || cuw_is_cart) { 395 jQuery(document.body).trigger('wc_update_cart'); 396 jQuery(document.body).trigger('cuw_cart_page_updated'); 397 } else if (page === 'checkout' || cuw_is_checkout) { 398 jQuery(document.body).trigger('update_checkout'); 399 jQuery(document.body).trigger('cuw_checkout_page_updated'); 400 } else { 401 jQuery(document.body).trigger('wc_fragment_refresh'); 402 jQuery(document.body).trigger('cuw_fragment_refreshed'); 403 } 404 405 if (cuw_has_cart_block || cuw_has_checkout_block) { 406 setTimeout(function () { 407 jQuery(document.body).trigger('added_to_cart', {}); 408 }, 0); 409 } 410 }, 411 412 // to get the product details in popup 413 show_product_details_popup: function (section, product_id) { 414 cuw_spinner.show(section); 415 416 $.ajax({ 417 type: 'post', 418 url: cuw_ajax_url, 419 async: false, 420 data: { 421 action: 'cuw_frontend_ajax', 422 method: 'get_product_details_popup', 423 product_id: product_id, 424 nonce: cuw_ajax_nonce || '' 425 }, 426 success: function (response) { 427 if (response.data.html) { 428 $('body').append(response.data.html); 429 cuw_modal.show($('#cuw-modal-product-details-' + product_id), true); 430 $('#cuw-modal-product-details-' + product_id + ' .variant-select').trigger('change'); 431 } 432 cuw_spinner.hide(section); 433 }, 434 }); 435 }, 436 437 // to update the product image 438 update_product_image: function (section, product_id) { 439 cuw_spinner.show(section.find(".cuw-product-image")); 440 441 $.ajax({ 442 type: 'post', 443 url: cuw_ajax_url, 444 async: true, 445 data: { 446 action: 'cuw_frontend_ajax', 447 method: 'get_offer_image', 448 product_id: product_id, 449 nonce: cuw_ajax_nonce || '' 450 }, 451 success: function (response) { 452 cuw_spinner.hide(section.find('.cuw-product-image')); 453 if (response.data.html) { 454 if (section.find('.cuw-product-image a').length > 0) { 455 section.find('.cuw-product-image a').html(response.data.html); 456 } else { 457 section.find('.cuw-product-image').html(response.data.html); 458 } 459 } 460 }, 461 }); 462 }, 463 } 464 465 $(document).on("change", ".cuw-product-addons .cuw-product .cuw-product-checkbox", function () { 466 let addons_count = $('.cuw-product-addons .cuw-product-checkbox:checked').length; 467 $('.cuw-product-addons-pricing-section').css('display', (addons_count > 0 ? 'flex' : 'none')); 468 $(this).closest('.cuw-product').find('.cuw-product-quantity').toggle($(this).prop('checked')); 469 $(this).closest('.cuw-product').find('.cuw-product-variants').toggle($(this).prop('checked')); 470 }); 471 472 $(document).on("click", ".cuw-modal-product-detail", function () { 473 cuw_actions.show_product_details_popup($(this).closest('.cuw-container'), $(this).data('id')); 474 }); 475 476 $(document).on("click", ".cuw-products .cuw-product .cuw-add-product-to-cart", function () { 477 cuw_actions.add_product_to_cart($(this).closest('.cuw-products'), $(this).closest('.cuw-product')); 478 }); 479 480 $(document).on("change", ".cuw-cart-item-variants .variant-select", function () { 481 cuw_actions.change_cart_item_variant($(this).closest('.cuw-cart-item-variants'), $(this).find("option:selected")); 482 }); 483 484 $(document).on("click", ".cuw-products .cuw-product .cuw-remove-item-from-cart", function () { 485 cuw_actions.remove_item_from_cart($(this).closest('.cuw-products'), $(this).closest('.cuw-product')); 486 }); 487 488 $(document).on("click", ".cuw-cart-addon-products .cuw-products .cuw-product input[type=checkbox]", function () { 489 if ($(this).is(":checked")) { 490 cuw_actions.add_addon_to_cart($(this).closest('.cuw-products'), $(this).closest('.cuw-product')); 491 } else { 492 cuw_actions.remove_addon_from_cart($(this).closest('.cuw-products'), $(this).closest('.cuw-product')); 493 } 494 }); 495 496 $(document).on("click", ".cuw-offer input[type=checkbox], .cuw-offer button", function () { 497 let offer = $(this).closest('.cuw-offer'); 498 if (!offer.hasClass('cuw-offer-added')) { 499 cuw_actions.add_offer_to_cart(offer); 500 } else { 501 cuw_actions.remove_offer_from_cart(offer); 502 } 503 }); 504 505 $(document).on("click", ".cuw-action input[type=checkbox], .cuw-action button", function () { 506 cuw_actions.perform_action($(this).closest('.cuw-action')); 507 }); 508 509 $(document).on("click", ".cuw-products .cuw-add-to-cart", function () { 510 cuw_actions.add_products_to_cart($(this).closest(".cuw-products"), $(this).data('choose_variants') == '1'); 511 }); 512 513 $(".cuw-page .cuw-qty").change(function () { 514 $(".cuw-page .cuw-qty").val($(this).val()); 515 $('.cuw-hidden-product-quantity').val($(this).val()); 516 }).trigger('change'); 517 518 $(".cuw-page .variant-select").change(function () { 519 $(".cuw-page .variant-select").val($(this).val()); 520 $('.cuw-hidden-product-variant').val($(this).val()); 521 }).trigger('change'); 522 523 $(".cuw-page-offer-form, .cuw-page-offer-accept").submit(function () { 524 cuw_spinner.show($(this)); 525 cuw_page_action_performing = true; 526 }); 527 528 $(".cuw-offer-decline-link").click(function () { 529 cuw_page_action_performing = true; 530 $(".cuw-offer-decline-link").css({'pointer-events': 'none', 'opacity': '0.8'}); 531 }); 532 533 $("#cuw-ppu-offer .cuw-ppu-ignore-offers").click(function () { 534 cuw_actions.perform_ppu_action('ignore_offers'); 535 }); 536 537 $("#cuw-ppu-offer .cuw-ppu-accept-button").click(function () { 538 cuw_actions.perform_ppu_action('accept_offer'); 539 }); 540 541 $("#cuw-ppu-offer .cuw-ppu-decline-button, #cuw-ppu-offer .cuw-ppu-decline-link").click(function () { 542 cuw_actions.perform_ppu_action('decline_offer'); 543 }); 544 545 jQuery(document.body).on('click', '.cuw-custom-trigger', function () { 546 cuw_spinner.show($(this).closest('.cuw-modal').find('.cuw-modal-body')); 547 $($(this).data('target')).trigger($(this).data('event')); 548 }); 549 550 jQuery(document.body).on('cuw_update_offers', function (event, campaign_type = '') { 551 if ($('.cuw-offers').length === 0 || campaign_type === '') { 552 return; 553 } 554 555 $.ajax({ 556 type: 'post', 557 url: cuw_ajax_url, 558 async: false, 559 data: { 560 action: 'cuw_frontend_ajax', 561 method: 'get_all_offers_html', 562 campaign_type: campaign_type, 563 nonce: cuw_ajax_nonce || '' 564 }, 565 success: function (response) { 566 if (response.data && response.data.html) { 567 $.each(response.data.html, function (location, html) { 568
568 $('.cuw-offers[data-location="' + location + '"]').html(html); 569 }); 570 } 571 }, 572 }); 573 }); 574 575 if (cuw_dynamic_offer_display_enabled) { 576 if (cuw_is_cart || cuw_has_cart_block) { 577 jQuery(document.body).on('applied_coupon removed_coupon', function () { 578 jQuery(document.body).trigger('cuw_update_offers', ['cart_upsells']); 579 }); 580 } else if (cuw_is_checkout || cuw_has_checkout_block) { 581 jQuery(document.body).on('applied_coupon_in_checkout removed_coupon_in_checkout', function () { 582 jQuery(document.body).trigger('cuw_update_offers', ['checkout_upsells']); 583 }); 584 } 585 } 586 587 jQuery(document.body).on('cuw_show_upsell_popup', function (event, data, element) { 588 if (data.dynamic_content) { 589 $.ajax({ 590 type: 'post', 591 url: cuw_ajax_url, 592 data: { 593 action: 'cuw_frontend_ajax', 594 method: 'get_upsell_popup', 595 campaign_id: data.campaign_id, 596 product_id: data.product_id, 597 trigger: data.trigger, 598 page: data.page, 599 nonce: cuw_ajax_nonce || '' 600 }, 601 success: function (response) { 602 if (response.success && response.data && response.data.campaign_id && response.data.html) { 603 let campaign_id = response.data.campaign_id; 604 if ($('#cuw-modal-' + campaign_id).length > 0) { 605 $('#cuw-modal-' + campaign_id).find('.cuw-cart-subtotal').html(response.data.cart_subtotal); 606 } else { 607 $('body').append(response.data.html); 608 } 609 610 cuw_modal.show($('#cuw-modal-' + campaign_id), true); 611 612 // to add scroll action event listener 613 if (cuw_products && cuw_products.carousel_update_actions) { 614 $('#cuw-modal-' + campaign_id + ' .cuw-carousel .cuw-carousel-slider').on('scroll', function () { 615 cuw_products.carousel_update_actions($(this).closest(".cuw-carousel")); 616 }); 617 } 618 } 619 }, 620 }); 621 } else if (data.campaign_id) { 622 let modal = $('#cuw-modal-' + data.campaign_id); 623 if (modal.length > 0) { 624 modal.data('shown', true); 625 cuw_modal.show(modal); 626 } 627 } 628 }); 629 630 jQuery(document.body).on('checkout_error', function () { 631 cuw_modal.hide('.cuw-modal'); 632 }); 633 634 let messages = $(".cuw-page-timer"); 635 if (messages.length > 0) { 636 let element = messages.first(); 637 let message = element.data('message'); 638 let params = new URLSearchParams(window.location.search); 639 let unique_id = params.get('cuw_order_id'); 640 if (params.get('cuw_ppu_offer')) { 641 unique_id = params.get('cuw_ppu_offer') + '_' + (params.get('cuw_order') || ''); 642 } 643 if (!unique_id) { 644 return; 645 } 646 let duration = (element.data('minutes') * 60) + element.data('seconds'), minutes, seconds; 647 if (Cookies && unique_id) { 648 let duration_from_cookie = Cookies.get("cuw_timer_" + unique_id); 649 if (duration_from_cookie !== undefined) { 650 duration = duration_from_cookie; 651 } 652 } 653 setInterval(function () { 654 if (duration >= 0) { 655 minutes = parseInt(duration / 60, 10); 656 seconds = parseInt(duration % 60, 10); 657 minutes = minutes < 10 ? "0" + minutes : minutes; 658 seconds = seconds < 10 ? "0" + seconds : seconds; 659 messages.html(message.replace('{minutes}', minutes).replace('{seconds}', seconds)); 660 if (duration === 0) { 661 if (params.get('cuw_ppu_offer')) { 662 cuw_actions.perform_ppu_action('decline_offer'); 663 } else if (!cuw_page_action_performing) { 664 window.location = element.data('redirect'); 665 } 666 } 667 if (Cookies && unique_id) { 668 Cookies.set("cuw_timer_" + unique_id, duration); 669 } 670 duration--; 671 } 672 }, 1000); 673 } 674 675});
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.