added inf. scroll to stream; passing inf. scroll cukes
This commit is contained in:
parent
33e0de94f8
commit
bc0c92ec64
2 changed files with 22 additions and 2 deletions
|
|
@ -179,8 +179,6 @@ end
|
|||
|
||||
And /^I scroll down$/ do
|
||||
evaluate_script("window.scrollBy(0,3000000)")
|
||||
sleep 1
|
||||
wait_until(30) { evaluate_script('$("#infscr-loading:visible").length') == 0 }
|
||||
step "I wait for the ajax to finish"
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -9,9 +9,26 @@ app.views.Stream = Backbone.View.extend({
|
|||
|
||||
this.publisher = new app.views.Publisher({collection : this.collection});
|
||||
|
||||
// inf scroll
|
||||
// we're using this._loading to keep track of backbone's collection
|
||||
// fetching state... is there a better way to do this?
|
||||
var throttledScroll = _.throttle($.proxy(this.infScroll, this), 200);
|
||||
$(window).scroll(throttledScroll);
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
infScroll : function(options) {
|
||||
var $window = $(window);
|
||||
var distFromTop = $window.height() + $window.scrollTop();
|
||||
var distFromBottom = $(document).height() - distFromTop;
|
||||
var bufferPx = 300;
|
||||
|
||||
if(distFromBottom < bufferPx && !this._loading) {
|
||||
this.render();
|
||||
}
|
||||
},
|
||||
|
||||
prependPost : function(post) {
|
||||
var postView = new app.views.Post({ model: post });
|
||||
$(this.el).prepend(postView.render().el);
|
||||
|
|
@ -32,6 +49,8 @@ app.views.Stream = Backbone.View.extend({
|
|||
href: this.collection.url(),
|
||||
id: "paginate"
|
||||
}).text('Load more posts'));
|
||||
|
||||
this._loading = false;
|
||||
},
|
||||
|
||||
render : function(evt) {
|
||||
|
|
@ -39,6 +58,9 @@ app.views.Stream = Backbone.View.extend({
|
|||
|
||||
var self = this;
|
||||
self.addLoader();
|
||||
|
||||
this._loading = true;
|
||||
|
||||
self.collection.fetch({
|
||||
add: true,
|
||||
success: $.proxy(this.collectionFetched, self)
|
||||
|
|
|
|||
Loading…
Reference in a new issue