From a30d12312a2e6949147e6e3c866c53420a4288df Mon Sep 17 00:00:00 2001 From: Xaver Maierhofer Date: Tue, 26 Dec 2017 18:14:23 +0100 Subject: [PATCH] [BUGFIX] Support CustomEvent in IE --- lib/sidebar.js | 2 +- polyfill.js | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/sidebar.js b/lib/sidebar.js index c042c88..b28cf3c 100644 --- a/lib/sidebar.js +++ b/lib/sidebar.js @@ -15,7 +15,7 @@ define(function () { el.appendChild(sidebar); var button = document.createElement('button'); - var visibility = new Event('visibility'); + var visibility = new CustomEvent('visibility'); sidebar.appendChild(button); button.classList.add('sidebarhandle'); diff --git a/polyfill.js b/polyfill.js index 856beb2..c646e44 100644 --- a/polyfill.js +++ b/polyfill.js @@ -8,7 +8,7 @@ if (!String.prototype.includes) { } if (typeof Object.assign !== 'function') { - Object.assign = function(target, varArgs) { // .length of function is 2 + Object.assign = function (target, varArgs) { // .length of function is 2 if (target == null) { // TypeError if undefined or null throw new TypeError('Cannot convert undefined or null to object'); } @@ -30,3 +30,21 @@ if (typeof Object.assign !== 'function') { return to; }; } + +// eslint-disable-next-line consistent-return +(function () { + if (typeof window.CustomEvent === 'function') { + return false; + } + + function CustomEvent(event, params) { + params = params || { bubbles: false, cancelable: false, detail: undefined }; + var evt = document.createEvent('CustomEvent'); + evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail); + return evt; + } + + CustomEvent.prototype = window.Event.prototype; + + window.CustomEvent = CustomEvent; +})();