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

Conversation

akashdsouza
Copy link
Contributor

If this looks ok, I can add the same to /methods under classes and modules(perhaps in a mixin?).

@locks locks temporarily deployed to ember-api-docs-staging-pr-321 August 11, 2017 02:49 Inactive
@sivakumar-kailasam
Copy link
Member

Fixes #318

actions: {
didTransition() {
this._super();
if ((typeof FastBoot === 'undefined') && isEmpty(this.get('controller.anchor'))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think I've mentioned it before somewhere. isEmpty(this.get('controller.anchor')) this will probably result in scroll jump unless there is anchor specifically set up. Which is probably not a good behavior.

@sivakumar-kailasam @locks
Do we need to have backward compatibility on this? Or could we come up with a more specific anchor for scrolling to methods?

Copy link
Member

Choose a reason for hiding this comment

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

Unfortunately we do. There's just so many old links out there outside our website that refer to the old doc urls. We can probably do an analysis of google analytics metrics to see the trends few months down the line and make changes but until then we have to keep at this.

Copy link
Contributor

Choose a reason for hiding this comment

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

@akashdsouza
Oh okay. Then I think we need to specifically check for null or "" (or both?) so it only detects just ?anchor=

Copy link
Contributor

Choose a reason for hiding this comment

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

Hopefully, that will work and there won't be a need to look into location.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright. I will update the check.
Should I use a data-attribute instead of id for scrolling to the tab?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think ID is 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

@locks locks temporarily deployed to ember-api-docs-staging-pr-321 August 16, 2017 18:24 Inactive
@akashdsouza akashdsouza force-pushed the bugfix_autoscroll_methods branch from c7dd461 to 3daf6e6 Compare August 16, 2017 20:03
@locks locks temporarily deployed to ember-api-docs-staging-pr-321 August 16, 2017 20:03 Inactive
@akashdsouza
Copy link
Contributor Author

This might have to wait until #322 is merged

@akashdsouza akashdsouza force-pushed the bugfix_autoscroll_methods branch from 3daf6e6 to d418399 Compare August 17, 2017 19:52
@locks locks temporarily deployed to ember-api-docs-staging-pr-321 August 17, 2017 19:52 Inactive
$(config.APP.scrollContainerSelector).scrollTop(offset - navMenuHeight - 10);
}
} else {
this.get('scrollPositionReset').doReset();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is the reset needed if there's no anchor?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To retain the behavior available here:

this.get('scrollPositionReset').doReset();

Earlier, as there was no didTransition in /methods, didTransition above would have been called.

@@ -1,5 +1,6 @@
import Route from '@ember/routing/route';
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the correct place to put the Mixin would be project-version/classes/class.js and project-version/modules/module.js and project-version/namespaces/namespace.js. That should cover all cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is already a scroll-tracker mixin in these routes to reset scrolling. How would this need to be handled? Remove the scroll reset altogether as it is present in scroll-page mixin?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we could actually add this logic to the Scroll Tracker mixin itself. It is already at the right places - maybe it will just need to be added to namespaces/namespace.js.

@MartinMalinda
Copy link
Contributor

MartinMalinda commented Aug 17, 2017

Works well, but the Mixin should be put in different places as I've suggested above, otherwise, the scroll jump may not happen in various places.

I think we should also consider updating these query params

There is a query-param reset like this (query-params anchor=""). I think the reason for that was so there would not be a random jump to some method - but now it causes a scroll jump to the tab element. (query-params anchor=undefined) should be a better alternative now.

scroll-jump

@akashdsouza akashdsouza force-pushed the bugfix_autoscroll_methods branch from d418399 to e4f1924 Compare August 18, 2017 03:08
@locks locks temporarily deployed to ember-api-docs-staging-pr-321 August 18, 2017 03:09 Inactive
@akashdsouza akashdsouza force-pushed the bugfix_autoscroll_methods branch from e4f1924 to 24391cf Compare August 18, 2017 03:45
@locks locks temporarily deployed to ember-api-docs-staging-pr-321 August 18, 2017 03:45 Inactive
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 offset = (elem && elem.offset && elem.offset()) ? elem.offset().top : null;
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.

@locks locks temporarily deployed to ember-api-docs-staging-pr-321 August 18, 2017 07:01 Inactive
@akashdsouza
Copy link
Contributor Author

Updated

this._super();
if ((typeof FastBoot === 'undefined') && window.location.search === '?anchor=' ) {
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

@MartinMalinda
Copy link
Contributor

Works well 💯 The offset check could be simplified but it's also fine as is.

@akashdsouza akashdsouza force-pushed the bugfix_autoscroll_methods branch from d7815d6 to 43d462f Compare August 20, 2017 18:08
@locks locks temporarily deployed to ember-api-docs-staging-pr-321 August 20, 2017 18:09 Inactive
@locks locks temporarily deployed to ember-api-docs-staging-pr-321 August 31, 2017 16:40 Inactive
@toddjordan
Copy link
Contributor

looks good, thanks @akashdsouza !!!

@toddjordan toddjordan merged commit 42c02b5 into ember-learn:master Aug 31, 2017
lifeart pushed a commit to lifeart/ember-api-docs that referenced this pull request Apr 18, 2018
* [Bugfix]Fix autoscroll to methods issue

* Do not include header height while calculating scroll offset
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants