summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/commons/polyfills/event.js
blob: 543dd5f9a93382b645bb08f815db4a43a0954950 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/**
 * Polyfill: Event constructor
 * @what new Event()
 * @why To align browser support
 * @browsers Internet Explorer 11
 * @see https://caniuse.com/#feat=mdn-api_event_event
 *
 * Although `initEvent` is deprecated for modern browsers it is the one supported by IE
 */
if (typeof window.Event !== 'function') {
  window.Event = function Event(event, params) {
    const evt = document.createEvent('Event');
    const evtParams = {
      bubbles: false,
      cancelable: false,
      ...params,
    };
    evt.initEvent(event, evtParams.bubbles, evtParams.cancelable);
    return evt;
  };
  window.Event.prototype = Event;
}