Merge pull request #2050 from verg/unify_scroll_to_first_post

Scroll to Top of Topic instead of Reloading
This commit is contained in:
Sam 2014-03-05 11:22:54 +11:00
commit 24356cd807
5 changed files with 15 additions and 4 deletions

View File

@ -30,6 +30,13 @@ Discourse.HeaderController = Discourse.Controller.extend({
self.set("currentUser.unread_notifications", 0);
headerView.showDropdownBySelector("#user-notifications");
});
},
jumpToTopPost: function () {
var topic = this.get('topic');
if (topic) {
Discourse.URL.routeTo(topic.get('firstPostUrl'));
}
}
}

View File

@ -22,7 +22,7 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected
actions: {
jumpTop: function() {
Discourse.URL.routeTo(this.get('url'));
Discourse.URL.routeTo(this.get('firstPostUrl'));
},
jumpBottom: function() {

View File

@ -68,7 +68,7 @@ Discourse.Topic = Discourse.Model.extend({
// Helper to build a Url with a post number
urlForPostNumber: function(postNumber) {
var url = this.get('url');
if (postNumber && (postNumber > 1)) {
if (postNumber && (postNumber > 0)) {
if (postNumber >= this.get('highest_post_number')) {
url += "/last";
} else {
@ -91,6 +91,10 @@ Discourse.Topic = Discourse.Model.extend({
return this.urlForPostNumber(this.get('highest_post_number'));
}.property('url', 'highest_post_number'),
firstPostUrl: function () {
return this.urlForPostNumber(1);
}.property('url'),
lastPosterUrl: function() {
return Discourse.getURL("/users/") + this.get("last_poster.username");
}.property('last_poster'),

View File

@ -19,7 +19,7 @@
{{boundCategoryLink topic.category}}
{{#if topic.details.loaded}}
{{topicStatus topic=topic}}
<a class='topic-link' href='{{unbound topic.url}}'>{{{topic.fancy_title}}}</a>
<a class='topic-link' href='{{unbound topic.url}}' {{action jumpToTopPost}}>{{{topic.fancy_title}}}</a>
{{else}}
{{#if topic.errorLoading}}
{{topic.errorTitle}}

View File

@ -35,7 +35,7 @@
{{boundCategoryLink category}}
{{#if details.loaded}}
{{topicStatus topic=model}}
<a href='{{unbound url}}'>
<a href='{{unbound url}}' {{action jumpTop}}>
{{#if topicSaving}}
{{fancy_title}}
{{else}}