diff --git a/app/assets/javascripts/discourse/lib/keyboard_shortcuts.js b/app/assets/javascripts/discourse/lib/keyboard_shortcuts.js index 6b19db16a46..a90a1c0b89e 100644 --- a/app/assets/javascripts/discourse/lib/keyboard_shortcuts.js +++ b/app/assets/javascripts/discourse/lib/keyboard_shortcuts.js @@ -224,7 +224,7 @@ Discourse.KeyboardShortcuts = Ember.Object.createWithMixins({ if (rgx === null || typeof rgx[1] === 'undefined') { this._scrollList($article, direction); } else { - Discourse.TopicView.jumpToPost(rgx[1]); + Discourse.URL.jumpToPost(rgx[1]); } } }, diff --git a/app/assets/javascripts/discourse/lib/url.js b/app/assets/javascripts/discourse/lib/url.js index 60d926394d8..b499c53e017 100644 --- a/app/assets/javascripts/discourse/lib/url.js +++ b/app/assets/javascripts/discourse/lib/url.js @@ -1,3 +1,4 @@ +/*global LockOn:true*/ /** URL related functions. @@ -10,6 +11,29 @@ Discourse.URL = Em.Object.createWithMixins({ // Used for matching a topic TOPIC_REGEXP: /\/t\/([^\/]+)\/(\d+)\/?(\d+)?/, + /** + Jumps to a particular post in the stream + **/ + jumpToPost: function(postNumber) { + var holderId = '#post-cloak-' + postNumber; + + Em.run.schedule('afterRender', function() { + if (postNumber === 1) { + $(window).scrollTop(0); + return; + } + + new LockOn(holderId, {offsetCalculator: function() { + var $header = $('header'), + $title = $('#topic-title'), + windowHeight = $(window).height() - $title.height(), + expectedOffset = $title.height() - $header.find('.contents').height() + (windowHeight / 5); + + return $header.outerHeight(true) + ((expectedOffset < 0) ? 0 : expectedOffset); + }}).lock(); + }); + }, + /** Browser aware replaceState. Will only be invoked if the browser supports it. @@ -181,7 +205,7 @@ Discourse.URL = Em.Object.createWithMixins({ topicProgressController.set('progressPosition', closest); Discourse.PostView.considerHighlighting(topicController, closest); }).then(function() { - Discourse.TopicView.jumpToPost(closest); + Discourse.URL.jumpToPost(closest); }); // Abort routing, we have replaced our state. diff --git a/app/assets/javascripts/discourse/routes/topic_from_params_route.js b/app/assets/javascripts/discourse/routes/topic_from_params_route.js index 4dc652ce04e..e6fa7c41b5e 100644 --- a/app/assets/javascripts/discourse/routes/topic_from_params_route.js +++ b/app/assets/javascripts/discourse/routes/topic_from_params_route.js @@ -35,7 +35,7 @@ Discourse.TopicFromParamsRoute = Discourse.Route.extend({ progressPosition: closest, expanded: false }); - Discourse.TopicView.jumpToPost(closest); + Discourse.URL.jumpToPost(closest); if (topic.present('draft')) { composerController.open({ diff --git a/app/assets/javascripts/discourse/views/topic_view.js b/app/assets/javascripts/discourse/views/topic.js.es6 similarity index 85% rename from app/assets/javascripts/discourse/views/topic_view.js rename to app/assets/javascripts/discourse/views/topic.js.es6 index 593d29a114f..25e376dfa53 100644 --- a/app/assets/javascripts/discourse/views/topic_view.js +++ b/app/assets/javascripts/discourse/views/topic.js.es6 @@ -1,15 +1,6 @@ -/*global LockOn:true*/ +import AddCategoryClass from 'discourse/mixins/add-category-class'; -/** - This view is for rendering an icon representing the status of a topic - - @class TopicView - @extends Discourse.View - @namespace Discourse - @uses Discourse.Scrolling - @module Discourse -**/ -Discourse.TopicView = Discourse.View.extend(Discourse.Scrolling, { +export default Discourse.View.extend(AddCategoryClass, Discourse.Scrolling, { templateName: 'topic', topicBinding: 'controller.model', userFiltersBinding: 'controller.userFilters', @@ -21,6 +12,8 @@ Discourse.TopicView = Discourse.View.extend(Discourse.Scrolling, { menuVisible: true, SHORT_POST: 1200, + categoryId: Em.computed.alias('topic.category.id'), + postStream: Em.computed.alias('controller.postStream'), _updateTitle: function() { @@ -186,29 +179,4 @@ Discourse.TopicView = Discourse.View.extend(Discourse.Scrolling, { return I18n.t("topic.read_more", opts); } }.property('topicTrackingState.messageCount') - -}); - -Discourse.TopicView.reopenClass({ - - jumpToPost: function(postNumber) { - var holderId = '#post-cloak-' + postNumber; - - Em.run.schedule('afterRender', function() { - if (postNumber === 1) { - $(window).scrollTop(0); - return; - } - - new LockOn(holderId, {offsetCalculator: function() { - var $header = $('header'), - $title = $('#topic-title'), - windowHeight = $(window).height() - $title.height(), - expectedOffset = $title.height() - $header.find('.contents').height() + (windowHeight / 5); - - return $header.outerHeight(true) + ((expectedOffset < 0) ? 0 : expectedOffset); - }}).lock(); - }); - } - });