-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support shadow DOM and same-origin iframes
- Loading branch information
Dima Voytenko
committed
Jan 6, 2021
1 parent
4a14845
commit 323414b
Showing
10 changed files
with
2,241 additions
and
1,594 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,7 +1,7 @@ | ||
{ | ||
"name": "resize-observer-polyfill", | ||
"author": "Denis Rul <[email protected]>", | ||
"version": "1.5.1", | ||
"version": "1.5.2", | ||
"description": "A polyfill for the Resize Observer API", | ||
"main": "dist/ResizeObserver.js", | ||
"module": "dist/ResizeObserver.es.js", | ||
|
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,83 @@ | ||
import ResizeObserverController from './ResizeObserverController.js'; | ||
|
||
/** | ||
* Singleton controller class which handles updates of ResizeObserver instances. | ||
*/ | ||
export default class GlobalResizeObserverController { | ||
/** | ||
* A mapping from a DOM root node and a respective controller. A root node | ||
* could be the main document, a same-origin iframe, or a shadow root. | ||
* See https://developer.mozilla.org/en-US/docs/Web/API/Node/getRootNode | ||
* for more info. | ||
* | ||
* @private {Map<Node, ResizeObserverController>} | ||
*/ | ||
rootNodeControllers_ = typeof WeakMap !== 'undefined' ? new WeakMap() : new Map(); | ||
|
||
/** | ||
* Holds reference to the controller's instance. | ||
* | ||
* @private {GlobalResizeObserverController} | ||
*/ | ||
static instance_ = null; | ||
|
||
/** | ||
* Adds observer to observers list. | ||
* | ||
* @param {Node} rootNode - The root node for which the observer is added. | ||
* @param {ResizeObserverSPI} observer - Observer to be added. | ||
* @returns {void} | ||
*/ | ||
addObserver(rootNode, observer) { | ||
let rootNodeController = this.rootNodeControllers_.get(rootNode); | ||
|
||
if (!rootNodeController) { | ||
rootNodeController = new ResizeObserverController(rootNode, this); | ||
this.rootNodeControllers_.set(rootNode, rootNodeController); | ||
} | ||
rootNodeController.addObserver(observer); | ||
} | ||
|
||
/** | ||
* Removes observer from observers list. | ||
* | ||
* @param {Node} rootNode - The root node from which the observer is removed. | ||
* @param {ResizeObserverSPI} observer - Observer to be removed. | ||
* @returns {void} | ||
*/ | ||
removeObserver(rootNode, observer) { | ||
const rootNodeController = this.rootNodeControllers_.get(rootNode); | ||
|
||
if (rootNodeController) { | ||
rootNodeController.removeObserver(observer); | ||
} | ||
} | ||
|
||
/** | ||
* Invokes the update of observers. It will continue running updates insofar | ||
* it detects changes. | ||
* | ||
* @param {Node} rootNode - The root node to refresh. | ||
* @returns {void} | ||
*/ | ||
refresh(rootNode) { | ||
const rootNodeController = this.rootNodeControllers_.get(rootNode); | ||
|
||
if (rootNodeController) { | ||
rootNodeController.refresh(); | ||
} | ||
} | ||
|
||
/** | ||
* Returns instance of the GlobalResizeObserverController. | ||
* | ||
* @returns {GlobalResizeObserverController} | ||
*/ | ||
static getInstance() { | ||
if (!this.instance_) { | ||
this.instance_ = new GlobalResizeObserverController(); | ||
} | ||
|
||
return this.instance_; | ||
} | ||
} |
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.