Skip to content

[Bugfix]Fix autoscroll to methods issue #321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 31, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion app/mixins/scroll-tracker.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import Mixin from '@ember/object/mixin';
import { inject as service } from '@ember/service';
import $ from 'jquery';
import config from 'ember-api-docs/config/environment';

export default Mixin.create({

Expand All @@ -11,7 +13,18 @@ export default Mixin.create({
},

didTransition() {
this.get('scrollPositionReset').doReset();
this._super();
let isAnchorEmpty = window && window.location && window.location.search === '?anchor='
if ((typeof FastBoot === 'undefined') && isAnchorEmpty ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this seem hacky?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting anchor from the controller cannot be done from these places?
If we are not in FastBoot, it is safe to reach into window.location.search right away. (typeof FastBoot === 'undefined') && window.location.search === '?anchor=') should be fine.
This will also break if we have more than 1 queryParam, but this is probably fine. So far there no plans for adding more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. anchor is only available in child route's(methods) controller.
I will update the check

let elem = $('#methods');
let offset = (elem && elem.offset && elem.offset()) ? elem.offset().top : null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also overly defensive. If it's JQuery object, it is safe to assume that elem.offset will be a function even if the element is not found.

let offset = elem.offset() ? olem.offset().top : 0 should be fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated. Sorry about the delay

if (offset) {
const navMenuHeight = $('header').outerHeight();
$(config.APP.scrollContainerSelector).scrollTop(offset - navMenuHeight - 10);
Copy link
Contributor Author

@akashdsouza akashdsouza Aug 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since header is no longer a fixed element on the page, do we still need to take navMenuHeight into consideration? Having a little space above the method doesn't look all bad

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having a little space above the method doesn't look all bad

There will be less space if we remove it :). But let's do it, I think the anchor is gonna be more clear.

}
} else {
this.get('scrollPositionReset').doReset();
}
}
}
});
3 changes: 2 additions & 1 deletion app/routes/project-version/namespaces/namespace.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import ClassRoute from '../classes/class';
import ScrollTracker from 'ember-api-docs/mixins/scroll-tracker';

export default ClassRoute.extend({
export default ClassRoute.extend(ScrollTracker, {
templateName: 'project-version/classes/class',

model(params, transition) {
Expand Down
9 changes: 5 additions & 4 deletions app/templates/project-version/classes/class.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
model.project.id
model.projectVersion.compactVersion
model.name
(query-params anchor="")
(query-params anchor=undefined)
class="tabbed-layout__menu__item"
activeClass="tabbed-layout__menu__item_selected"
current-when=(concat parentName ".index")
Expand All @@ -60,9 +60,10 @@
model.project.id
model.projectVersion.compactVersion
model.name
(query-params anchor="")
(query-params anchor=undefined)
class="tabbed-layout__menu__item"
activeClass="tabbed-layout__menu__item_selected"
id="methods"
current-when=(concat parentName ".methods")
data-test-tab="methods"
}}
Expand All @@ -74,7 +75,7 @@
model.project.id
model.projectVersion.compactVersion
model.name
(query-params anchor="")
(query-params anchor=undefined)
class="tabbed-layout__menu__item"
activeClass="tabbed-layout__menu__item_selected"
current-when=(concat parentName ".properties")
Expand All @@ -88,7 +89,7 @@
model.project.id
model.projectVersion.compactVersion
model.name
(query-params anchor="")
(query-params anchor=undefined)
class="tabbed-layout__menu__item"
activeClass="tabbed-layout__menu__item_selected"
current-when=(concat parentName ".events")
Expand Down