Skip to content

Instantly share code, notes, and snippets.

@kpheasey
Last active October 6, 2015 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kpheasey/1e52d40d0f651c65d546 to your computer and use it in GitHub Desktop.
Save kpheasey/1e52d40d0f651c65d546 to your computer and use it in GitHub Desktop.
RailsScript Infinite Scroll
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