Sha256: d0cc81d5a844eb4edf2ebe74c0d9cfe23c81ecef8152fe1c5cd033c5638fb849
Contents?: true
Size: 1.28 KB
Versions: 3
Compression:
Stored size: 1.28 KB
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() }) } Spree.loadCarousel = function (element, div) { var container = $(element) var productCarousel = $(div) 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) } } Spree.loadsCarouselElements = function () { $('div[data-product-carousel-taxon-id]').each(function (_index, element) { Spree.loadCarousel(element, this) }) } document.addEventListener('turbo:load', function () { var carouselPresent = $('div[data-product-carousel-taxon-id]') if (carouselPresent.length) { // load Carousels straight away if they are in the viewport Spree.loadsCarouselElements() // load additional Carousels when scrolling down $(window).on('resize scroll', function () { Spree.loadsCarouselElements() }) } })
Version data entries
3 entries across 3 versions & 1 rubygems