Created
October 9, 2015 17:30
-
-
Save Javiani/0a9c79fc152e20adfec9 to your computer and use it in GitHub Desktop.
Custom Event
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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