Refactor appending comments to the comment stream
This commit is contained in:
parent
b3453c494e
commit
e3e9510e6a
1 changed files with 6 additions and 9 deletions
|
|
@ -86,12 +86,13 @@ app.views.CommentStream = app.views.Base.extend({
|
||||||
var commentHtml = new app.views.Comment({model: comment}).render().el;
|
var commentHtml = new app.views.Comment({model: comment}).render().el;
|
||||||
var commentBlocks = this.$(".comments div.comment.media");
|
var commentBlocks = this.$(".comments div.comment.media");
|
||||||
this._moveInsertPoint(comment.get("created_at"), commentBlocks);
|
this._moveInsertPoint(comment.get("created_at"), commentBlocks);
|
||||||
if (this._insertPoint === commentBlocks.length) {
|
if (this._insertPoint >= commentBlocks.length) {
|
||||||
this.$(".comments").append(commentHtml);
|
this.$(".comments").append(commentHtml);
|
||||||
|
} else if (this._insertPoint <= 0) {
|
||||||
|
this.$(".comments").prepend(commentHtml);
|
||||||
} else {
|
} else {
|
||||||
commentBlocks.eq(this._insertPoint).before(commentHtml);
|
commentBlocks.eq(this._insertPoint).before(commentHtml);
|
||||||
}
|
}
|
||||||
this._insertPoint++;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
commentTextareaFocused: function(){
|
commentTextareaFocused: function(){
|
||||||
|
|
@ -100,14 +101,10 @@ app.views.CommentStream = app.views.Base.extend({
|
||||||
|
|
||||||
expandComments: function(evt){
|
expandComments: function(evt){
|
||||||
if(evt){ evt.preventDefault(); }
|
if(evt){ evt.preventDefault(); }
|
||||||
var self = this;
|
|
||||||
|
|
||||||
this.model.comments.fetch({
|
this.model.comments.fetch({
|
||||||
success : function(resp){
|
success: function() {
|
||||||
self.$("div.comment.show_comments").addClass("hidden");
|
this.$("div.comment.show_comments").addClass("hidden");
|
||||||
|
}.bind(this)
|
||||||
self.model.trigger("commentsExpanded", self);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue