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.
This commit is contained in:
Robin Ward 2014-05-06 14:25:24 -04:00
parent 9e719e49da
commit 8a471d629e
1 changed files with 9 additions and 7 deletions

View File

@ -36,10 +36,7 @@ Discourse.PostView = Discourse.GroupedView.extend(Ember.Evented, {
// If the cooked content changed, add the quote controls // If the cooked content changed, add the quote controls
cookedChanged: function() { cookedChanged: function() {
var self = this; Em.run.scheduleOnce('afterRender', this, 'insertQuoteControls');
Em.run.schedule('afterRender', function() {
self.insertQuoteControls();
});
}.observes('post.cooked'), }.observes('post.cooked'),
mouseUp: function(e) { mouseUp: function(e) {
@ -186,8 +183,13 @@ Discourse.PostView = Discourse.GroupedView.extend(Ember.Evented, {
// Add the quote controls to a post // Add the quote controls to a post
insertQuoteControls: function() { insertQuoteControls: function() {
var self = this; var self = this,
return this.$('aside.quote').each(function(i, e) { $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); var $aside = $(e);
if ($aside.data('post')) { if ($aside.data('post')) {
self.updateQuoteElements($aside, 'chevron-down'); self.updateQuoteElements($aside, 'chevron-down');
@ -242,6 +244,6 @@ Discourse.PostView = Discourse.GroupedView.extend(Ember.Evented, {
this.trigger('postViewInserted', $post); this.trigger('postViewInserted', $post);
// Find all the quotes // Find all the quotes
this.insertQuoteControls(); Em.run.scheduleOnce('afterRender', this, 'insertQuoteControls');
} }
}); });