Skip to content
Open
Changes from all commits
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
18 changes: 9 additions & 9 deletions src/smoothscroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,13 @@ function polyfill() {
if (shouldBailOut(arguments[0]) === true) {
original.scroll.call(
w,
arguments[0].left !== undefined
arguments[0] !== null && arguments[0].left !== undefined
? arguments[0].left
: typeof arguments[0] !== 'object'
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I noticed that the browser implementation of window.scrollTo handles null, whereas this ternary excludes null and passes a default of scrollX or pageXOffset.

: arguments[0] === null || typeof arguments[0] !== 'object'
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Update: Checking against null and allowing it to be passed through to the original scroll function. If this isn't desirable I can revert it.

? arguments[0]
: w.scrollX || w.pageXOffset,
// use top prop, second argument if present or fallback to scrollY
arguments[0].top !== undefined
arguments[0] !== null && arguments[0].top !== undefined
? arguments[0].top
: arguments[1] !== undefined
? arguments[1]
Expand Down Expand Up @@ -285,10 +285,10 @@ function polyfill() {
if (shouldBailOut(arguments[0])) {
original.scrollBy.call(
w,
arguments[0].left !== undefined
arguments[0] !== null && arguments[0].left !== undefined
? arguments[0].left
: typeof arguments[0] !== 'object' ? arguments[0] : 0,
arguments[0].top !== undefined
arguments[0] !== null && arguments[0].top !== undefined
? arguments[0].top
: arguments[1] !== undefined ? arguments[1] : 0
);
Expand Down Expand Up @@ -322,11 +322,11 @@ function polyfill() {
original.elementScroll.call(
this,
// use left prop, first number argument or fallback to scrollLeft
arguments[0].left !== undefined
arguments[0] !== null && arguments[0].left !== undefined
? ~~arguments[0].left
: typeof arguments[0] !== 'object' ? ~~arguments[0] : this.scrollLeft,
// use top prop, second argument or fallback to scrollTop
arguments[0].top !== undefined
arguments[0] !== null && arguments[0].top !== undefined
? ~~arguments[0].top
: arguments[1] !== undefined ? ~~arguments[1] : this.scrollTop
);
Expand Down Expand Up @@ -357,10 +357,10 @@ function polyfill() {
if (shouldBailOut(arguments[0]) === true) {
original.elementScroll.call(
this,
arguments[0].left !== undefined
arguments[0] !== null && arguments[0].left !== undefined
? ~~arguments[0].left + this.scrollLeft
: ~~arguments[0] + this.scrollLeft,
arguments[0].top !== undefined
arguments[0] !== null && arguments[0].top !== undefined
? ~~arguments[0].top + this.scrollTop
: ~~arguments[1] + this.scrollTop
);
Expand Down