diff --git a/app/assets/javascripts/discourse/controllers/topic_controller.js b/app/assets/javascripts/discourse/controllers/topic_controller.js index 8ff7c724caf..27cc245c530 100644 --- a/app/assets/javascripts/discourse/controllers/topic_controller.js +++ b/app/assets/javascripts/discourse/controllers/topic_controller.js @@ -308,24 +308,6 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected this.get('content').toggleStar(); }, - /** - Toggle the replies this post is a reply to - - @method showReplyHistory - **/ - toggleReplyHistory: function(post) { - var replyHistory = post.get('replyHistory'), - topicController = this; - - if (replyHistory.length > 0) { - replyHistory.clear(); - } else { - post.set('loadingReplyHistory', true); - topicController.get('postStream').findReplyHistory(post).then(function () { - post.set('loadingReplyHistory', false); - }); - } - }, /** Clears the pin from a topic for the currently logged in user diff --git a/app/assets/javascripts/discourse/templates/post.js.handlebars b/app/assets/javascripts/discourse/templates/post.js.handlebars index 7077f869d6f..bc87acde1a2 100644 --- a/app/assets/javascripts/discourse/templates/post.js.handlebars +++ b/app/assets/javascripts/discourse/templates/post.js.handlebars @@ -5,7 +5,7 @@
{{#if showUserReplyTab}} - + {{#if loadingReplyHistory}} {{i18n loading}} {{else}} diff --git a/app/assets/javascripts/discourse/views/embedded_post_view.js b/app/assets/javascripts/discourse/views/embedded_post_view.js index b7c807fb17c..cde2661bd06 100644 --- a/app/assets/javascripts/discourse/views/embedded_post_view.js +++ b/app/assets/javascripts/discourse/views/embedded_post_view.js @@ -11,7 +11,8 @@ Discourse.EmbeddedPostView = Discourse.GroupedView.extend({ classNames: ['reply'], didInsertElement: function() { - Discourse.ScreenTrack.current().track(this.get('elementId'), this.get('post.post_number')); + var post = this.get('content'); + Discourse.ScreenTrack.current().track(this.get('elementId'), post.get('post_number')); }, willDestroyElement: function() { diff --git a/app/assets/javascripts/discourse/views/post_view.js b/app/assets/javascripts/discourse/views/post_view.js index 466c388ee3a..db155843ef9 100644 --- a/app/assets/javascripts/discourse/views/post_view.js +++ b/app/assets/javascripts/discourse/views/post_view.js @@ -135,6 +135,39 @@ Discourse.PostView = Discourse.GroupedView.extend({ } }, + /** + Toggle the replies this post is a reply to + + @method showReplyHistory + **/ + toggleReplyHistory: function(post) { + + var replyHistory = post.get('replyHistory'), + topicController = this.get('controller'), + origScrollTop = $(window).scrollTop(); + + + if (replyHistory.length > 0) { + var origHeight = this.$('.embedded-posts.top').height(); + + replyHistory.clear(); + Em.run.next(function() { + $(window).scrollTop(origScrollTop - origHeight); + }); + } else { + post.set('loadingReplyHistory', true); + + var self = this; + topicController.get('postStream').findReplyHistory(post).then(function () { + post.set('loadingReplyHistory', false); + + Em.run.next(function() { + $(window).scrollTop(origScrollTop + self.$('.embedded-posts.top').height()); + }); + }); + } + }, + // Add the quote controls to a post insertQuoteControls: function() { var postView = this;