-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(improvements): Bug fixes, support for scrolling via the scrollTo…
…p and scrollLeft setters, and more This version brings several improvements. First, the setters on Element.prototype for 'scrollLeft' and 'scrollTop' now works with the polyfill. If an element is within a scrolling box with a scroll-behavior of 'smooth', using these setters will now trigger smooth scrolling between the start and end positions. Additionally, part of the CSSOM View Module enhancements to the Element interface is proper standardizations of Element.prototype.scroll, Element.prototype.scrollTo, Element.prototype.scrollBy, and Element.protoype.scrollIntoView. These methods are all polyfilled with fallback within this polyfill for a unified scrolling API across browsers. Finally, a few bugs have been fixed
- Loading branch information
Showing
19 changed files
with
302 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface AdjustableElement extends Element { | ||
__adjustingScrollPosition?: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import {SUPPORTS_SCROLL_BEHAVIOR} from "./support/supports-scroll-behavior"; | ||
import {patch} from "./patch/patch"; | ||
import {SUPPORTS_ELEMENT_PROTOTYPE_SCROLL_METHODS} from "./support/supports-element-prototype-scroll-methods"; | ||
|
||
if (!SUPPORTS_SCROLL_BEHAVIOR) { | ||
if (!SUPPORTS_SCROLL_BEHAVIOR || !SUPPORTS_ELEMENT_PROTOTYPE_SCROLL_METHODS) { | ||
patch(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export const ELEMENT_ORIGINAL_SCROLL_BY = Element.prototype.scrollBy; | ||
export const ELEMENT_ORIGINAL_SCROLL_BY = Element.prototype.scrollBy; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const ELEMENT_ORIGINAL_SCROLL_LEFT_SET_DESCRIPTOR = Object.getOwnPropertyDescriptor(Element.prototype, "scrollLeft")!.set!; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const ELEMENT_ORIGINAL_SCROLL_TOP_SET_DESCRIPTOR = Object.getOwnPropertyDescriptor(Element.prototype, "scrollTop")!.set!; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import {handleScrollMethod} from "../shared"; | ||
import {ELEMENT_ORIGINAL_SCROLL_LEFT_SET_DESCRIPTOR} from "../../original/element/scroll-left"; | ||
|
||
/** | ||
* Patches the 'scrollLeft' property descriptor on the Element prototype | ||
*/ | ||
export function patchElementScrollLeft (): void { | ||
|
||
Object.defineProperty(Element.prototype, "scrollLeft", { | ||
set (scrollLeft: number) { | ||
if (this.__adjustingScrollPosition) { | ||
return ELEMENT_ORIGINAL_SCROLL_LEFT_SET_DESCRIPTOR.call(this, scrollLeft); | ||
} | ||
|
||
handleScrollMethod(this, "scrollTo", scrollLeft, this.scrollTop); | ||
return scrollLeft; | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import {handleScrollMethod} from "../shared"; | ||
import {ELEMENT_ORIGINAL_SCROLL_TOP_SET_DESCRIPTOR} from "../../original/element/scroll-top"; | ||
|
||
/** | ||
* Patches the 'scrollTop' property descriptor on the Element prototype | ||
*/ | ||
export function patchElementScrollTop(): void { | ||
|
||
Object.defineProperty(Element.prototype, "scrollTop", { | ||
set (scrollTop: number) { | ||
if (this.__adjustingScrollPosition) { | ||
return ELEMENT_ORIGINAL_SCROLL_TOP_SET_DESCRIPTOR.call(this, scrollTop); | ||
} | ||
|
||
handleScrollMethod(this, "scrollTo", this.scrollLeft, scrollTop); | ||
return scrollTop; | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.