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

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

parent 79208e90
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -5,15 +5,14 @@ App.Router = Backbone.Router.extend({ ...@@ -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();
} }
}); });
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({ ...@@ -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"
})); }));
} }
}); });
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter