Created
January 7, 2015 22:48
-
-
Save sayrer/49119e05afec82aeba49 to your computer and use it in GitHub Desktop.
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
(function (window) { | |
'use strict'; | |
// | |
// Detect full support | |
// | |
var isSupported = ( | |
'CustomEvent' in window && | |
// in Safari, typeof CustomEvent == 'object' but it works | |
(typeof window.CustomEvent === 'function' || | |
(window.CustomEvent.toString().indexOf('CustomEventConstructor') > -1)) | |
); | |
if (isSupported) { return; } | |
// | |
// Apply Shim | |
// | |
// | |
/** | |
* http://www.w3.org/TR/dom/#customevent | |
* @param {string} type | |
* @param {{bubbles: (boolean|undefined), | |
* cancelable: (boolean|undefined), | |
* detail: *}=} eventInitDict | |
*/ | |
function CustomEvent(type, eventInitDict) { | |
if (typeof type != 'string') { | |
throw new TypeError( | |
'Failed to construct "CustomEvent": An event name must be provided.'); | |
} | |
var event = document.createEvent('CustomEvent'); | |
var defaultInitDict = { bubbles: false, cancelable: false, detail: null }; | |
eventInitDict = eventInitDict || defaultInitDict; | |
event.initCustomEvent( | |
type, | |
eventInitDict.bubbles, | |
eventInitDict.cancelable, | |
eventInitDict.detail | |
); | |
return event; | |
} | |
window.CustomEvent = CustomEvent; | |
}(this)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment