Sha256: 1f313028b65c97200acb08ca04543c43d044220c0074491f2706858d6d12dd31
Contents?: true
Size: 1.28 KB
Versions: 8
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('turbolinks: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
8 entries across 8 versions & 1 rubygems