loadMore -> render (Stream view); add #paginate div if not already present in addLoader

This commit is contained in:
danielgrippi 2011-12-26 01:14:09 -05:00 committed by Dennis Collinson
parent 79208e9073
commit 6ad4c8e348
2 changed files with 17 additions and 14 deletions

View file

@ -5,15 +5,14 @@ App.Router = Backbone.Router.extend({
"like_stream": "stream",
"mentions": "stream",
"people/:id": "stream",
"u/:name": "stream",
"tag_followings": "stream",
"tags/:name": "stream",
"posts/:id": "stream"
},
stream: function() {
App.stream = new App.Views.Stream;
App.stream = new App.Views.Stream().render();
$("#main_stream").html(App.stream.el);
App.stream.loadMore();
}
});

View file

@ -1,17 +1,12 @@
App.Views.Stream = Backbone.View.extend({
events: {
"click #paginate": "loadMore"
"click #paginate": "render"
},
initialize: function() {
_.bindAll(this, "collectionFetched");
this.collection = this.collection || new App.Collections.Stream;
this.collection.bind("add", this.appendPost, this);
},
render : function(){
_.each(this.collection.models, this.appendPost, this)
return this;
},
@ -28,20 +23,29 @@ App.Views.Stream = Backbone.View.extend({
}).text('Load more posts'));
},
loadMore: function(evt) {
render : function(evt) {
if(evt) { evt.preventDefault(); }
this.addLoader();
this.collection.fetch({
var self = this;
self.addLoader();
self.collection.fetch({
add: true,
success: this.collectionFetched
success: $.proxy(this.collectionFetched, self)
});
return this;
},
addLoader: function(){
if(this.$("#paginate").length == 0) {
$(this.el).append($("<div>", {
"id" : "paginate"
}));
}
this.$("#paginate").html($("<img>", {
src : "/images/static-loader.png",
"class" : 'loader'
"class" : "loader"
}));
}
});