From f2a1ef8d7ddfd20fd9b6b3b465450a0b5d3d6779 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Tue, 10 Sep 2013 17:14:12 -0400 Subject: [PATCH] FIX: When expanding embedded replies, adjust the scroll position to not lose your place --- .../discourse/controllers/topic_controller.js | 18 ---------- .../discourse/templates/post.js.handlebars | 2 +- .../discourse/views/embedded_post_view.js | 3 +- .../javascripts/discourse/views/post_view.js | 33 +++++++++++++++++++ 4 files changed, 36 insertions(+), 20 deletions(-) diff --git a/app/assets/javascripts/discourse/controllers/topic_controller.js b/app/assets/javascripts/discourse/controllers/topic_controller.js index 8ff7c724c..27cc245c5 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 7077f869d..bc87acde1 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 b7c807fb1..cde2661bd 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 466c388ee..db155843e 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;