summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Calviño Sánchez <danxuliu@gmail.com>2018-10-18 17:51:07 +0200
committerDaniel Calviño Sánchez <danxuliu@gmail.com>2018-11-20 12:16:43 +0100
commita9b40b9305ac10a51f6bd16c9af39a12d9d26d92 (patch)
treecf4e26ca1fb5ddd18b4969024a5aee456d9463d7
parent838cc20e9f8e7457cd733b58b336b684da933e1e (diff)
Keep a reference to the newest comment added
This avoids iterating over all the comments each time a new one is added. Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
-rw-r--r--js/views/chatview.js8
1 files changed, 5 insertions, 3 deletions
diff --git a/js/views/chatview.js b/js/views/chatview.js
index 690e92b80..f76148ad6 100644
--- a/js/views/chatview.js
+++ b/js/views/chatview.js
@@ -239,6 +239,8 @@
onRender: function() {
delete this._lastAddedMessageModel;
+ this._$newestComment = $();
+
this.$el.find('.emptycontent').after(this.addCommentTemplate({}));
this.$el.find('.has-tooltip').tooltip({container: this._tooltipContainer});
@@ -391,11 +393,11 @@
_onAddModel: function(model) {
this.$el.find('.emptycontent').toggleClass('hidden', true);
- var $newestComment = this.$container.children('.comment').last();
- var scrollToNew = $newestComment.length > 0 && this._getCommentTopPosition($newestComment) < this.$container.outerHeight();
+ var scrollToNew = this._$newestComment.length > 0 && this._getCommentTopPosition(this._$newestComment) < this.$container.outerHeight();
var $el = $(this.commentTemplate(this._formatItem(model)));
this.$container.append($el);
+ this._$newestComment = $el;
if (this._modelsHaveSameActor(this._lastAddedMessageModel, model) &&
this._modelsAreTemporaryNear(this._lastAddedMessageModel, model) &&
@@ -425,7 +427,7 @@
this._postRenderItem(model, $el);
if (scrollToNew) {
- var newestCommentHiddenHeight = (this._getCommentTopPosition($el) + this._getCommentOuterHeight($el)) - this.$container.outerHeight();
+ var newestCommentHiddenHeight = (this._getCommentTopPosition(this._$newestComment) + this._getCommentOuterHeight(this._$newestComment)) - this.$container.outerHeight();
this.$container.scrollTop(this.$container.scrollTop() + newestCommentHiddenHeight);
}
},