Refactor appending comments to the comment stream

This commit is contained in:
Steffen van Bergerem 2016-09-02 00:18:15 +02:00 committed by Dennis Schubert
parent b3453c494e
commit e3e9510e6a
No known key found for this signature in database
GPG key ID: 5A0304BEA7966D7E

View file

@ -86,12 +86,13 @@ app.views.CommentStream = app.views.Base.extend({
var commentHtml = new app.views.Comment({model: comment}).render().el;
var commentBlocks = this.$(".comments div.comment.media");
this._moveInsertPoint(comment.get("created_at"), commentBlocks);
if (this._insertPoint === commentBlocks.length) {
if (this._insertPoint >= commentBlocks.length) {
this.$(".comments").append(commentHtml);
} else if (this._insertPoint <= 0) {
this.$(".comments").prepend(commentHtml);
} else {
commentBlocks.eq(this._insertPoint).before(commentHtml);
}
this._insertPoint++;
},
commentTextareaFocused: function(){
@ -100,14 +101,10 @@ app.views.CommentStream = app.views.Base.extend({
expandComments: function(evt){
if(evt){ evt.preventDefault(); }
var self = this;
this.model.comments.fetch({
success : function(resp){
self.$("div.comment.show_comments").addClass("hidden");
self.model.trigger("commentsExpanded", self);
}
success: function() {
this.$("div.comment.show_comments").addClass("hidden");
}.bind(this)
});
}
});