Chatwoot/app/javascript/shared/helpers/CustomEventHelper.js
Pranav Raj S 12ee7e5d82
feat: Add chatwoot:ready event listener on window (#1091)
* feat: Add `chatwoot:ready` event listener on window

* Add specs

* Rename customEventHelper.js -> CustomEventHelper.js
2020-07-25 21:54:58 +05:30

15 lines
411 B
JavaScript

export const createEvent = eventName => {
let event;
if (typeof window.CustomEvent === 'function') {
event = new CustomEvent(eventName);
} else {
event = document.createEvent('CustomEvent');
event.initCustomEvent(eventName, false, false, null);
}
return event;
};
export const dispatchWindowEvent = eventName => {
const event = createEvent(eventName);
window.dispatchEvent(event);
};