-
-
Notifications
You must be signed in to change notification settings - Fork 115
/
Copy pathscroll-tracker.js
42 lines (38 loc) · 1.17 KB
/
scroll-tracker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import Mixin from '@ember/object/mixin';
import { inject as service } from '@ember/service';
import config from 'ember-api-docs/config/environment';
import getOffset from 'ember-api-docs/utils/get-offset';
export default Mixin.create({
scrollPositionReset: service(),
actions: {
willTransition(transition) {
this.scrollPositionReset.scheduleReset(transition);
},
didTransition() {
this._super();
if (
typeof FastBoot === 'undefined' &&
window.location.search === '?anchor='
) {
let elem = document.querySelector('#methods');
if (elem && elem.offsetHeight) {
const offsetToScroll = getOffset(
elem,
config.APP.scrollContainerSelector
);
const scrollContainer = document.querySelector(
config.APP.scrollContainerSelector
);
if (scrollContainer.scrollTo) {
scrollContainer.scrollTo(0, offsetToScroll - 10);
} else {
// fallback for IE11
scrollContainer.scrollTop = offsetToScroll - 10;
}
return;
}
}
this.scrollPositionReset.doReset();
},
},
});