From 7f440532a7e6f3c91b94707c2d547925d1cd4fac Mon Sep 17 00:00:00 2001 From: verg Date: Mon, 3 Mar 2014 17:42:48 -0500 Subject: [PATCH] Jump to First Post instead of Reloading Topic --- .../javascripts/discourse/controllers/header_controller.js | 7 +++++++ .../javascripts/discourse/controllers/topic_controller.js | 2 +- app/assets/javascripts/discourse/models/topic.js | 6 +++++- .../javascripts/discourse/templates/header.js.handlebars | 2 +- .../javascripts/discourse/templates/topic.js.handlebars | 2 +- 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/discourse/controllers/header_controller.js b/app/assets/javascripts/discourse/controllers/header_controller.js index cacc847e5ee..c037cafc020 100644 --- a/app/assets/javascripts/discourse/controllers/header_controller.js +++ b/app/assets/javascripts/discourse/controllers/header_controller.js @@ -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')); + } } } diff --git a/app/assets/javascripts/discourse/controllers/topic_controller.js b/app/assets/javascripts/discourse/controllers/topic_controller.js index 734855ccb79..bae43bbbccf 100644 --- a/app/assets/javascripts/discourse/controllers/topic_controller.js +++ b/app/assets/javascripts/discourse/controllers/topic_controller.js @@ -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() { diff --git a/app/assets/javascripts/discourse/models/topic.js b/app/assets/javascripts/discourse/models/topic.js index b55c6e3d97e..fcc5e6575b2 100644 --- a/app/assets/javascripts/discourse/models/topic.js +++ b/app/assets/javascripts/discourse/models/topic.js @@ -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'), diff --git a/app/assets/javascripts/discourse/templates/header.js.handlebars b/app/assets/javascripts/discourse/templates/header.js.handlebars index cc809fb00cf..66a13360fc1 100644 --- a/app/assets/javascripts/discourse/templates/header.js.handlebars +++ b/app/assets/javascripts/discourse/templates/header.js.handlebars @@ -19,7 +19,7 @@ {{boundCategoryLink topic.category}} {{#if topic.details.loaded}} {{topicStatus topic=topic}} - {{{topic.fancy_title}}} + {{{topic.fancy_title}}} {{else}} {{#if topic.errorLoading}} {{topic.errorTitle}} diff --git a/app/assets/javascripts/discourse/templates/topic.js.handlebars b/app/assets/javascripts/discourse/templates/topic.js.handlebars index 032a07e7e1d..210706123ad 100644 --- a/app/assets/javascripts/discourse/templates/topic.js.handlebars +++ b/app/assets/javascripts/discourse/templates/topic.js.handlebars @@ -35,7 +35,7 @@ {{boundCategoryLink category}} {{#if details.loaded}} {{topicStatus topic=model}} - + {{#if topicSaving}} {{fancy_title}} {{else}}