@s-ui/js
Version:
Set of JS utilities
22 lines • 736 B
JavaScript
/**
* This function creates an event and dispatches it
* @param {Object} dispatchEventParams
* @param {string} dispatchEventParams.eventName
* @param {Object} dispatchEventParams.detail
**/
export function dispatchEvent(_ref) {
var eventName = _ref.eventName,
_ref$detail = _ref.detail,
detail = _ref$detail === void 0 ? {} : _ref$detail;
var event;
// check if native CustomEvent is available and use it
if (window.CustomEvent && typeof window.CustomEvent === 'function') {
event = new window.CustomEvent(eventName, {
detail: detail
});
} else {
event = document.createEvent('CustomEvent');
event.initCustomEvent(eventName, true, true, detail);
}
window.document.dispatchEvent(event);
}