egroupware_official/api/js/etemplate/Et2Widget/event.ts

23 lines
466 B
TypeScript
Raw Permalink Normal View History

2023-12-09 00:22:01 +01:00
/**
* 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);
});
}