- Notifications
You must be signed in to change notification settings - Fork 516
Support iframe viewport tracking #465
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
philipwalton merged 10 commits into w3c:master from samouri:support-iframe-viewport-tracking Dec 10, 2020
Merged
Changes from 4 commits
Commits
Show all changes
10 commits Select commit Hold shift + click to select a range
67723f2 polyfill: support iframe viewport tracking
samouri b1a4e50 add unit tests
samouri 3d1147f recomment
samouri b356b47 address most comments from dvoytenko
samouri bf707a4 update with rect tests
samouri a591735 support returning zeros rect rootbounds for cross-document
samouri 8e9227f two small fixes
samouri 6298663 Bump version vfom 0.11.0 --> 0.12.0
samouri 000ca37 address dvoytenko comments
samouri 77d813a duplicate rootMargin test for same-origin
samouri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| | @@ -131,8 +131,12 @@ function IntersectionObserver(callback, opt_options) { | |
| throw new Error('callback must be a function'); | ||
| } | ||
| | ||
| if (options.root && options.root.nodeType != 1) { | ||
| throw new Error('root must be an Element'); | ||
| if ( | ||
| options.root && | ||
| options.root.nodeType != 1 && | ||
| options.root.nodeType != 9 | ||
| ) { | ||
| throw new Error('root must be a Document or Element'); | ||
| } | ||
| | ||
| // Binds and throttles `this._checkForIntersections`. | ||
| | @@ -395,7 +399,9 @@ IntersectionObserver.prototype._monitorIntersections = function(doc) { | |
| }); | ||
| | ||
| // Also monitor the parent. | ||
| if (doc != (this.root && this.root.ownerDocument || document)) { | ||
| var rootDoc = | ||
| (this.root && (this.root.ownerDocument || this.root)) || document; | ||
| if (doc != rootDoc) { | ||
| var frame = getFrameElement(doc); | ||
| if (frame) { | ||
| this._monitorIntersections(frame.ownerDocument); | ||
| | @@ -415,7 +421,8 @@ IntersectionObserver.prototype._unmonitorIntersections = function(doc) { | |
| return; | ||
| } | ||
| | ||
| var rootDoc = (this.root && this.root.ownerDocument || document); | ||
| var rootDoc = | ||
| (this.root && (this.root.ownerDocument || this.root)) || document; | ||
| | ||
| // Check if any dependent targets are still remaining. | ||
| var hasDependentTargets = | ||
| | @@ -618,19 +625,20 @@ IntersectionObserver.prototype._computeTargetAndRootIntersection = | |
| */ | ||
| IntersectionObserver.prototype._getRootRect = function() { | ||
| var rootRect; | ||
| if (this.root) { | ||
| if (this.root && !isDoc(this.root)) { | ||
samouri marked this conversation as resolved. Show resolved Hide resolved | ||
| rootRect = getBoundingClientRect(this.root); | ||
| } else { | ||
| // Use <html>/<body> instead of window since scroll bars affect size. | ||
| var html = document.documentElement; | ||
| var body = document.body; | ||
| var doc = isDoc(this.root) ? this.root : document; | ||
| var html = doc.documentElement; | ||
| var body = doc.body; | ||
| rootRect = { | ||
| top: 0, | ||
| left: 0, | ||
| right: html.clientWidth || body.clientWidth, | ||
| width: html.clientWidth || body.clientWidth, | ||
| bottom: html.clientHeight || body.clientHeight, | ||
| height: html.clientHeight || body.clientHeight | ||
| height: html.clientHeight || body.clientHeight, | ||
| ||
| }; | ||
| } | ||
| return this._expandRectByRootMargin(rootRect); | ||
| | @@ -714,8 +722,12 @@ IntersectionObserver.prototype._rootIsInDom = function() { | |
| * @private | ||
| */ | ||
| IntersectionObserver.prototype._rootContainsTarget = function(target) { | ||
| return containsDeep(this.root || document, target) && | ||
| (!this.root || this.root.ownerDocument == target.ownerDocument); | ||
| var rootDoc = | ||
| (this.root && (this.root.ownerDocument || this.root)) || document; | ||
| return ( | ||
| containsDeep(this.root || rootDoc, target) && | ||
| (!this.root || rootDoc == target.ownerDocument) | ||
| ); | ||
| }; | ||
| | ||
| | ||
| | @@ -978,6 +990,10 @@ function getParentNode(node) { | |
| return parent; | ||
| } | ||
| | ||
| function isDoc(node) { | ||
samouri marked this conversation as resolved. Show resolved Hide resolved | ||
| return node && node.nodeType === 9; | ||
| } | ||
| | ||
| | ||
| // Exposes the constructors globally. | ||
| window.IntersectionObserver = IntersectionObserver; | ||
| | ||
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.