Skip to content

Instantly share code, notes, and snippets.

@Javiani
Created October 9, 2015 17:30
Show Gist options
  • Save Javiani/0a9c79fc152e20adfec9 to your computer and use it in GitHub Desktop.
Save Javiani/0a9c79fc152e20adfec9 to your computer and use it in GitHub Desktop.
Custom Event
Event = (function(){
try {
var p = new CustomEvent('c', { detail: { foo: 'b' } });
if('c' === p.type && 'b' === p.detail.foo)
return CustomEvent;
} catch (e) {
return 'function' === typeof document.createEvent ? function(type, params) {
var e = document.createEvent('CustomEvent');
params = params || {};
e.initCustomEvent(type, params.bubbles || false, params.cancelable || false, params.detail || null);
return e;
} :function(type, params) {
var e = document.createEventObject();
e.type = type;
if (params) {
e.bubbles = Boolean(params.bubbles);
e.cancelable = Boolean(params.cancelable);
e.detail = params.detail;
} else {
e.bubbles = false;
e.cancelable = false;
e.detail = void 0;
}
return e;
};
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment