var EndlessPage = Class.create();
EndlessPage.prototype = {
initialize: function (total_pages, url, auth_token) {
this.timer = null;
this.current_page = 1;
this.total_pages = total_pages;
this.ajax_path = url;
this.interval = 1000;
this.scroll_offset = 0.6;
this.auth_token = auth_token;
this.start_listener();
},
stop_listener: function () {
this.timer = null;
},
start_listener: function () {
this.timer = setTimeout('ep._check_scroll()', this.interval);
},
_check_scroll: function () {
if(this.timer == undefined || this.total_pages == this.current_page) {
return;
}
var offset = document.viewport.getScrollOffsets()[1];
if(offset/document.viewport.getHeight() > this.scroll_offset) {
this.current_page++;
new Ajax.Request(this.ajax_path, { parameters: { authenticity_token: this.auth_token, page: this.current_page } });
}
this.start_listener();
}
};