Created
May 7, 2019 17:53
-
-
Save karen-white/8e002172a2946b8473b8538aa737dee9 to your computer and use it in GitHub Desktop.
Infinite Scroll on Cornerstone 1.18.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { hooks } from '@bigcommerce/stencil-utils'; | |
import CatalogPage from './catalog'; | |
import $ from 'jquery'; | |
import FacetedSearch from './common/faceted-search'; | |
import InfiniteScroll from 'infinite-scroll'; | |
export default class Category extends CatalogPage { | |
loaded() { | |
function infiniteScroll() { | |
const elem = document.querySelector('.productGrid'); | |
const infScroll = new InfiniteScroll(elem, { | |
// options | |
path: '.pagination-item--next .pagination-link', | |
append: '.product', | |
history: false, | |
}); | |
return infScroll; | |
} | |
infiniteScroll(); | |
if ($('#facetedSearch').length > 0) { | |
this.initFacetedSearch(); | |
} else { | |
this.onSortBySubmit = this.onSortBySubmit.bind(this); | |
hooks.on('sortBy-submitted', this.onSortBySubmit); | |
} | |
} | |
initFacetedSearch() { | |
const $productListingContainer = $('#product-listing-container'); | |
const $facetedSearchContainer = $('#faceted-search-container'); | |
const productsPerPage = this.context.categoryProductsPerPage; | |
const requestOptions = { | |
config: { | |
category: { | |
shop_by_price: true, | |
products: { | |
limit: productsPerPage, | |
}, | |
}, | |
}, | |
template: { | |
productListing: 'category/product-listing', | |
sidebar: 'category/sidebar', | |
}, | |
showMore: 'category/show-more', | |
}; | |
this.facetedSearch = new FacetedSearch(requestOptions, (content) => { | |
$productListingContainer.html(content.productListing); | |
$facetedSearchContainer.html(content.sidebar); | |
$('html, body').animate({ | |
scrollTop: 0, | |
}, 100); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment