Skip to content

Instantly share code, notes, and snippets.

Created May 10, 2015 12:50
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 anonymous/e6b56f1bccf754a865eb to your computer and use it in GitHub Desktop.
Save anonymous/e6b56f1bccf754a865eb to your computer and use it in GitHub Desktop.
<div class="participations" data-no-turbolink>
<h2><%= participation.user.name %></h2>
</div>
<div class="container">
<div class="row">
<div id="participations">
<%= render @participations %>
</div>
<%= will_paginate @participations %>
</div>
</div>
$('#participations').append('<%= j render(@participations) %>');
<% if @participations.next_page %>
$('.pagination').replaceWith('<%= j will_paginate(@participations) %>');
<% else %>
$('.pagination').remove();
<% end %>
$(window).scroll ->
#Return right away if we're busy loading next set
return if(window.pagination_loading)
url = $('.pagination .next_page').attr('href')
console.log "url is undefined: url #{url}"
if url && $(window).scrollTop() > $(document).height() - $(window).height() - 50
#Note that we're loading data set
window.pagination_loading = true
#load as before but attach callback to clear falg when we're done.
$('.pagination').text('Fetching more products...')
$.getScript(url).always ->
window.pagination_loading = false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment