Skip to content

Commit 1a9cf60

Browse files
committed
Added CustomEvent polyfill for Internet Explorer
1 parent a244b52 commit 1a9cf60

File tree

3 files changed

+25
-39
lines changed

3 files changed

+25
-39
lines changed

a11y-dialog.js

+12-19
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,26 @@
44
// Helper function for dispatching cross browser dispatch events
55
// from http://youmightnotneedjquery.com/#trigger_custom
66
function dispatchEvent (el, eventName) {
7-
var event;
8-
97
// IE < Edge Polyfill
108
// from https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent
11-
(function () {
12-
if ( typeof window.CustomEvent === "function" ) return false;
13-
14-
function CustomEvent ( event, params ) {
15-
params = params || { bubbles: false, cancelable: false, detail: undefined };
16-
var evt = document.createEvent( 'CustomEvent' );
17-
evt.initCustomEvent( event, params.bubbles, params.cancelable, params.detail );
18-
return evt;
19-
}
9+
function _CustomEvent (event, params) {
10+
params = params || { bubbles: false, cancelable: false, detail: undefined };
11+
var evt = document.createEvent('CustomEvent');
12+
evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
13+
return evt;
14+
}
2015

21-
CustomEvent.prototype = window.Event.prototype;
16+
_CustomEvent.prototype = global.Event.prototype;
2217

23-
window.CustomEvent = CustomEvent;
24-
})();
18+
var event;
2519

26-
if (window.CustomEvent) {
27-
event = new CustomEvent(eventName);
20+
if (global.CustomEvent) {
21+
event = new global.CustomEvent(eventName);
2822
} else {
29-
event = document.createEvent('CustomEvent');
30-
event.initCustomEvent(eventName, true, true);
23+
event = new _CustomEvent(eventName)
3124
}
3225

33-
el.dispatchEvent(event);
26+
event && el.dispatchEvent(event);
3427
}
3528

3629
// Helper function to get all focusable children from a node

a11y-dialog.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/main.js

+12-19
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,26 @@
44
// Helper function for dispatching cross browser dispatch events
55
// from http://youmightnotneedjquery.com/#trigger_custom
66
function dispatchEvent (el, eventName) {
7-
var event;
8-
97
// IE < Edge Polyfill
108
// from https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent
11-
(function () {
12-
if ( typeof window.CustomEvent === "function" ) return false;
13-
14-
function CustomEvent ( event, params ) {
15-
params = params || { bubbles: false, cancelable: false, detail: undefined };
16-
var evt = document.createEvent( 'CustomEvent' );
17-
evt.initCustomEvent( event, params.bubbles, params.cancelable, params.detail );
18-
return evt;
19-
}
9+
function _CustomEvent (event, params) {
10+
params = params || { bubbles: false, cancelable: false, detail: undefined };
11+
var evt = document.createEvent('CustomEvent');
12+
evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
13+
return evt;
14+
}
2015

21-
CustomEvent.prototype = window.Event.prototype;
16+
_CustomEvent.prototype = global.Event.prototype;
2217

23-
window.CustomEvent = CustomEvent;
24-
})();
18+
var event;
2519

26-
if (window.CustomEvent) {
27-
event = new CustomEvent(eventName);
20+
if (global.CustomEvent) {
21+
event = new global.CustomEvent(eventName);
2822
} else {
29-
event = document.createEvent('CustomEvent');
30-
event.initCustomEvent(eventName, true, true);
23+
event = new _CustomEvent(eventName)
3124
}
3225

33-
el.dispatchEvent(event);
26+
event && el.dispatchEvent(event);
3427
}
3528

3629
// Helper function to get all focusable children from a node

0 commit comments

Comments
 (0)