Skip to content

Instantly share code, notes, and snippets.

@leemark
Created March 30, 2017 18:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leemark/777b5ce94bce409b5f208c924bb5878b to your computer and use it in GitHub Desktop.
Save leemark/777b5ce94bce409b5f208c924bb5878b to your computer and use it in GitHub Desktop.
Polyfill for CustomEvent constructor in IE9-11. All credit to: https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent#Polyfill
(function () {
if ( typeof window.CustomEvent === "function" ) return false;
function CustomEvent ( event, params ) {
params = params || { bubbles: false, cancelable: false, detail: undefined };
var evt = document.createEvent( 'CustomEvent' );
evt.initCustomEvent( event, params.bubbles, params.cancelable, params.detail );
return evt;
}
CustomEvent.prototype = window.Event.prototype;
window.CustomEvent = CustomEvent;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment