loadMore -> render (Stream view); add #paginate div if not already present in addLoader
This commit is contained in:
parent
79208e9073
commit
6ad4c8e348
2 changed files with 17 additions and 14 deletions
|
|
@ -5,15 +5,14 @@ App.Router = Backbone.Router.extend({
|
||||||
"like_stream": "stream",
|
"like_stream": "stream",
|
||||||
"mentions": "stream",
|
"mentions": "stream",
|
||||||
"people/:id": "stream",
|
"people/:id": "stream",
|
||||||
|
"u/:name": "stream",
|
||||||
"tag_followings": "stream",
|
"tag_followings": "stream",
|
||||||
"tags/:name": "stream",
|
"tags/:name": "stream",
|
||||||
"posts/:id": "stream"
|
"posts/:id": "stream"
|
||||||
},
|
},
|
||||||
|
|
||||||
stream: function() {
|
stream: function() {
|
||||||
App.stream = new App.Views.Stream;
|
App.stream = new App.Views.Stream().render();
|
||||||
$("#main_stream").html(App.stream.el);
|
$("#main_stream").html(App.stream.el);
|
||||||
|
|
||||||
App.stream.loadMore();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,12 @@
|
||||||
App.Views.Stream = Backbone.View.extend({
|
App.Views.Stream = Backbone.View.extend({
|
||||||
events: {
|
events: {
|
||||||
"click #paginate": "loadMore"
|
"click #paginate": "render"
|
||||||
},
|
},
|
||||||
|
|
||||||
initialize: function() {
|
initialize: function() {
|
||||||
_.bindAll(this, "collectionFetched");
|
|
||||||
|
|
||||||
this.collection = this.collection || new App.Collections.Stream;
|
this.collection = this.collection || new App.Collections.Stream;
|
||||||
this.collection.bind("add", this.appendPost, this);
|
this.collection.bind("add", this.appendPost, this);
|
||||||
},
|
|
||||||
|
|
||||||
render : function(){
|
|
||||||
_.each(this.collection.models, this.appendPost, this)
|
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -28,20 +23,29 @@ App.Views.Stream = Backbone.View.extend({
|
||||||
}).text('Load more posts'));
|
}).text('Load more posts'));
|
||||||
},
|
},
|
||||||
|
|
||||||
loadMore: function(evt) {
|
render : function(evt) {
|
||||||
if(evt) { evt.preventDefault(); }
|
if(evt) { evt.preventDefault(); }
|
||||||
|
|
||||||
this.addLoader();
|
var self = this;
|
||||||
this.collection.fetch({
|
self.addLoader();
|
||||||
|
self.collection.fetch({
|
||||||
add: true,
|
add: true,
|
||||||
success: this.collectionFetched
|
success: $.proxy(this.collectionFetched, self)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
addLoader: function(){
|
addLoader: function(){
|
||||||
|
if(this.$("#paginate").length == 0) {
|
||||||
|
$(this.el).append($("<div>", {
|
||||||
|
"id" : "paginate"
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
this.$("#paginate").html($("<img>", {
|
this.$("#paginate").html($("<img>", {
|
||||||
src : "/images/static-loader.png",
|
src : "/images/static-loader.png",
|
||||||
"class" : 'loader'
|
"class" : "loader"
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue