FIX: Jumping within a topic should respect anchors

This commit is contained in:
Robin Ward 2016-07-20 14:39:26 -04:00
parent b9177af1eb
commit e09a304122
1 changed files with 14 additions and 4 deletions

View File

@ -5,10 +5,11 @@ import { defaultHomepage } from 'discourse/lib/utilities';
let _jumpScheduled = false; let _jumpScheduled = false;
const rewrites = []; const rewrites = [];
const TOPIC_REGEXP = /\/t\/([^\/]+)\/(\d+)\/?(\d+)?/;
const DiscourseURL = Ember.Object.extend({ const DiscourseURL = Ember.Object.extend({
// Used for matching a topic // Used for matching a topic
TOPIC_REGEXP: /\/t\/([^\/]+)\/(\d+)\/?(\d+)?/,
isJumpScheduled: function() { isJumpScheduled: function() {
return _jumpScheduled; return _jumpScheduled;
@ -207,11 +208,11 @@ const DiscourseURL = Ember.Object.extend({
same topic, use replaceState and instruct our controller to load more posts. same topic, use replaceState and instruct our controller to load more posts.
**/ **/
navigatedToPost(oldPath, path, routeOpts) { navigatedToPost(oldPath, path, routeOpts) {
const newMatches = this.TOPIC_REGEXP.exec(path); const newMatches = TOPIC_REGEXP.exec(path);
const newTopicId = newMatches ? newMatches[2] : null; const newTopicId = newMatches ? newMatches[2] : null;
if (newTopicId) { if (newTopicId) {
const oldMatches = this.TOPIC_REGEXP.exec(oldPath); const oldMatches = TOPIC_REGEXP.exec(oldPath);
const oldTopicId = oldMatches ? oldMatches[2] : null; const oldTopicId = oldMatches ? oldMatches[2] : null;
// If the topic_id is the same // If the topic_id is the same
@ -237,7 +238,16 @@ const DiscourseURL = Ember.Object.extend({
this.appEvents.trigger('post:highlight', closest); this.appEvents.trigger('post:highlight', closest);
}).then(() => { }).then(() => {
DiscourseURL.jumpToPost(closest, {skipIfOnScreen: routeOpts.skipIfOnScreen}); const jumpOpts = {
skipIfOnScreen: routeOpts.skipIfOnScreen
};
const m = /#.+$/.exec(path);
if (m) {
jumpOpts.anchor = m[0];
}
this.jumpToPost(closest, jumpOpts);
}); });
// Abort routing, we have replaced our state. // Abort routing, we have replaced our state.