Created
April 11, 2018 14:24
-
-
Save AlbertoDePena/b7844499bd36ee436d1b7e8943bdff61 to your computer and use it in GitHub Desktop.
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
export class EventDispatcher { | |
public static dispatch(element: Element, eventName: string, args?: any): boolean { | |
let customEvent: CustomEvent; | |
if ((window as any).CustomEvent) { | |
customEvent = new CustomEvent(eventName, { | |
detail: { args: args }, | |
bubbles: true | |
}); | |
} else { | |
customEvent = document.createEvent('CustomEvent'); | |
customEvent.initCustomEvent(eventName, true, true, { | |
detail: { args: args } | |
}); | |
} | |
element.dispatchEvent(customEvent); | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment