forked from cornerstonejs/cornerstone
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtriggerEvent.js
More file actions
24 lines (22 loc) · 776 Bytes
/
Copy pathtriggerEvent.js
File metadata and controls
24 lines (22 loc) · 776 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/**
* Trigger a CustomEvent
*
* @param {EventTarget} el The element or EventTarget to trigger the event upon
* @param {String} type The event type name
* @param {Object|null} detail=null The event data to be sent
* @returns {Boolean} The return value is false if at least one event listener called preventDefault(). Otherwise it returns true.
*/
export default function triggerEvent (el, type, detail = null) {
let event;
// This check is needed to polyfill CustomEvent on IE11-
if (typeof window.CustomEvent === 'function') {
event = new CustomEvent(type, {
detail,
cancelable: true
});
} else {
event = document.createEvent('CustomEvent');
event.initCustomEvent(type, true, true, detail);
}
return el.dispatchEvent(event);
}