diff options
author | Steffen van Bergerem <svbergerem@online.de> | 2016-09-02 01:18:15 +0300 |
---|---|---|
committer | Dennis Schubert <mail@dennis-schubert.de> | 2016-09-04 04:14:17 +0300 |
commit | e3e9510e6a67f680d12adea326c6aa0d8da89876 (patch) | |
tree | a080d4cf7b34870e6958ceb58130083978782836 /app/assets | |
parent | b3453c494ebdf866a0e51cf76ce899efaba92159 (diff) |
Refactor appending comments to the comment stream
Diffstat (limited to 'app/assets')
-rw-r--r-- | app/assets/javascripts/app/views/comment_stream_view.js | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/app/assets/javascripts/app/views/comment_stream_view.js b/app/assets/javascripts/app/views/comment_stream_view.js index 6878eec1a..6c3293c84 100644 --- a/app/assets/javascripts/app/views/comment_stream_view.js +++ b/app/assets/javascripts/app/views/comment_stream_view.js @@ -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) }); } }); |