Sha256: 81196d08360474aaecf0ec88b9ebeb6eb17058ad8397780f255a4ac59bcdaa5d

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

//= require harpiya/frontend/viewport

Harpiya.fetchRelatedProducts = function (id, htmlContainer) {
  return $.ajax({
    url: Harpiya.routes.product_related(id)
  }).done(function (data) {
    htmlContainer.html(data)
    htmlContainer.find('.carousel').carouselBootstrap4()
  })
}

document.addEventListener('turbolinks:load', function () {
  var productDetailsPage = $('body#product-details')

  if (productDetailsPage.length) {
    var productId = $('div[data-related-products]').attr('data-related-products-id')
    var relatedProductsEnabled = $('div[data-related-products]').attr('data-related-products-enabled')
    var relatedProductsFetched = false
    var relatedProductsContainer = $('#related-products')

    if (!relatedProductsFetched && relatedProductsContainer.length && relatedProductsEnabled && relatedProductsEnabled === 'true' && productId !== '') {
      $(window).on('resize scroll', function () {
        if (!relatedProductsFetched && relatedProductsContainer.isInViewport()) {
          Harpiya.fetchRelatedProducts(productId, relatedProductsContainer)
          relatedProductsFetched = true
        }
      })
    }
  }
})

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
harpiya_frontend-4.3.0.alpha app/assets/javascripts/harpiya/frontend/views/harpiya/product/related.js