2022-02-21 04:10:11 +00:00
|
|
|
export const createEvent = ({ eventName, data = null }) => {
|
2020-07-25 16:24:58 +00:00
|
|
|
let event;
|
|
|
|
if (typeof window.CustomEvent === 'function') {
|
2022-02-21 04:10:11 +00:00
|
|
|
event = new CustomEvent(eventName, { detail: data });
|
2020-07-25 16:24:58 +00:00
|
|
|
} else {
|
|
|
|
event = document.createEvent('CustomEvent');
|
2022-02-21 04:10:11 +00:00
|
|
|
event.initCustomEvent(eventName, false, false, data);
|
2020-07-25 16:24:58 +00:00
|
|
|
}
|
|
|
|
return event;
|
|
|
|
};
|
|
|
|
|
2022-02-21 04:10:11 +00:00
|
|
|
export const dispatchWindowEvent = ({ eventName, data }) => {
|
|
|
|
const event = createEvent({ eventName, data });
|
2020-07-25 16:24:58 +00:00
|
|
|
window.dispatchEvent(event);
|
|
|
|
};
|