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 nonce: cuw_ajax_nonce || '' 219 }, 220 beforeSend: function () { 221 cuw_spinner.show(product); 222 product.find('.cuw-add-product-to-cart, .cuw-remove-item-from-cart').prop('disabled', true).css('opacity', 0.8); 223 }, 224 success: function (response) { 225 if (response.success && response.data) { 226 if (response.data.item_key && response.data.cart_subtotal) { 227 product.data('key', response.data.item_key); 228 cuw_products.update_inputs(product, false); 229 cuw_products.update_prices(section, response.data); 230 cuw_actions.update_fragments(page); 231 } 232 } 233 cuw_spinner.hide(product); 234 product.find('.cuw-add-product-to-cart, .cuw-remove-item-from-cart').prop('disabled', false).css('opacity', 1); 235 }, 236 }); 237 }, 238 239 // remove item from cart 240 remove_item_from_cart: function (section, product) { 241 let key = product.data('key'); 242 if (!key) { 243 return; 244 } 245 246 let page = this.get_page(section); 247 248 $.ajax({ 249 type: 'post', 250 url: cuw_ajax_url, 251 async: true, 252 data: { 253 action: 'cuw_frontend_ajax', 254 method: 'remove_item_from_cart', 255 item_key: key, 256 page: page, 257 nonce: cuw_ajax_nonce || '' 258 }, 259 beforeSend: function () { 260 cuw_spinner.show(product); 261 product.find('.cuw-add-product-to-cart, .cuw-remove-item-from-cart').prop('disabled', true).css('opacity', 0.8); 262 }, 263 success: function (response) { 264 if (response.success && response.data) { 265 if (response.data.item_removed && response.data.cart_subtotal) { 266 product.data('key', ''); 267 cuw_products.update_inputs(product, true); 268 cuw_products.update_prices(section, response.data); 269 cuw_actions.update_fragments(page); 270 } 271 } 272 cuw_spinner.hide(product); 273 product.find('.cuw-add-product-to-cart, .cuw-remove-item-from-cart').prop('disabled', false).css('opacity', 1); 274 }, 275 }); 276 }, 277 278 // add addon product to cart 279 add_addon_to_cart: function (section, product) { 280 let wrapper = product; 281 if (product.closest('.cart_item').length) { 282 wrapper = product.closest('.cart_item'); 283 } 284 285 $.ajax({ 286 type: 'post', 287 url: cuw_ajax_url, 288 async: true, 289 data: { 290 action: 'cuw_frontend_ajax', 291 method: 'add_addon_to_cart', 292 campaign_id: section.data('campaign_id') || 0, 293 product_id: product.data('id') || 0, 294 quantity: section.data('quantity') || 0, 295 variation_id: product.data('variant_id') || product.val() || 0, 296 main_item_key: section.data('main_item_key') || '', 297 nonce: cuw_ajax_nonce || "" 298 }, 299 beforeSend: function () { 300 cuw_spinner.show(wrapper); 301 }, 302 success: function (response) { 303 if (response.success && response.data && response.data.item_key) { 304 cuw_actions.update_fragments('cart'); 305 } 306 cuw_spinner.hide(wrapper); 307 }, 308 }); 309 }, 310 311 // remove addon item from cart 312 remove_addon_from_cart: function (section, product) { 313 let key = product.data('item_key'); 314 if (!key) { 315 return; 316 } 317 318 let wrapper = product; 319 if (product.closest('.cart_item').length) { 320 wrapper = product.closest('.cart_item'); 321 } 322 323 $.ajax({ 324 type: 'post', 325 url: cuw_ajax_url, 326 async: true, 327 data: { 328 action: 'cuw_frontend_ajax', 329 method: 'remove_addon_from_cart', 330 item_key: key, 331 nonce: cuw_ajax_nonce || "" 332 }, 333 beforeSend: function () { 334 cuw_spinner.show(wrapper); 335 }, 336 success: function (response) { 337 if (response.success && response.data) { 338 cuw_actions.update_fragments('cart'); 339 } 340 cuw_spinner.hide(wrapper); 341 product.data('lock', false); 342 }, 343 }); 344 }, 345 346 // change cart item variant 347 change_cart_item_variant: function (section, variant) { 348 let key = section.data('item_key'); 349 if (!key) { 350 return; 351 } 352 353 let wrapper = variant; 354 if (variant.closest('.cart_item').length > 0) { 355 wrapper = variant.closest('.cart_item'); 356 } 357 358 $.ajax({ 359 type: 'post', 360 url: cuw_ajax_url, 361 async: true, 362 data: { 363 action: 'cuw_frontend_ajax', 364 method: 'change_cart_item_variant', 365 item_key: key, 366 variation_id: variant.val() || 0, 367 nonce: cuw_ajax_nonce || "" 368 }, 369 beforeSend: function () { 370 cuw_spinner.show(wrapper); 371 }, 372 success: function (response) { 373 if (response.success && response.data) { 374 cuw_actions.update_fragments('cart'); 375 } 376 cuw_spinner.hide(wrapper); 377 }, 378 }); 379 }, 380 381 // to get page 382 get_page: function (section = null) { 383 let page = ''; 384 if (section !== null) { 385 page = section.data('page') ? section.data('page') : section.closest('.cuw-modal').data('page'); 386 } 387 return page; 388 }, 389 390 // to update page fragments 391 update_fragments: function (page = '') { 392 if (page === 'cart' || cuw_is_cart) { 393 jQuery(document.body).trigger('wc_update_cart'); 394 jQuery(document.body).trigger('cuw_cart_page_updated'); 395 } else if (page === 'checkout' || cuw_is_checkout) { 396 jQuery(document.body).trigger('update_checkout'); 397 jQuery(document.body).trigger('cuw_checkout_page_updated'); 398 } else { 399 jQuery(document.body).trigger('wc_fragment_refresh'); 400 jQuery(document.body).trigger('cuw_fragment_refreshed'); 401 } 402 403 if (cuw_has_cart_block || cuw_has_checkout_block) { 404 setTimeout(function () { 405 jQuery(document.body).trigger('added_to_cart', {}); 406 }, 0); 407 } 408 }, 409 410 // to get the product details in popup 411 show_product_details_popup: function (section, product_id) { 412 cuw_spinner.show(section); 413 414 $.ajax({ 415 type: 'post', 416 url: cuw_ajax_url, 417 async: false, 418 data: { 419 action: 'cuw_frontend_ajax', 420 method: 'get_product_details_popup', 421 product_id: product_id, 422 nonce: cuw_ajax_nonce || '' 423 }, 424 success: function (response) { 425 if (response.data.html) { 426 $('body').append(response.data.html); 427 cuw_modal.show($('#cuw-modal-product-details-' + product_id), true); 428 $('#cuw-modal-product-details-' + product_id + ' .variant-select').trigger('change'); 429 } 430 cuw_spinner.hide(section); 431 }, 432 }); 433 }, 434 435 // to update the product image 436 update_product_image: function (section, product_id) { 437 cuw_spinner.show(section.find(".cuw-product-image")); 438 439 $.ajax({ 440 type: 'post', 441 url: cuw_ajax_url, 442 async: true, 443 data: { 444 action: 'cuw_frontend_ajax', 445 method: 'get_offer_image', 446 product_id: product_id, 447 nonce: cuw_ajax_nonce || '' 448 }, 449 success: function (response) { 450 cuw_spinner.hide(section.find('.cuw-product-image')); 451 if (response.data.html) { 452 if (section.find('.cuw-product-image a').length > 0) { 453 section.find('.cuw-product-image a').html(response.data.html); 454 } else { 455 section.find('.cuw-product-image').html(response.data.html); 456 } 457 } 458 }, 459 }); 460 }, 461 } 462 463 $(document).on("change", ".cuw-product-addons .cuw-product .cuw-product-checkbox", function () { 464 let addons_count = $('.cuw-product-addons .cuw-product-checkbox:checked').length; 465 $('.cuw-product-addons-pricing-section').css('display', (addons_count > 0 ? 'flex' : 'none')); 466 $(this).closest('.cuw-product').find('.cuw-product-quantity').toggle($(this).prop('checked')); 467 $(this).closest('.cuw-product').find('.cuw-product-variants').toggle($(this).prop('checked')); 468 }); 469 470 $(document).on("click", ".cuw-modal-product-detail", function () { 471 cuw_actions.show_product_details_popup($(this).closest('.cuw-container'), $(this).data('id')); 472 }); 473 474 $(document).on("click", ".cuw-products .cuw-product .cuw-add-product-to-cart", function () { 475 cuw_actions.add_product_to_cart($(this).closest('.cuw-products'), $(this).closest('.cuw-product')); 476 }); 477 478 $(document).on("change", ".cuw-cart-item-variants .variant-select", function () { 479 cuw_actions.change_cart_item_variant($(this).closest('.cuw-cart-item-variants'), $(this).find("option:selected")); 480 }); 481 482 $(document).on("click", ".cuw-products .cuw-product .cuw-remove-item-from-cart", function () { 483 cuw_actions.remove_item_from_cart($(this).closest('.cuw-products'), $(this).closest('.cuw-product')); 484 }); 485 486 $(document).on("click", ".cuw-cart-addon-products .cuw-products .cuw-product input[type=checkbox]", function () { 487 if ($(this).is(":checked")) { 488 cuw_actions.add_addon_to_cart($(this).closest('.cuw-products'), $(this).closest('.cuw-product')); 489 } else { 490 cuw_actions.remove_addon_from_cart($(this).closest('.cuw-products'), $(this).closest('.cuw-product')); 491 } 492 }); 493 494 $(document).on("click", ".cuw-offer input[type=checkbox], .cuw-offer button", function () { 495 let offer = $(this).closest('.cuw-offer'); 496 if (!offer.hasClass('cuw-offer-added')) { 497 cuw_actions.add_offer_to_cart(offer); 498 } else { 499 cuw_actions.remove_offer_from_cart(offer); 500 } 501 }); 502 503 $(document).on("click", ".cuw-action input[type=checkbox], .cuw-action button", function () { 504 cuw_actions.perform_action($(this).closest('.cuw-action')); 505 }); 506 507 $(document).on("click", ".cuw-products .cuw-add-to-cart", function () { 508 cuw_actions.add_products_to_cart($(this).closest(".cuw-products"), $(this).data('choose_variants') == '1'); 509 }); 510 511 $(".cuw-page .cuw-qty").change(function () { 512 $(".cuw-page .cuw-qty").val($(this).val()); 513 $('.cuw-hidden-product-quantity').val($(this).val()); 514 }).trigger('change'); 515 516 $(".cuw-page .variant-select").change(function () { 517 $(".cuw-page .variant-select").val($(this).val()); 518 $('.cuw-hidden-product-variant').val($(this).val()); 519 }).trigger('change'); 520 521 $(".cuw-page-offer-form, .cuw-page-offer-accept").submit(function () { 522 cuw_spinner.show($(this)); 523 cuw_page_action_performing = true; 524 }); 525 526 $(".cuw-offer-decline-link").click(function () { 527 cuw_page_action_performing = true; 528 $(".cuw-offer-decline-link").css({'pointer-events': 'none', 'opacity': '0.8'}); 529 }); 530 531 $("#cuw-ppu-offer .cuw-ppu-ignore-offers").click(function () { 532 cuw_actions.perform_ppu_action('ignore_offers'); 533 }); 534 535 $("#cuw-ppu-offer .cuw-ppu-accept-button").click(function () { 536 cuw_actions.perform_ppu_action('accept_offer'); 537 }); 538 539 $("#cuw-ppu-offer .cuw-ppu-decline-button, #cuw-ppu-offer .cuw-ppu-decline-link").click(function () { 540 cuw_actions.perform_ppu_action('decline_offer'); 541 }); 542 543 jQuery(document.body).on('click', '.cuw-custom-trigger', function () { 544 cuw_spinner.show($(this).closest('.cuw-modal').find('.cuw-modal-body')); 545 $($(this).data('target')).trigger($(this).data('event')); 546 }); 547 548 jQuery(document.body).on('cuw_update_offers', function (event, campaign_type = '') { 549 if ($('.cuw-offers').length === 0 || campaign_type === '') { 550 return; 551 } 552 553 $.ajax({ 554 type: 'post', 555 url: cuw_ajax_url, 556 async: false, 557 data: { 558 action: 'cuw_frontend_ajax', 559 method: 'get_all_offers_html', 560 campaign_type: campaign_type, 561 nonce: cuw_ajax_nonce || '' 562 }, 563 success: function (response) { 564 if (response.data && response.data.html) { 565 $.each(response.data.html, function (location, html) { 566 $('.cuw-offers[data-location="' + location + '"]').html(html); 567 }); 568 } 569 }, 570 }); 571 }); 572 573
573 if (cuw_dynamic_offer_display_enabled) { 574 if (cuw_is_cart || cuw_has_cart_block) { 575 jQuery(document.body).on('applied_coupon removed_coupon', function () { 576 jQuery(document.body).trigger('cuw_update_offers', ['cart_upsells']); 577 }); 578 } else if (cuw_is_checkout || cuw_has_checkout_block) { 579 jQuery(document.body).on('applied_coupon_in_checkout removed_coupon_in_checkout', function () { 580 jQuery(document.body).trigger('cuw_update_offers', ['checkout_upsells']); 581 }); 582 } 583 } 584 585 jQuery(document.body).on('cuw_show_upsell_popup', function (event, data, element) { 586 if (data.dynamic_content) { 587 $.ajax({ 588 type: 'post', 589 url: cuw_ajax_url, 590 data: { 591 action: 'cuw_frontend_ajax', 592 method: 'get_upsell_popup', 593 campaign_id: data.campaign_id, 594 product_id: data.product_id, 595 trigger: data.trigger, 596 page: data.page, 597 nonce: cuw_ajax_nonce || '' 598 }, 599 success: function (response) { 600 if (response.success && response.data && response.data.campaign_id && response.data.html) { 601 let campaign_id = response.data.campaign_id; 602 if ($('#cuw-modal-' + campaign_id).length > 0) { 603 $('#cuw-modal-' + campaign_id).find('.cuw-cart-subtotal').html(response.data.cart_subtotal); 604 } else { 605 $('body').append(response.data.html); 606 } 607 608 cuw_modal.show($('#cuw-modal-' + campaign_id), true); 609 610 // to add scroll action event listener 611 if (cuw_products && cuw_products.carousel_update_actions) { 612 $('#cuw-modal-' + campaign_id + ' .cuw-carousel .cuw-carousel-slider').on('scroll', function () { 613 cuw_products.carousel_update_actions($(this).closest(".cuw-carousel")); 614 }); 615 } 616 } 617 }, 618 }); 619 } else if (data.campaign_id) { 620 let modal = $('#cuw-modal-' + data.campaign_id); 621 if (modal.length > 0) { 622 modal.data('shown', true); 623 cuw_modal.show(modal); 624 } 625 } 626 }); 627 628 jQuery(document.body).on('checkout_error', function () { 629 cuw_modal.hide('.cuw-modal'); 630 }); 631 632 let messages = $(".cuw-page-timer"); 633 if (messages.length > 0) { 634 let element = messages.first(); 635 let message = element.data('message'); 636 let params = new URLSearchParams(window.location.search); 637 let unique_id = params.get('cuw_order_id'); 638 if (params.get('cuw_ppu_offer')) { 639 unique_id = params.get('cuw_ppu_offer') + '_' + (params.get('cuw_order') || ''); 640 } 641 if (!unique_id) { 642 return; 643 } 644 let duration = (element.data('minutes') * 60) + element.data('seconds'), minutes, seconds; 645 if (Cookies && unique_id) { 646 let duration_from_cookie = Cookies.get("cuw_timer_" + unique_id); 647 if (duration_from_cookie !== undefined) { 648 duration = duration_from_cookie; 649 } 650 } 651 setInterval(function () { 652 if (duration >= 0) { 653 minutes = parseInt(duration / 60, 10); 654 seconds = parseInt(duration % 60, 10); 655 minutes = minutes < 10 ? "0" + minutes : minutes; 656 seconds = seconds < 10 ? "0" + seconds : seconds; 657 messages.html(message.replace('{minutes}', minutes).replace('{seconds}', seconds)); 658 if (duration === 0) { 659 if (params.get('cuw_ppu_offer')) { 660 cuw_actions.perform_ppu_action('decline_offer'); 661 } else if (!cuw_page_action_performing) { 662 window.location = element.data('redirect'); 663 } 664 } 665 if (Cookies && unique_id) { 666 Cookies.set("cuw_timer_" + unique_id, duration); 667 } 668 duration--; 669 } 670 }, 1000); 671 } 672 673});
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.