feat: Add chatwoot:ready
event listener on window (#1091)
* feat: Add `chatwoot:ready` event listener on window * Add specs * Rename customEventHelper.js -> CustomEventHelper.js
This commit is contained in:
parent
80b083c7fc
commit
12ee7e5d82
5 changed files with 42 additions and 0 deletions
15
app/javascript/shared/helpers/CustomEventHelper.js
Normal file
15
app/javascript/shared/helpers/CustomEventHelper.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
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);
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue