diff --git a/CustomEvent.js b/CustomEvent.js index 95cc72a..728d592 100644 --- a/CustomEvent.js +++ b/CustomEvent.js @@ -1,21 +1,15 @@ -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; -} +(function() { + if (typeof window === "undefined") return false; + if (typeof window.CustomEvent === "function") return false; -function register() { -} + 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; + } -module.exports = function ( undefined ) { - if ( typeof window.CustomEvent === 'function' ) { - return; - }; CustomEvent.prototype = window.Event.prototype; + window.CustomEvent = CustomEvent; -}; +})(); diff --git a/README.md b/README.md index bf07134..889de91 100644 --- a/README.md +++ b/README.md @@ -13,11 +13,15 @@ npm install --save-dev jspolyfill-custom-event # Usage ```js -require( 'jspolyfill-custom-event' )(); +require('jspolyfill-custom-event'); +``` + +or + +```js +import('jspolyfill-custom-event'); ``` -**Note**: Make sure to add the extra set of parenthesis at the end to fire the `function` that -registers the creation of the polyfill. # Syntax