Advertisement
NikolayBezay

Tollmansdot dynamic carousel DT

Jan 5th, 2022
717
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 4.70 KB | None | 0 0
  1. <style>
  2.     .slider-item img {
  3.         display: none;
  4.     }
  5.  
  6.     .slider-item .productImage {
  7.         background-image: url(https://adoric-fonts.s3.amazonaws.com/product_placeholder.svg);
  8.         background-repeat: no-repeat;
  9.         background-position: center;
  10.         background-size: contain;
  11.         left: 0px !important;
  12.         right: 0px !important;
  13.         margin: 0 auto !important;
  14.     }
  15.  
  16.     .productImage,
  17.     .productTitle,
  18.     .productButton {
  19.         left: 0px !important;
  20.         right: 0px !important;
  21.         margin: 0 auto !important;
  22.     }
  23.  
  24.     .slider-item .productPrice {
  25.         width: 50% !important;
  26.         left: 0px !important;
  27.     }
  28.  
  29.     .slider-item .productSalePrice {
  30.         width: 50% !important;
  31.         right: 0px !important;
  32.         left: unset !important;
  33.     }
  34.     .slider-item .productSalePrice SPAN{
  35.         color: rgb(0, 0, 0) !important;
  36.         text-decoration: none !important;
  37.     }
  38. </style>
  39. <script>
  40.     (function() {
  41.         var productChanel = 'https://feeds.datafeedwatch.com/59896/c413cbaf3a5fffb4186bb420db4fac1e24390f7f.json';
  42.  
  43.         function updateSlideContent(campaignSlide, sourceSlide) {
  44.             /* productImage productTitle productButton productPrice ₪*/
  45.             var productLink = sourceSlide.link;
  46.             if (productLink) {
  47.                 campaignSlide.querySelector('.productButton a').href = productLink;
  48.             }
  49.             var productTitle = sourceSlide.title;
  50.             if (productTitle) {
  51.                 campaignSlide.querySelector('.productTitle SPAN').textContent = productTitle;
  52.             }
  53.             var productImage = sourceSlide.image_link;
  54.             if (productImage) {
  55.                 campaignSlide.querySelector('.productImage').style.setProperty('background-image', 'url(' + productImage + ')', 'important');
  56.             }
  57.             var productPrice = sourceSlide.price;
  58.             var slidePriceElement = campaignSlide.querySelector('.productPrice SPAN');
  59.             if (productPrice && slidePriceElement) {
  60.                slidePriceElement.textContent = productPrice.replace('ILS', '') + '₪';
  61.             }
  62.             var productSalePrice = sourceSlide.sale_price;
  63.             var salePriceSlideElement = campaignSlide.querySelector('.productSalePrice SPAN');
  64.             if (productSalePrice && productSalePrice.length > 0) {
  65.                salePriceSlideElement.textContent = productSalePrice.replace('ILS', '') + '₪';
  66.                 slidePriceElement.style.setProperty('color', 'rgb(244, 67, 54)', 'important');
  67.                 slidePriceElement.style.setProperty('text-decoration', 'line-through', 'important');
  68.                 slidePriceElement.style.setProperty('font-family', '"Open Sans Hebrew", sans-serif', 'important');
  69.             } else {
  70.                 salePriceSlideElement.style.display = 'none';
  71.                 slidePriceElement.parentNode.style.setProperty('left', '0px', 'important');
  72.                 slidePriceElement.parentNode.style.setProperty('right', '0px', 'important');
  73.                 slidePriceElement.parentNode.style.setProperty('margin', '0 auto', 'important');
  74.                 slidePriceElement.style.setProperty('text-align', 'center', 'important');
  75.             }
  76.         }
  77.         var sliderItems = document.querySelectorAll('.' + self.identifier + '.__ADORIC__ [tabindex] .slider-item');
  78.         var sliderWrapper = document.querySelector('.' + self.identifier + '.__ADORIC__ [tabindex] .slider-content');
  79.         try {
  80.             var data = null;
  81.             var xhr = new XMLHttpRequest();
  82.             xhr.withCredentials = true;
  83.             xhr.addEventListener('readystatechange', function() {
  84.                 if (this.readyState === 4) {
  85.                     var responseJson = JSON.parse(this.responseText);
  86.                     var pageProducts = responseJson.products;
  87.                     for (var i = 1; i < sliderItems.length; i++) {
  88.                        var pageItemIndex = i - 1;
  89.                        if (i <= pageProducts.length) {
  90.                            updateSlideContent(sliderItems[i], pageProducts[pageItemIndex]);
  91.                        } else {
  92.                            sliderWrapper.removeChild(sliderItems[i]);
  93.                        }
  94.                        if (i == sliderItems.length - 1 && pageProducts.length >= i) {
  95.                             updateSlideContent(sliderItems[0], pageProducts[i]);
  96.                         }
  97.                     }
  98.                 }
  99.             });
  100.             xhr.open('GET', productChanel);
  101.             xhr.setRequestHeader('cache-control', 'no-cache');
  102.             xhr.send(data);
  103.         } catch (error) {
  104.             console.log(error);
  105.         }
  106.     })();
  107. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement