ResizeObserverPolyfill (utils/dom)
@ckeditor/ckeditor5-utils/src/dom/resizeobserver
A polyfill class for the native ResizeObserver.
Filtering
Properties
-
protected readonly
_callback : functionmodule:utils/dom/resizeobserver~ResizeObserverPolyfill#_callbackA function called when any observed element was resized.
-
DOM elements currently observed by the observer instance.
-
protected readonly
_periodicCheckTimeout : Map.<HTMLElement, Rect>module:utils/dom/resizeobserver~ResizeObserverPolyfill#_periodicCheckTimeoutAn UID of the current timeout upon which the observed elements rects will be compared to the previous rects from the past.
-
protected readonly
_previousRects : Map.<HTMLElement, Rect>module:utils/dom/resizeobserver~ResizeObserverPolyfill#_previousRectsCached DOM elements bounding rects to compare to upon the next check.
Methods
-
constructor( callback )module:utils/dom/resizeobserver~ResizeObserverPolyfill#constructorCreates an instance of the
ResizeObserverPolyfillclass.It synchronously reacts to resize of the window to check if observed elements' geometry changed.
Additionally, the polyfilled observer uses a timeout to check if observed elements' geometry has changed in some other way (dynamic layouts, scrollbars showing up, etc.), so its response can also be asynchronous.
Parameters
callback : functionA function called when any observed element was resized. Refer to the native
ResizeObserverAPI to learn more.
-
observe( element )module:utils/dom/resizeobserver~ResizeObserverPolyfill#observeStarts observing a DOM element.
Learn more in the native method documentation.
Parameters
element : HTMLElement
-
unobserve( element )module:utils/dom/resizeobserver~ResizeObserverPolyfill#unobserveStops observing a DOM element.
Learn more in the native method documentation.
Parameters
element : HTMLElement
-
protected
_checkElementRectsAndExecuteCallback()module:utils/dom/resizeobserver~ResizeObserverPolyfill#_checkElementRectsAndExecuteCallbackChecks if the geometry of any of the element has changed. If so, executes the resize callback with element geometry data.
-
protected
_hasRectChanged( element ) → Booleanmodule:utils/dom/resizeobserver~ResizeObserverPolyfill#_hasRectChangedCompares the DOM element geometry to the cached geometry from the past. Returns
trueif geometry has changed or the element is checked for the first time.Parameters
element : HTMLElement
Returns
Boolean
-
protected
_startPeriodicCheck()module:utils/dom/resizeobserver~ResizeObserverPolyfill#_startPeriodicCheckWhen called, the observer calls the resize callback for all observed elements but also starts checking periodically for changes in the elements' geometry. If some are detected, resize callback is called for relevant elements that were resized.
-
protected
_stopPeriodicCheck()module:utils/dom/resizeobserver~ResizeObserverPolyfill#_stopPeriodicCheckStops checking for changes in all observed elements geometry.
Every day, we work hard to keep our documentation complete. Have you spotted outdated information? Is something missing? Please report it via our issue tracker.