-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import {DOCUMENT} from '@angular/common'; | ||
import {inject, Injectable, InjectionToken} from '@angular/core'; | ||
|
||
import {AbstractEventPlugin} from './abstract.plugin'; | ||
|
||
export const GLOBAL_HANDLER = new InjectionToken<(name: string) => EventTarget>( | ||
'[GLOBAL_HANDLER]: Global event target handler', | ||
{ | ||
factory: () => { | ||
const document = inject(DOCUMENT); | ||
|
||
return name => | ||
name === 'body' | ||
? document.body | ||
: (document.defaultView as any)[name] || document.defaultView; | ||
}, | ||
}, | ||
); | ||
|
||
@Injectable() | ||
export class GlobalEventPlugin extends AbstractEventPlugin { | ||
private readonly handler: Function = inject(GLOBAL_HANDLER); | ||
protected readonly modifier = '>'; | ||
|
||
public addEventListener(_: HTMLElement, event: string, handler: Function): Function { | ||
return this.manager.addEventListener( | ||
this.handler(event.split('>')[0]), | ||
event.split('>')[1], | ||
handler, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters