Last change
on this file since b738035 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Rev | Line | |
---|
[6a3a178] | 1 |
|
---|
| 2 | var NativeCustomEvent = global.CustomEvent;
|
---|
| 3 |
|
---|
| 4 | function useNative () {
|
---|
| 5 | try {
|
---|
| 6 | var p = new NativeCustomEvent('cat', { detail: { foo: 'bar' } });
|
---|
| 7 | return 'cat' === p.type && 'bar' === p.detail.foo;
|
---|
| 8 | } catch (e) {
|
---|
| 9 | }
|
---|
| 10 | return false;
|
---|
| 11 | }
|
---|
| 12 |
|
---|
| 13 | /**
|
---|
| 14 | * Cross-browser `CustomEvent` constructor.
|
---|
| 15 | *
|
---|
| 16 | * https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent.CustomEvent
|
---|
| 17 | *
|
---|
| 18 | * @public
|
---|
| 19 | */
|
---|
| 20 |
|
---|
| 21 | module.exports = useNative() ? NativeCustomEvent :
|
---|
| 22 |
|
---|
| 23 | // IE >= 9
|
---|
| 24 | 'undefined' !== typeof document && 'function' === typeof document.createEvent ? function CustomEvent (type, params) {
|
---|
| 25 | var e = document.createEvent('CustomEvent');
|
---|
| 26 | if (params) {
|
---|
| 27 | e.initCustomEvent(type, params.bubbles, params.cancelable, params.detail);
|
---|
| 28 | } else {
|
---|
| 29 | e.initCustomEvent(type, false, false, void 0);
|
---|
| 30 | }
|
---|
| 31 | return e;
|
---|
| 32 | } :
|
---|
| 33 |
|
---|
| 34 | // IE <= 8
|
---|
| 35 | function CustomEvent (type, params) {
|
---|
| 36 | var e = document.createEventObject();
|
---|
| 37 | e.type = type;
|
---|
| 38 | if (params) {
|
---|
| 39 | e.bubbles = Boolean(params.bubbles);
|
---|
| 40 | e.cancelable = Boolean(params.cancelable);
|
---|
| 41 | e.detail = params.detail;
|
---|
| 42 | } else {
|
---|
| 43 | e.bubbles = false;
|
---|
| 44 | e.cancelable = false;
|
---|
| 45 | e.detail = void 0;
|
---|
| 46 | }
|
---|
| 47 | return e;
|
---|
| 48 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.