From c5c5c38eff5faaa8fdb21ccd6934948a865668b9 Mon Sep 17 00:00:00 2001 From: Phil Blais Date: Wed, 4 Mar 2020 20:17:30 -0500 Subject: [PATCH 1/2] Add polyfill for CustomEvent to fix #1186 --- src/gridstack-poly.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/gridstack-poly.js b/src/gridstack-poly.js index 3f69a3a92..657ceaf1c 100644 --- a/src/gridstack-poly.js +++ b/src/gridstack-poly.js @@ -5,6 +5,18 @@ * gridstack.js may be freely distributed under the MIT license. */ +// https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent +if (typeof window.CustomEvent !== "function") { + function CustomEvent (event, params) { + params = params || {bubbles: false, cancelable: false, detail: null}; + var evt = document.createEvent('CustomEvent'); + evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail); + return evt; + } + + window.CustomEvent = CustomEvent; +} + // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isNaN Number.isNaN = Number.isNaN || function isNaN(input) { return typeof input === 'number' && input !== input; From f1ec3e2f1226e0ebc9981f39dec9c8ec0c979bc4 Mon Sep 17 00:00:00 2001 From: Phil Blais Date: Wed, 4 Mar 2020 21:06:14 -0500 Subject: [PATCH 2/2] Scope the CustomEvent polyfill --- src/gridstack-poly.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/gridstack-poly.js b/src/gridstack-poly.js index 657ceaf1c..5ec62d795 100644 --- a/src/gridstack-poly.js +++ b/src/gridstack-poly.js @@ -6,7 +6,11 @@ */ // https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent -if (typeof window.CustomEvent !== "function") { +(function () { + if (typeof window.CustomEvent === "function") { + return false; + } + function CustomEvent (event, params) { params = params || {bubbles: false, cancelable: false, detail: null}; var evt = document.createEvent('CustomEvent'); @@ -15,7 +19,7 @@ if (typeof window.CustomEvent !== "function") { } window.CustomEvent = CustomEvent; -} +})(); // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isNaN Number.isNaN = Number.isNaN || function isNaN(input) {