Skip to content

Commit 42c02b5

Browse files
akashdsouzatoddjordan
authored andcommitted
[Bugfix]Fix autoscroll to methods issue (#321)
* [Bugfix]Fix autoscroll to methods issue * Do not include header height while calculating scroll offset
1 parent 80d9c6f commit 42c02b5

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

app/components/ember-anchor.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ export default AnchorComponent.extend({
1010
let qp = this.get('anchorQueryParam');
1111
let qpVal = this.get(get(this, 'attrs.a') ? 'a' : `controller.${qp}`);
1212
let elem = $(`[data-${qp}="${qpVal}"]`);
13-
let offset = (elem && elem.offset && elem.offset()) ? elem.offset().top : null;
13+
let offset = elem.offset() ? elem.offset().top : 0;
1414
if (offset) {
15-
const navMenuHeight = $('header').outerHeight();
16-
$(config.APP.scrollContainerSelector).scrollTop(offset - navMenuHeight - 10);
15+
$(config.APP.scrollContainerSelector).scrollTop(offset);
1716
}
1817
}
1918
});

app/mixins/scroll-tracker.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import Mixin from '@ember/object/mixin';
22
import { inject as service } from '@ember/service';
3+
import $ from 'jquery';
4+
import config from 'ember-api-docs/config/environment';
35

46
export default Mixin.create({
57

@@ -11,6 +13,15 @@ export default Mixin.create({
1113
},
1214

1315
didTransition() {
16+
this._super();
17+
if ((typeof FastBoot === 'undefined') && window.location.search === '?anchor=' ) {
18+
let elem = $('#methods');
19+
let offset = elem.offset() ? elem.offset().top : 0;
20+
if (offset) {
21+
$(config.APP.scrollContainerSelector).scrollTop(offset - 10);
22+
return;
23+
}
24+
}
1425
this.get('scrollPositionReset').doReset();
1526
}
1627
}

app/routes/project-version/namespaces/namespace.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import ClassRoute from '../classes/class';
2+
import ScrollTracker from 'ember-api-docs/mixins/scroll-tracker';
23

3-
export default ClassRoute.extend({
4+
export default ClassRoute.extend(ScrollTracker, {
45
templateName: 'project-version/classes/class',
56

67
model(params, transition) {

app/templates/project-version/classes/class.hbs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
model.project.id
4747
model.projectVersion.compactVersion
4848
model.name
49-
(query-params anchor="")
49+
(query-params anchor=undefined)
5050
class="tabbed-layout__menu__item"
5151
activeClass="tabbed-layout__menu__item_selected"
5252
current-when=(concat parentName ".index")
@@ -59,9 +59,10 @@
5959
model.project.id
6060
model.projectVersion.compactVersion
6161
model.name
62-
(query-params anchor="")
62+
(query-params anchor=undefined)
6363
class="tabbed-layout__menu__item"
6464
activeClass="tabbed-layout__menu__item_selected"
65+
id="methods"
6566
current-when=(concat parentName ".methods")
6667
data-test-tab="methods"
6768
}}
@@ -73,7 +74,7 @@
7374
model.project.id
7475
model.projectVersion.compactVersion
7576
model.name
76-
(query-params anchor="")
77+
(query-params anchor=undefined)
7778
class="tabbed-layout__menu__item"
7879
activeClass="tabbed-layout__menu__item_selected"
7980
current-when=(concat parentName ".properties")
@@ -87,7 +88,7 @@
8788
model.project.id
8889
model.projectVersion.compactVersion
8990
model.name
90-
(query-params anchor="")
91+
(query-params anchor=undefined)
9192
class="tabbed-layout__menu__item"
9293
activeClass="tabbed-layout__menu__item_selected"
9394
current-when=(concat parentName ".events")

0 commit comments

Comments
 (0)