Created
May 19, 2013 00:16
-
-
Save zackbraksa/5606187 to your computer and use it in GitHub Desktop.
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
class CommunitiesController < ApplicationController | |
# ... | |
def show | |
@community = Community.find(params[:id]) | |
@users = @community.users | |
@ressources = Ressource.paginate(:page => params[:page], :per_page => 5) | |
end | |
# ... | |
end |
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
var currentPage = 1; | |
var intervalID = -1000; | |
function checkScroll() { | |
if (nearBottomOfPage()) { | |
currentPage++; | |
console.log("endless request "+ currentPage); | |
jQuery.ajax('?page=' + currentPage, {asynchronous:true, evalScripts:true, method:'get', success: function(data, textStatus, jqXHR) { | |
$('.ressources').append(jQuery(data).find('.ressources').html()); | |
if(typeof jQuery(data).find('.ressources').html() == 'undefined' || jQuery(data).find('.ressources').html().trim().length == 0){ | |
clearInterval(intervalID); | |
} | |
},}); | |
} | |
} | |
function nearBottomOfPage() { | |
return scrollDistanceFromBottom() < 50; | |
} | |
function scrollDistanceFromBottom(argument) { | |
return pageHeight() - (window.pageYOffset + self.innerHeight); | |
} | |
function pageHeight() { | |
return Math.max(document.body.scrollHeight, document.body.offsetHeight); | |
} | |
$('document').ready(function(){ | |
intervalID = setInterval(checkScroll, 250); | |
}) |
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
<div class="row"> | |
<div class="span12"> | |
<div class="box"> | |
<h1>Board</h1> | |
</div> | |
</div> | |
</div> | |
<div class="row"> | |
<div class="span12"> | |
<div class="ressources"> | |
<%= render :partial => 'ressource', :collection => @ressources %> | |
</div> | |
</div> | |
</div> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Finally found an infinite scroll that worked. Thank you!