Advertisement
orenchuck

carousel without reload page soda

Jul 27th, 2022
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. <script>
  2. (function() {
  3. /* cart counter different on mb and dt */
  4. //dt
  5. var cartCounter = document.querySelector('div.header-action-area.d-none p.v2-cart-counter');
  6. //mb
  7. var cartCounter = document.querySelector('div.header-mobile a.header-cart p');
  8.  
  9. function adoricAddToCart(productId, addToCartButton) {
  10. /* add this ti add to cart function */
  11. addToCartButton.style.backgroundColor = 'rgb(255, 255, 255)';
  12. addToCartButton.style.border = '1px solid rgb(0, 158, 226)';
  13. addToCartButton.style.color = '#00adee';
  14. addToCartButton.textContent = 'Added to cart';
  15. addToCartButton.style.outline = 'none';
  16. setTimeout(() => {
  17. addToCartButton.style.backgroundColor = 'rgb(0, 158, 226)';
  18. addToCartButton.style.color = 'rgb(255, 255, 255)';
  19. }, 1500);
  20.  
  21. window.adoricAddToCart = data;
  22. /*--------------*/
  23.  
  24.  
  25. xhr.addEventListener('readystatechange', function() {
  26. if (this.readyState === 4) {
  27. /* add here counting in the cart instead of reload */
  28. cartCounter.textContent = parseInt(cartCounter.textContent) + 1;
  29. if (cartCounter.classList.contains('d-none')) {
  30. cartCounter.classList.remove('d-none');
  31. }
  32. /*---------------*/
  33. }
  34. });
  35. }
  36.  
  37. currentCampaignRepeater.addEventListener('click', function(event) {
  38. if (event.target.getAttribute('role') === 'button' && productItem) {
  39. /* here add an addToCartButton value and add it to adoricAddToCart function. Don't forget to
  40. add the second argument into function */
  41.  
  42. var addToCartButton = event.target;
  43. adoricAddToCart(productId, addToCartButton);
  44. }
  45. });
  46.  
  47. /* add this event listener on close campaign*/
  48. adoric.on('lightbox:before:close', function(e) {
  49. if (e.lightbox.options.campaignId === self.campaignId) {
  50. if (window.adoricAddToCart) {
  51. window.location.reload();
  52. }
  53. }
  54. });
  55. })();
  56.  
  57. /* and add to the button link keep opened */
  58. </script>
  59.  
  60.  
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement