Highlight posts when jumping to them.

This commit is contained in:
Robin Ward 2014-06-13 13:41:17 -04:00
parent 1876407db8
commit 42ca46e628
2 changed files with 28 additions and 17 deletions

View File

@ -179,6 +179,7 @@ Discourse.URL = Em.Object.createWithMixins({
enteredAt: new Date().getTime().toString()
});
topicProgressController.set('progressPosition', closest);
Discourse.PostView.considerHighlighting(topicController, closest);
}).then(function() {
Discourse.TopicView.jumpToPost(closest);
});

View File

@ -226,29 +226,18 @@ Discourse.PostView = Discourse.GroupedView.extend(Ember.Evented, {
didInsertElement: function() {
var $post = this.$(),
post = this.get('post'),
postNumber = post.get('post_number'),
highlightNumber = this.get('controller.highlightOnInsert');
// If we're meant to highlight a post
if ((highlightNumber > 1) && (highlightNumber === postNumber)) {
this.set('controller.highlightOnInsert', null);
var $contents = $('#post_' + postNumber +' .topic-body', $post),
origColor = $contents.data('orig-color') || $contents.css('backgroundColor');
$contents.data("orig-color", origColor);
$contents
.addClass('highlighted')
.stop()
.animate({ backgroundColor: origColor }, 2500, 'swing', function(){
$contents.removeClass('highlighted');
});
}
postNumber = post.get('post_number');
this.showLinkCounts();
// Track this post
Discourse.ScreenTrack.current().track(this.$().prop('id'), postNumber);
// Highlight the post if required
if (postNumber > 1) {
Discourse.PostView.considerHighlighting(this.get('controller'), postNumber);
}
// Add syntax highlighting
Discourse.SyntaxHighlighting.apply($post);
Discourse.Lightbox.apply($post);
@ -280,3 +269,24 @@ Discourse.PostView = Discourse.GroupedView.extend(Ember.Evented, {
}
}.observes('controller.searchHighlight', 'cooked')
});
Discourse.PostView.reopenClass({
considerHighlighting: function(controller, postNumber) {
var highlightNumber = controller.get('highlightOnInsert');
// If we're meant to highlight a post
if (highlightNumber === postNumber) {
controller.set('highlightOnInsert', null);
var $contents = $('#post_' + postNumber +' .topic-body'),
origColor = $contents.data('orig-color') || $contents.css('backgroundColor');
$contents.data("orig-color", origColor);
$contents
.addClass('highlighted')
.stop()
.animate({ backgroundColor: origColor }, 2500, 'swing', function(){
$contents.removeClass('highlighted');
});
}
}
});