Skip to content
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

Refactor #11

Merged
merged 2 commits into from
Jun 12, 2015
Merged

Conversation

jeremenichelli
Copy link
Collaborator

Suggestion

See diff in unified view.

Refactor

List of things improved:

  • documentation and comments for specific decisions
  • group all private functions at the top of the script for better organization and code readability
  • pass window, document and undefined variables to improve performance inside closure
  • modified bailOut method to return true if behavior is auto or undefined and throw error if behavior is not supported as Firefox does in its implementation of the standard
  • improve findScrollableParentmethod to stop if node is invalid and avoid crashing
  • group local variables declaration inside functions
  • group overrides at the end of the script

left other comments and explanations over the diff file

tested in Chrome 43

* @returns {Boolean}
*/
function bailOut(x) {
if (typeof x !== 'object' || x.behavior === undefined || x.behavior === 'auto' ) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Firefox falls back to original method if behavior is undefinedor auto.

@jeremenichelli
Copy link
Collaborator Author

Dont' hate me @iamdustan, I got excited...

// global frame variable to avoid collision
frame,
// global metric variables
startY, startX, endX, endY;
Copy link
Owner

Choose a reason for hiding this comment

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

is it possible to have multiple scrollBy/scrollTo’s going at once? I guess we’re only supporting those 3 scrolling methods and not element-with-overflow-scrolling.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not on the window object, but it could be possible that browsers allow scrolling in the window and an element, but I would have to test. Either way, functionality was not extended or modified.

@iamdustan
Copy link
Owner

👏👏 this is awesome @jeremenichelli. Great work.


// TODO: look into polyfilling scroll-behavior: smooth css property
Copy link
Owner

Choose a reason for hiding this comment

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

this TODO would still be a nice to have. I have what the perf implications of looking up a CSS property on every element is though.

We could maybe get away with it since we only support scrolling the entire document or Element.prototype.scrollIntoView.

First thought is that in either window.scrollTo/scrollBy method we look at the html and body tags for that css property and if it is set we return calling the same method with the scroll behavior set.

Copy link
Owner

Choose a reason for hiding this comment

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

Actually, by that point we could easily support it when Element.scrollBy support is added by checking for that behavior when called. No need to traverse the DOM looking for all of those elements. JIT property checks.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeap, I think is nitpicky but it would a nice-to-have and not that hard to implement.

Copy link
Owner

Choose a reason for hiding this comment

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

No need for that right now. I’ll take this PR as is. I made another issue (#12) for that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Roger that 👍

@iamdustan
Copy link
Owner

Once the couple nit/typos are corrected I’ll :shipit:

@jeremenichelli
Copy link
Collaborator Author

@iamdustan fixed typos, some bug on scrollIntoView and increase SCROLL_TIME value. Give it a last glance and let me know what you think.

iamdustan added a commit that referenced this pull request Jun 12, 2015
@iamdustan iamdustan merged commit 645d3ed into iamdustan:master Jun 12, 2015
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.

2 participants