Skip to content

Commit 7a9245e

Browse files
makepanicRobbieTheWagner
authored andcommitted
fix: scroll hash anchor into view (ember-learn#403)
fixes ember-learn#228
1 parent af59a22 commit 7a9245e

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import Route from '@ember/routing/route';
2+
import { scheduleOnce } from '@ember/runloop';
3+
4+
export function initialize() {
5+
Route.reopen({
6+
afterModel() {
7+
this._super(...arguments);
8+
9+
const { hash } = location;
10+
if (hash && hash.length) {
11+
scheduleOnce('afterRender', null, () => {
12+
const anchor = document.querySelector(`a[href="${hash}"`);
13+
if (anchor) {
14+
anchor.scrollIntoView();
15+
}
16+
});
17+
}
18+
}
19+
})
20+
}
21+
22+
export default {
23+
initialize
24+
};

app/initializers/route-anchor-jump.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default, initialize } from 'ember-cli-addon-docs/initializers/route-anchor-jump';

0 commit comments

Comments
 (0)