DomTargetsListener
Keeps emitter's callback attached to exactly the DOM event targets returned by getTargets(), for code whose
targets are known only later or change over time.
To listen to the events of the whole editor UI, use listenToEventRoots
instead, which follows the editor's registry on its own.
Use this listener for particular elements, such as the positioning target of a balloon or the limiter of a sticky
panel: return document and their event roots from getTargets().
Unlike the registry listeners, it does not listen to document on its own.
The targets are read once, when the listener is created. Call refresh whenever they may have changed:
it calls getTargets() again, attaches the callback to the targets that appeared and detaches it from the targets
that disappeared, leaving the others alone. Call destroy to detach the callback from every target:
const scrollListener = new DomTargetsListener( () => [ document, ...getEventRoots( limiterElement ) ], {
emitter: view,
event: 'scroll',
listenerOptions: { useCapture: true },
callback: onScroll
} );
// For example once the limiter was moved to another shadow root.
scrollListener.refresh();
// For example when the view is destroyed.
scrollListener.destroy();Copy codeOnly this callback is ever detached, so other listeners of the same emitter on the same targets are not affected.
Type parameters
TEvent: extends keyof DomEventMap
Properties
_attachedTargets: Set<EventTarget>privatereadonlymodule:utils/dom/domtargetslistener~DomTargetsListener#_attachedTargetsThe targets the callback is currently attached to.
module:utils/dom/domtargetslistener~DomTargetsListener#_callbackThe callback attached to each target.
_emitter: DomEmitterprivatereadonlymodule:utils/dom/domtargetslistener~DomTargetsListener#_emitterThe emitter the callback is attached with.
_event: keyof DomEventMapprivatereadonlymodule:utils/dom/domtargetslistener~DomTargetsListener#_eventThe DOM event the callback is attached to.
_getTargets: () => Iterable<EventTarget | null | undefined>privatereadonlymodule:utils/dom/domtargetslistener~DomTargetsListener#_getTargetsReturns the targets that should be listened to.
_listenerOptions: CallbackOptions & object | undefinedprivatereadonlymodule:utils/dom/domtargetslistener~DomTargetsListener#_listenerOptionsThe options the callback is attached with.
Methods
constructor( getTargets, options )module:utils/dom/domtargetslistener~DomTargetsListener#constructorCreates the listener and attaches the callback to the targets returned by
getTargets().Type parameters
TEvent: extends keyof DomEventMap
Parameters
getTargets: () => Iterable<EventTarget | null | undefined>Returns the targets that should be listened to.
nullandundefinedentries are skipped.options: DomTargetsListenerOptions<TEvent>Describes the listener to attach to each target.
destroy() → voidmodule:utils/dom/domtargetslistener~DomTargetsListener#destroyrefresh() → voidmodule:utils/dom/domtargetslistener~DomTargetsListener#refreshReads the targets again: attaches the callback to the targets that appeared and detaches it from the targets that disappeared.
Returns
void
_attachTo( targets ) → voidprivatemodule:utils/dom/domtargetslistener~DomTargetsListener#_attachToAttaches the callback to exactly the given targets.
Parameters
targets: Set<EventTarget>
Returns
void