Last active
October 6, 2015 16:29
-
-
Save kpheasey/1e52d40d0f651c65d546 to your computer and use it in GitHub Desktop.
RailsScript Infinite Scroll
This file contains 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
window.App ||= {} | |
class App.GemgentoCategories extends App.Base | |
show: => | |
new App.ProductGrid() | |
@infiniteScroll() | |
return | |
# Enable infinite scrolling | |
infiniteScroll: -> | |
$("#category-products").infinitescroll | |
navSelector: "div.pagination" | |
nextSelector: "div.pagination a:first" | |
itemSelector: "#category-products div.tile" | |
bufferPx: 1200 | |
, (arrayOfNewElem) -> | |
# hide the pagination link if we didn't load a full page | |
if arrayOfNewElem.length != 12 | |
$('#next').hide() | |
$(window).trigger('resize') # make sure the tiles are all sized correctly | |
# hide images and fade in once loaded | |
$(arrayOfNewElem).each -> | |
$imageWrapper = $('.image-wrapper', this) | |
$('img', $imageWrapper).hide() | |
$imageWrapper.imagesLoaded -> | |
$('img', $imageWrapper).fadeIn() | |
return | |
# pause the infinite scroll when user navigates away | |
$(document).on 'page:fetch', -> | |
$("#category-products").infinitescroll('pause'); | |
# resume infinite scroll when page is restored | |
$(document).on 'page:restore', -> | |
$("#category-products").infinitescroll('resume'); | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment