Created
August 17, 2012 05:50
-
-
Save vincentopensourcetaiwan/3376284 to your computer and use it in GitHub Desktop.
Endless Page
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
jQuery -> | |
if $('.pagination').length | |
$(window).scroll -> | |
url = $('.pagination .next_page').attr('href') | |
if url && $(window).scrollTop() > $(document).height() - $(window).height() - 50 | |
$('.pagination').text("Fetching more posts...") | |
$.getScript(url) | |
$(window).scroll() | |
# /app/assets/javascripts/posts.js.coffee |
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
<%= post.body %><br /> | |
<!-- /app/views/posts/_post.html.erb --> |
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
<h1>Listing posts</h1> | |
<div id="posts"> | |
<%= render @posts %> | |
</div> | |
<%= will_paginate(@posts)%> | |
<!-- /app/views/posts/index.html.erb --> |
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
$('#posts').append('<%= j render(@posts) %>'); | |
<% if @posts.next_page %> | |
$('.pagination').replaceWith('<%= j will_paginate(@posts) %>'); | |
<% else %> | |
$('.pagination').remove(); | |
<% end %> | |
// /app/views/index.js.erb |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment