ResizeObserverPolyfill (utils/dom)
@ckeditor/ckeditor5-utils/src/dom/resizeobserver
A polyfill class for the native ResizeObserver
.
Filtering
Properties
-
_callback : function
module:utils/dom/resizeobserver~ResizeObserverPolyfill#_callback
protected readonly
A function called when any observed element was resized.
-
_elements : Set
module:utils/dom/resizeobserver~ResizeObserverPolyfill#_elements
protected readonly
DOM elements currently observed by the observer instance.
-
_periodicCheckTimeout : Map.<HTMLElement, Rect>
module:utils/dom/resizeobserver~ResizeObserverPolyfill#_periodicCheckTimeout
protected readonly
An UID of the current timeout upon which the observed elements rects will be compared to the previous rects from the past.
-
_previousRects : Map.<HTMLElement, Rect>
module:utils/dom/resizeobserver~ResizeObserverPolyfill#_previousRects
protected readonly
Cached DOM elements bounding rects to compare to upon the next check.
Methods
-
constructor( callback )
module:utils/dom/resizeobserver~ResizeObserverPolyfill#constructor
Creates an instance of the
ResizeObserverPolyfill
class.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 : function
A function called when any observed element was resized. Refer to the native
ResizeObserver
API to learn more.
-
observe( element )
module:utils/dom/resizeobserver~ResizeObserverPolyfill#observe
Starts observing a DOM element.
-
unobserve( element )
module:utils/dom/resizeobserver~ResizeObserverPolyfill#unobserve
Stops observing a DOM element.
-
_checkElementRectsAndExecuteCallback()
module:utils/dom/resizeobserver~ResizeObserverPolyfill#_checkElementRectsAndExecuteCallback
protected
Checks if the geometry of any of the element has changed. If so, executes the resize callback with element geometry data.
-
_hasRectChanged( element ) → Boolean
module:utils/dom/resizeobserver~ResizeObserverPolyfill#_hasRectChanged
protected
Compares the DOM element geometry to the cached geometry from the past. Returns
true
if geometry has changed or the element is checked for the first time.Parameters
element : HTMLElement
Returns
Boolean
-
_startPeriodicCheck()
module:utils/dom/resizeobserver~ResizeObserverPolyfill#_startPeriodicCheck
protected
When 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.
-
_stopPeriodicCheck()
module:utils/dom/resizeobserver~ResizeObserverPolyfill#_stopPeriodicCheck
protected
Stops checking for changes in all observed elements geometry.
Every day, we work hard to keep our documentation complete. Have you spotted an outdated information? Is something missing? Please report it via our issue tracker.