FIX: Direct links to hash URLS were broken. Regression?
This commit is contained in:
parent
5aa411b58c
commit
fa25700400
|
@ -71,6 +71,20 @@ Discourse.URL = Em.Object.createWithMixins({
|
|||
}
|
||||
},
|
||||
|
||||
// Scroll to the same page, different anchor
|
||||
scrollToId: function(id) {
|
||||
if (Em.isEmpty(id)) { return; }
|
||||
|
||||
jumpScheduled = true;
|
||||
Em.run.schedule('afterRender', function() {
|
||||
var $elem = $(id);
|
||||
if ($elem.length > 0) {
|
||||
$('html,body').scrollTop($elem.offset().top - $('header').height() - 15);
|
||||
jumpScheduled = false;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
Our custom routeTo method is used to intelligently overwrite default routing
|
||||
behavior.
|
||||
|
@ -98,12 +112,7 @@ Discourse.URL = Em.Object.createWithMixins({
|
|||
|
||||
// Scroll to the same page, different anchor
|
||||
if (path.indexOf('#') === 0) {
|
||||
var $elem = $(path);
|
||||
if ($elem.length > 0) {
|
||||
Em.run.schedule('afterRender', function() {
|
||||
$('html,body').scrollTop($elem.offset().top - $('header').height() - 15);
|
||||
});
|
||||
}
|
||||
this.scrollToId(path);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,15 @@ Ember.DiscourseLocation = Ember.Object.extend({
|
|||
*/
|
||||
initState: function() {
|
||||
set(this, 'history', get(this, 'history') || window.history);
|
||||
this.replaceState(this.formatURL(this.getURL()));
|
||||
|
||||
var url = this.formatURL(this.getURL()),
|
||||
loc = get(this, 'location');
|
||||
|
||||
if (loc && loc.hash) {
|
||||
url += loc.hash;
|
||||
}
|
||||
|
||||
this.replaceState(url);
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -21,6 +21,13 @@ Discourse.StaticController.PAGES.forEach(function(page) {
|
|||
}
|
||||
},
|
||||
|
||||
activate: function() {
|
||||
this._super();
|
||||
|
||||
// Scroll to an element if exists
|
||||
Discourse.URL.scrollToId(document.location.hash);
|
||||
},
|
||||
|
||||
model: function() {
|
||||
return Discourse.StaticPage.find(page);
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue