solo
8 years ago
index.php
9 years ago
plugins.js
6 years ago
plugins.min.js
7 years ago
scripts.js
6 years ago
scripts.js
122 lines
| 1 | ;(function($, window, document, undefined){ |
| 2 | const AuxinRemoveCartContent = function() { |
| 3 | // Remove cart content |
| 4 | $(document).on( 'click', '.aux-remove-cart-content', function(e) { |
| 5 | e.preventDefault(); |
| 6 | |
| 7 | var product_id = $(this).data("product_id"); |
| 8 | var verify_nonce = $(this).data("verify_nonce"); |
| 9 | var $cartBoxEl = $(this).closest('.aux-cart-wrapper').addClass('aux-cart-remove-in-progress'); |
| 10 | |
| 11 | $.ajax({ |
| 12 | type: 'POST', |
| 13 | dataType: 'json', |
| 14 | url: auxin.ajax_url, |
| 15 | data: { |
| 16 | action: "auxels_remove_from_cart", |
| 17 | product_id: product_id, |
| 18 | verify_nonce: verify_nonce, |
| 19 | }, |
| 20 | success: function( response ){ |
| 21 | // Remove old notification |
| 22 | $(".woocommerce-message, .woocommerce-error").remove(); |
| 23 | // Start Notifications |
| 24 | if( response.success ) { |
| 25 | $('.aux-hidden-blocks').append( response.data.notif ); |
| 26 | |
| 27 | if( parseInt(response.data.total) === 0 ) { |
| 28 | $('.aux-card-dropdown').html(response.data.empty); |
| 29 | $('.aux-cart-contents').find('span').remove(); |
| 30 | } else { |
| 31 | $('.aux-card-item').filter(function(){ |
| 32 | return $(this).data('product-id') == product_id; |
| 33 | }).remove(); |
| 34 | $('.aux-cart-contents').find('span').text(response.data.count); |
| 35 | } |
| 36 | $(".aux-cart-subtotal").each(function() { |
| 37 | $(this).find('.woocommerce-Price-amount').contents().filter(function(){ |
| 38 | return this.nodeType == 3; |
| 39 | })[0].nodeValue = response.data.total; |
| 40 | }); |
| 41 | $cartBoxEl.removeClass('aux-cart-remove-in-progress'); |
| 42 | } else { |
| 43 | $('.aux-hidden-blocks').append( response.data ); |
| 44 | } |
| 45 | } |
| 46 | }); |
| 47 | |
| 48 | }); |
| 49 | }; |
| 50 | |
| 51 | const AuxinAjaxAddToCart = function() { |
| 52 | // Add Content to Cart |
| 53 | $(document).on( 'click', '.aux-ajax-add-to-cart', function(e) { |
| 54 | var productType = $(this).data("product-type"); |
| 55 | |
| 56 | if ( productType !== 'simple' || typeof auxin_cart_options === 'undefined' ) { |
| 57 | return; |
| 58 | } |
| 59 | |
| 60 | e.preventDefault(); |
| 61 | |
| 62 | var product_id = $(this).data("product_id"); |
| 63 | var quantity = $(this).data("quantity"); |
| 64 | var verify_nonce = $(this).data("verify_nonce"); |
| 65 | var $cartBoxEl = $('.aux-cart-wrapper'); |
| 66 | var hasAnimation = $cartBoxEl.hasClass('aux-basket-animation') ? true : false; |
| 67 | |
| 68 | $cartBoxEl.trigger('AuxCartInProgress'); |
| 69 | |
| 70 | if ( $(this).parents('.aux-shop-quicklook-modal') ) { |
| 71 | quantity = $(this).parents('.aux-shop-quicklook-modal').find('.quantity input').val(); |
| 72 | } |
| 73 | |
| 74 | $.ajax({ |
| 75 | type: 'POST', |
| 76 | dataType: 'json', |
| 77 | url: auxin.ajax_url, |
| 78 | data: { |
| 79 | action : "auxels_add_to_cart", |
| 80 | args : auxin_cart_options, |
| 81 | product_id : product_id, |
| 82 | quantity : quantity, |
| 83 | verify_nonce: verify_nonce |
| 84 | }, |
| 85 | success: function( response ){ |
| 86 | // Remove old notification |
| 87 | $(".woocommerce-message, .woocommerce-error").remove(); |
| 88 | // Start Notifications |
| 89 | if( response.success ) { |
| 90 | $('.aux-hidden-blocks').append( response.data.notif ); |
| 91 | |
| 92 | setTimeout( function(){ |
| 93 | if ( hasAnimation ) { |
| 94 | $cartBoxEl.on('AuxCartProgressAnimationDone', function(e) { |
| 95 | $cartBoxEl.find('.aux-card-dropdown').html( response.data.items ); |
| 96 | $cartBoxEl.find('.aux-shopping-basket').html( response.data.total ); |
| 97 | $cartBoxEl.trigger('AuxCartUpdated'); |
| 98 | }); |
| 99 | } else { |
| 100 | $cartBoxEl.find('.aux-card-dropdown').html( response.data.items ); |
| 101 | $cartBoxEl.find('.aux-shopping-basket').html( response.data.total ); |
| 102 | $cartBoxEl.trigger('AuxCartUpdated'); |
| 103 | } |
| 104 | }, 150); |
| 105 | |
| 106 | |
| 107 | } else { |
| 108 | $('.aux-hidden-blocks').append( response.data ); |
| 109 | } |
| 110 | |
| 111 | } |
| 112 | |
| 113 | }); |
| 114 | |
| 115 | }); |
| 116 | }; |
| 117 | |
| 118 | $(document).ready(function(){ |
| 119 | AuxinRemoveCartContent(); |
| 120 | AuxinAjaxAddToCart(); |
| 121 | }); |
| 122 | })(jQuery,window,document); |