Sha256: 1bdd2ee0565eb4944f80296d8129a02995d8541635065903e812032c3292707d

Contents?: true

Size: 1003 Bytes

Versions: 3

Compression:

Stored size: 1003 Bytes

Contents

//= require spree/frontend/viewport

Spree.fetchProductCarousel = function (taxonId, htmlContainer) {
  return $.ajax({
    url: Spree.routes.product_carousel(taxonId)
  }).done(function (data) {
    htmlContainer.html(data);
    htmlContainer.find('.carousel').carouselBootstrap4()
  })
}

document.addEventListener('turbolinks:load', function () {
  var homePage = $('body#home')

  if (homePage.length) {
    $(window).on('resize scroll', function () {
      $('div[data-product-carousel').each(function (_index, element) {
        var container = $(element)
        var productCarousel = $(this)
        var carouselLoaded = productCarousel.attr('data-product-carousel-loaded')

        if (container.length && !carouselLoaded && container.isInViewport()) {
          var taxonId = productCarousel.attr('data-product-carousel-taxon-id')
          productCarousel.attr('data-product-carousel-loaded', 'true')

          Spree.fetchProductCarousel(taxonId, container)
        }
      })
    })
  }
})

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
spree_frontend-4.1.0.rc3 app/assets/javascripts/spree/frontend/views/spree/home/product_carousels.js
spree_frontend-4.1.0.rc2 app/assets/javascripts/spree/frontend/views/spree/home/product_carousels.js
spree_frontend-4.1.0.rc1 app/assets/javascripts/spree/frontend/views/spree/home/product_carousels.js