This will ignore events emitted on elements in descendant overlays, even if the descendant overlay's element is nested into the DOM tree of this layer.
The arguments for this function are the same as for
let rootLayer = up.layer.root let overlay = await up.layer.open() rootLayer.on('foo', (event) => console.log('Listener called')) rootLayer.emit('foo') // logs "Listener called" overlay.emit('foo') // listener is not called
Whenever possible Unpoly will emit its events on associated layers instead of
This way you can listen to events on one layer without receiving events from other layers.
E.g. to listen to all requests originating from a given layer:
let rootLayer = up.layer.root let rootLink = rootLayer.affix('a[href=/foo]') let overlay = await up.layer.open() let overlayLink = overlay.affix('a[href=/bar]') rootLayer.on('up:request:load', (event) => console.log('Listener called')) up.follow(rootLink) // logs "Listener called" up.follow(overlayLink) // listener is not called
A space-separated list of event types to bind to.
The selector of an element on which the event must be triggered.
Omit the selector to listen to all events of the given type, regardless of the event target.
If the selector is not known in advance you may also pass a function that returns the selector. The function is evaluated every time an event with the given type is observed.
Whether to register a passive event listener.
A passive event listener may not call
This in particular may improve the frame rate when registering
Whether the listener should run at most once.
true the listener will automatically be unbound
after the first invocation.
The listener function that should be called.
The function takes the affected element as the second argument.
If the element has an
up-data attribute, its value is parsed as JSON
and passed as a third argument.
A function that unbinds the event listeners when called.