mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-23 08:23:12 +01:00
23 lines
466 B
TypeScript
23 lines
466 B
TypeScript
/**
|
|
* Waits for a specific event to be emitted from an element. Ignores events that bubble up from child elements.
|
|
*
|
|
* Copied from Shoelace
|
|
* /src/internal/event.ts
|
|
*/
|
|
export function waitForEvent(el : HTMLElement, eventName : string)
|
|
{
|
|
return new Promise<void>(resolve =>
|
|
{
|
|
function done(event : Event)
|
|
{
|
|
if(event.target === el)
|
|
{
|
|
el.removeEventListener(eventName, done);
|
|
resolve();
|
|
}
|
|
}
|
|
|
|
el.addEventListener(eventName, done);
|
|
});
|
|
}
|