-
Notifications
You must be signed in to change notification settings - Fork 1
/
customevent-polyfill.js
29 lines (27 loc) · 1.06 KB
/
customevent-polyfill.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
(function(root, factory) {
if (typeof define === 'function' && define.amd) define(factory);
else if (typeof exports === 'object') module.exports = factory();
else root.__customEventPolyfill = factory();
}(this, function() {
'use strict';
function CustomEvent (event, params) {
params = params || { bubbles: false, cancelable: false, detail: undefined };
var evt;
try {
evt = document.createEvent('CustomEvent');
evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
} catch (error) {
// fallback for browsers that don't support createEvent('CustomEvent')
evt = document.createEvent('Event');
for (var param in params) {
evt[param] = params[param];
}
evt.initEvent(event, params.bubbles, params.cancelable);
}
return evt;
}
if(typeof window.CustomEvent !== 'undefined') {
CustomEvent.prototype = window.CustomEvent.prototype;
}
window.CustomEvent = CustomEvent;
}));