Adds Event polyfill for IE
This commit is contained in:
parent
f9b30c6d7e
commit
d329cf4f02
4 changed files with 30 additions and 1 deletions
|
@ -12,4 +12,5 @@ import 'core-js/fn/symbol';
|
|||
// Browser polyfills
|
||||
import './polyfills/custom_event';
|
||||
import './polyfills/element';
|
||||
import './polyfills/event';
|
||||
import './polyfills/nodelist';
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
if (typeof window.CustomEvent !== 'function') {
|
||||
window.CustomEvent = function CustomEvent(event, params) {
|
||||
const evt = document.createEvent('CustomEvent');
|
||||
const evtParams = params || { bubbles: false, cancelable: false, detail: undefined };
|
||||
const evtParams = {
|
||||
bubbles: false,
|
||||
cancelable: false,
|
||||
detail: undefined,
|
||||
...params,
|
||||
};
|
||||
evt.initCustomEvent(event, evtParams.bubbles, evtParams.cancelable, evtParams.detail);
|
||||
return evt;
|
||||
};
|
||||
|
|
18
app/assets/javascripts/commons/polyfills/event.js
Normal file
18
app/assets/javascripts/commons/polyfills/event.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
/**
|
||||
* Polyfill for IE11 support.
|
||||
* new Event() is not supported by IE11.
|
||||
* 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;
|
||||
}
|
5
changelogs/unreleased/ie-event-polyfill.yml
Normal file
5
changelogs/unreleased/ie-event-polyfill.yml
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
title: Adds Event polyfill for IE11
|
||||
merge_request:
|
||||
author:
|
||||
type: fixed
|
Loading…
Reference in a new issue