// script for endless scrolling using jQuery
// demo: http://www.jstoolbox.com/demo/endless/
var engine = {
posts : [],
target : null,
busy : false,
count : 5,
render : function(obj){
var xhtml = '
';
if (obj.title) {
xhtml += '
'+obj.title+'
';
}
if (obj.posted_at) {
xhtml += '
Posted on: '+obj.posted_at+'
';
}
if (obj.comments_count) {
xhtml += '';
}
xhtml += '
' + obj.content + '
';
xhtml += '
';
return xhtml;
},
init : function(posts, target){
if (!target)
return;
this.target = $(target);
this.append(posts);
var that = this;
$(window).scroll(function(){
if ($(document).height() - $(window).height() <= $(window).scrollTop() + 50) {
that.scrollPosition = $(window).scrollTop();
that.get();
}
});
},
append : function(posts){
posts = (posts instanceof Array) ? posts : [];
this.posts = this.posts.concat(posts);
for (var i=0, len = posts.length; i