From 8a471d629e82c3b16e8e2db7363d976388234dbf Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Tue, 6 May 2014 14:25:24 -0400 Subject: [PATCH] FIX: Adds safety to painting on quote controls for elements that might not be present. This should fix an issue with not scrolling down after new posts are created sometimes. --- .../javascripts/discourse/views/post_view.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/discourse/views/post_view.js b/app/assets/javascripts/discourse/views/post_view.js index 393b4221e7e..8076cd08d55 100644 --- a/app/assets/javascripts/discourse/views/post_view.js +++ b/app/assets/javascripts/discourse/views/post_view.js @@ -36,10 +36,7 @@ Discourse.PostView = Discourse.GroupedView.extend(Ember.Evented, { // If the cooked content changed, add the quote controls cookedChanged: function() { - var self = this; - Em.run.schedule('afterRender', function() { - self.insertQuoteControls(); - }); + Em.run.scheduleOnce('afterRender', this, 'insertQuoteControls'); }.observes('post.cooked'), mouseUp: function(e) { @@ -186,8 +183,13 @@ Discourse.PostView = Discourse.GroupedView.extend(Ember.Evented, { // Add the quote controls to a post insertQuoteControls: function() { - var self = this; - return this.$('aside.quote').each(function(i, e) { + var self = this, + $quotes = this.$('aside.quote'); + + // Safety check - in some cases with cloackedView this seems to be `undefined`. + if (Em.isEmpty($quotes)) { return; } + + $quotes.each(function(i, e) { var $aside = $(e); if ($aside.data('post')) { self.updateQuoteElements($aside, 'chevron-down'); @@ -242,6 +244,6 @@ Discourse.PostView = Discourse.GroupedView.extend(Ember.Evented, { this.trigger('postViewInserted', $post); // Find all the quotes - this.insertQuoteControls(); + Em.run.scheduleOnce('afterRender', this, 'insertQuoteControls'); } });