1(function ($) { 2 "use strict"; 3 4 $(document).on('bacolaSinglePageInit', function () { 5 woocommerceSingleAjax(); 6 }); 7 8 function woocommerceSingleAjax() { 9 // Klb Notice 10 $('body').append('<div class="klb-notice-ajax"></div>'); 11 12 $("form.cart").addClass("single-ajax"); 13 14 $(".product:not(.product-type-external) form.cart").submit(function() { 15 var val = $("button[type=submit][clicked=true]").val(); 16 }); 17 $(".product:not(.product-type-external) form.cart button[type=submit]").click(function() { 18 $("button[type=submit]", $(this).parents("form")).removeAttr("clicked"); 19 $(this).attr("clicked", "true"); 20 }); 21 22 // AJax single add to cart 23 $('.product:not(.product-type-external) .single-product form.cart, .single .product:not(.product-type-external) form.cart').on('submit', function(e) { 24 25 if($('button[type=submit][clicked=true]').attr('id') == 'buynow'){ 26 return; 27 } 28 29 e.preventDefault(); 30 31 var form = $(this); 32 $('form.cart button.single_add_to_cart_button').append('<svg class="loader-image preloader added" width="65px" height="65px" viewBox="0 0 66 66" xmlns="http://www.w3.org/2000/svg"><circle class="path" fill="none" stroke-width="6" stroke-linecap="round" cx="33" cy="33" r="30"></circle></svg>') 33 34 var formData = new FormData(form[0]); 35 formData.append('add-to-cart', form.find('[name=add-to-cart]').val() ); 36 37 // Ajax action. 38 $.ajax({ 39 url: wc_add_to_cart_params.wc_ajax_url.toString().replace( '%%endpoint%%', 'bacola_add_to_cart' ), 40 data: formData, 41 type: 'POST', 42 processData: false, 43 contentType: false, 44 complete: function( response ) { 45 response = response.responseJSON; 46 47 // Redirect to cart option 48 if ( wc_add_to_cart_params.cart_redirect_after_add === 'yes' ) { 49 window.location = wc_add_to_cart_params.cart_url; 50 return; 51 } 52 53 if ( ! response ) { 54 return; 55 } 56 57 if ( response.error && response.product_url ) { 58 window.location = response.product_url; 59 return; 60 } 61 62 var $thisbutton = form.find('.single_add_to_cart_button'); // 63 // $thisbutton = null; // uncomment this if you don't want the 'View cart' button 64 65 // Trigger event so themes can refresh other areas. 66 $( document.body ).trigger( 'added_to_cart', [ response.fragments, response.cart_hash, $thisbutton ] ); 67 68 $(response.fragments.notices_html).appendTo('.klb-notice-ajax').delay(3000).fadeOut(300, function(){ $(this).remove();}); 69 70 //Close icon 71 $('.woocommerce-message, .woocommerce-error').append('<div class="klb-notice-close"><i class="klbth-icon-cancel"></i></div>'); 72 $('.klb-notice-close').on('click', function(){ 73 $(this).closest('.woocommerce-message, .woocommerce-error').remove(); 74 }); 75 76 $('.product-detail form.cart.single-ajax button svg, .bacola-product-bottom-popup-cart form.cart.single-ajax button svg').remove(); 77 } 78 }); 79 }); 80 } 81 82 $(document).ready(function() { 83 woocommerceSingleAjax(); 84 }); 85 86}(jQuery));
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.