diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..fe66af0 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,13 @@ +# http://editorconfig.org +root = true + +[*] +indent_style = space +indent_size = 4 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.md] +trim_trailing_whitespace = false \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b512c09 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules \ No newline at end of file diff --git a/bower.json b/bower.json new file mode 100644 index 0000000..c4fc4a1 --- /dev/null +++ b/bower.json @@ -0,0 +1,23 @@ +{ + "name": "customevent-polyfill", + "version": "1.0.0", + "homepage": "https://github.com/kaesetoast/customevent-polyfill", + "authors": [ + "Philipp Nowinski " + ], + "description": "A polyfill for CustomEvent", + "main": "customevent-polyfill.js", + "keywords": [ + "polyfill", + "customevent" + ], + "license": "MIT", + "ignore": [ + "**/.*", + "node_modules", + "bower_components", + "app/bower_components", + "test", + "tests" + ] +} diff --git a/customevent-polyfill.js b/customevent-polyfill.js new file mode 100644 index 0000000..ce33302 --- /dev/null +++ b/customevent-polyfill.js @@ -0,0 +1,25 @@ +(function () { + 'use strict'; + function CustomEvent (event, params) { + params = params || { bubbles: false, cancelable: false, detail: undefined }; + var evt; + try { + evt = document.createEvent('CustomEvent'); + evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail); + } catch (error) { + // fallback for browsers that don't support createEvent('CustomEvent') + evt = document.createEvent('Event'); + for (var param in params) { + evt[param] = params[param]; + } + evt.initEvent(event, params.bubbles, params.cancelable); + } + return evt; + } + + if(typeof window.CustomEvent !== 'undefined') { + CustomEvent.prototype = window.CustomEvent.prototype; + } + + window.CustomEvent = CustomEvent; +})(); \ No newline at end of file diff --git a/customevent-polyfill.min.js b/customevent-polyfill.min.js new file mode 100644 index 0000000..cf58c32 --- /dev/null +++ b/customevent-polyfill.min.js @@ -0,0 +1 @@ +!function(){"use strict";function t(t,e){e=e||{bubbles:!1,cancelable:!1,detail:void 0};var n;try{n=document.createEvent("CustomEvent"),n.initCustomEvent(t,e.bubbles,e.cancelable,e.detail)}catch(o){n=document.createEvent("Event");for(var c in e)n[c]=e[c];n.initEvent(t,e.bubbles,e.cancelable)}return n}"undefined"!=typeof window.CustomEvent&&(t.prototype=window.CustomEvent.prototype),window.CustomEvent=t}(); \ No newline at end of file diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 0000000..1289e57 --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,12 @@ +'use strict'; + +var gulp = require('gulp'), + uglify = require('gulp-uglify'), + rename = require('gulp-rename'); + +gulp.task('compress', function() { + gulp.src('customevent-polyfill.js') + .pipe(uglify()) + .pipe(rename('customevent-polyfill.min.js')) + .pipe(gulp.dest('.')); +}); diff --git a/package.json b/package.json new file mode 100644 index 0000000..aca4619 --- /dev/null +++ b/package.json @@ -0,0 +1,21 @@ +{ + "name": "customevent-polyfill", + "version": "1.0.0", + "description": "A polyfill for CustomEvent", + "main": "customevent-polyfill.js", + "repository": { + "type": "git", + "url": "git://github.com/kaesetoast/customevent-polyfill.git" + }, + "author": "Philipp Nowinski