(win, type, detail, opt_eventInit)
| 19 | * @return {!Event} |
| 20 | */ |
| 21 | export function createCustomEvent(win, type, detail, opt_eventInit) { |
| 22 | const eventInit = /** @type {!CustomEventInit} */ ({detail}); |
| 23 | Object.assign(eventInit, opt_eventInit); |
| 24 | // win.CustomEvent is a function on Edge, Chrome, FF, Safari but |
| 25 | // is an object on IE 11. |
| 26 | if (mode.isEsm() || typeof win.CustomEvent == 'function') { |
| 27 | return new win.CustomEvent(type, eventInit); |
| 28 | } else { |
| 29 | // Deprecated fallback for IE. |
| 30 | const e = win.document.createEvent('CustomEvent'); |
| 31 | e.initCustomEvent( |
| 32 | type, |
| 33 | !!eventInit.bubbles, |
| 34 | !!eventInit.cancelable, |
| 35 | detail |
| 36 | ); |
| 37 | return e; |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Listens for the specified event on the element. |
no test coverage detected