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