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(); 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 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}}"> <article class='boxed' {{bindAttr id="postElementId"}} {{bindAttr data-post-id="id"}} data-user-id="{{unbound user_id}}">
<div class='row'> <div class='row'>
{{#if showUserReplyTab}} {{#if showUserReplyTab}}
<a href='#' {{action toggleReplyHistory this}} class='reply-to-tab'> <a href='#' {{action toggleReplyHistory this target="view"}} class='reply-to-tab'>
{{#if loadingReplyHistory}} {{#if loadingReplyHistory}}
{{i18n loading}} {{i18n loading}}
{{else}} {{else}}

View file

@ -11,7 +11,8 @@ Discourse.EmbeddedPostView = Discourse.GroupedView.extend({
classNames: ['reply'], classNames: ['reply'],
didInsertElement: function() { 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() { 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 // Add the quote controls to a post
insertQuoteControls: function() { insertQuoteControls: function() {
var postView = this; var postView = this;