Skip to content
This repository has been archived by the owner on Dec 14, 2021. It is now read-only.

Commit

Permalink
DOM: Simplify CustomEvent polyfill
Browse files Browse the repository at this point in the history
  • Loading branch information
inexorabletash committed Jan 14, 2017
1 parent 40b7c32 commit 78ccdc7
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 7 deletions.
7 changes: 3 additions & 4 deletions dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,16 +217,15 @@
// https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent
// Needed for: IE
(function () {
if ('CustomEvent' in global) {
if ( typeof global.CustomEvent === "function" ) return false;
}
if ('CustomEvent' in global && typeof global.CustomEvent === "function")
return;
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;
CustomEvent.prototype = global.Event.prototype;
global.CustomEvent = CustomEvent;
})();

Expand Down
16 changes: 16 additions & 0 deletions polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -4800,6 +4800,22 @@ function __cons(t, a) {
});
}());

// CustomEvent
// https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent
// Needed for: IE
(function () {
if ('CustomEvent' in global && typeof global.CustomEvent === "function")
return;
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 = global.Event.prototype;
global.CustomEvent = CustomEvent;
})();

// Shim for DOM Events for IE7-
// http://www.quirksmode.org/blog/archives/2005/10/_and_the_winner_1.html
// Use addEvent(object, event, handler) instead of object.addEventListener(event, handler)
Expand Down
4 changes: 2 additions & 2 deletions polyfill.min.js

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions web.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,22 @@
});
}());

// CustomEvent
// https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent
// Needed for: IE
(function () {
if ('CustomEvent' in global && typeof global.CustomEvent === "function")
return;
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 = global.Event.prototype;
global.CustomEvent = CustomEvent;
})();

// Shim for DOM Events for IE7-
// http://www.quirksmode.org/blog/archives/2005/10/_and_the_winner_1.html
// Use addEvent(object, event, handler) instead of object.addEventListener(event, handler)
Expand Down
2 changes: 1 addition & 1 deletion web.min.js

Large diffs are not rendered by default.

0 comments on commit 78ccdc7

Please sign in to comment.