diaspora/public/javascripts/app/views/stream_view.js
2012-01-07 14:23:24 -08:00

48 lines
1.1 KiB
JavaScript

App.Views.Stream = Backbone.View.extend({
events: {
"click #paginate": "loadMore"
},
initialize: function() {
_.bindAll(this, "appendPost", "collectionFetched", "loadMore");
this.collection = this.collection || new App.Collections.Stream;
this.collection.bind("add", this.appendPost);
},
render : function(){
_.each(this.collection.models, this.appendPost)
return this;
},
appendPost: function(post) {
var postView = new App.Views.Post({ model: post }).render();
$(this.el).append(postView.el);
},
collectionFetched: function() {
this.$("#paginate").remove();
$(this.el).append($("<a>", {
href: this.collection.url(),
id: "paginate"
}).text('Load more posts'));
},
loadMore: function(evt) {
if(evt) { evt.preventDefault(); }
this.addLoader();
this.collection.fetch({
add: true,
success: this.collectionFetched
});
},
addLoader: function(){
this.$("#paginate").html($("<img>", {
src : "/images/static-loader.png",
"class" : 'loader'
}));
}
});