Skip to content
Extraits de code Groupes Projets
Valider bc0c92ec rédigé par danielgrippi's avatar danielgrippi Validation de Dennis Collinson
Parcourir les fichiers

added inf. scroll to stream; passing inf. scroll cukes

parent 33e0de94
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -179,8 +179,6 @@ end ...@@ -179,8 +179,6 @@ end
And /^I scroll down$/ do And /^I scroll down$/ do
evaluate_script("window.scrollBy(0,3000000)") 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" step "I wait for the ajax to finish"
end end
......
...@@ -9,9 +9,26 @@ app.views.Stream = Backbone.View.extend({ ...@@ -9,9 +9,26 @@ app.views.Stream = Backbone.View.extend({
this.publisher = new app.views.Publisher({collection : this.collection}); 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; 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) { prependPost : function(post) {
var postView = new app.views.Post({ model: post }); var postView = new app.views.Post({ model: post });
$(this.el).prepend(postView.render().el); $(this.el).prepend(postView.render().el);
...@@ -32,6 +49,8 @@ app.views.Stream = Backbone.View.extend({ ...@@ -32,6 +49,8 @@ app.views.Stream = Backbone.View.extend({
href: this.collection.url(), href: this.collection.url(),
id: "paginate" id: "paginate"
}).text('Load more posts')); }).text('Load more posts'));
this._loading = false;
}, },
render : function(evt) { render : function(evt) {
...@@ -39,6 +58,9 @@ app.views.Stream = Backbone.View.extend({ ...@@ -39,6 +58,9 @@ app.views.Stream = Backbone.View.extend({
var self = this; var self = this;
self.addLoader(); self.addLoader();
this._loading = true;
self.collection.fetch({ self.collection.fetch({
add: true, add: true,
success: $.proxy(this.collectionFetched, self) success: $.proxy(this.collectionFetched, self)
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter