FIX: When expanding embedded replies, adjust the scroll position to not lose your place

This commit is contained in:
Robin Ward 2013-09-10 17:14:12 -04:00
parent cc2acafc9a
commit f2a1ef8d7d
4 changed files with 36 additions and 20 deletions

View File

@ -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

View File

@ -5,7 +5,7 @@
<article class='boxed' {{bindAttr id="postElementId"}} {{bindAttr data-post-id="id"}} data-user-id="{{unbound user_id}}">
<div class='row'>
{{#if showUserReplyTab}}
<a href='#' {{action toggleReplyHistory this}} class='reply-to-tab'>
<a href='#' {{action toggleReplyHistory this target="view"}} class='reply-to-tab'>
{{#if loadingReplyHistory}}
{{i18n loading}}
{{else}}

View File

@ -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() {

View File

@ -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;