1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | const workingDefaultPrevented = (() => {
|
14 | const e = document.createEvent('Event');
|
15 | e.initEvent('foo', true, true);
|
16 | e.preventDefault();
|
17 | return e.defaultPrevented;
|
18 | })();
|
19 | if (!workingDefaultPrevented) {
|
20 | const origPreventDefault = Event.prototype.preventDefault;
|
21 | Event.prototype.preventDefault = function () {
|
22 | if (!this.cancelable) {
|
23 | return;
|
24 | }
|
25 | origPreventDefault.call(this);
|
26 | Object.defineProperty(this, 'defaultPrevented', {
|
27 | get() {
|
28 | return true;
|
29 | },
|
30 | configurable: true
|
31 | });
|
32 | };
|
33 | }
|
34 | const isIE = /Trident/.test(navigator.userAgent);
|
35 |
|
36 | if (!window.Event || isIE && (typeof window.Event !== 'function')) {
|
37 | const origEvent = window.Event;
|
38 | window['Event'] =
|
39 | ((inType, params) => {
|
40 | params = params || {};
|
41 | const e = document.createEvent('Event');
|
42 | e.initEvent(inType, Boolean(params.bubbles), Boolean(params.cancelable));
|
43 | return e;
|
44 | });
|
45 | if (origEvent) {
|
46 |
|
47 | for (const i in origEvent) {
|
48 |
|
49 | window['Event'][i] = origEvent[i];
|
50 | }
|
51 | window['Event'].prototype = origEvent.prototype;
|
52 | }
|
53 | }
|
54 |
|
55 | if (!window.CustomEvent || isIE && (typeof window.CustomEvent !== 'function')) {
|
56 | window['CustomEvent'] =
|
57 | ((inType, params) => {
|
58 | params = params || {};
|
59 | const e = document.createEvent('CustomEvent');
|
60 | e.initCustomEvent(inType, Boolean(params.bubbles), Boolean(params.cancelable), params.detail);
|
61 | return e;
|
62 | });
|
63 | window['CustomEvent'].prototype = window.Event.prototype;
|
64 | }
|
65 | if (!window.MouseEvent || isIE && (typeof window.MouseEvent !== 'function')) {
|
66 | const origMouseEvent = window.MouseEvent;
|
67 | window['MouseEvent'] =
|
68 | ((inType, params) => {
|
69 | params = params || {};
|
70 | const e = document.createEvent('MouseEvent');
|
71 | e.initMouseEvent(inType, Boolean(params.bubbles), Boolean(params.cancelable), params.view || window, params.detail, params.screenX, params.screenY, params.clientX, params.clientY, params.ctrlKey, params.altKey, params.shiftKey, params.metaKey, params.button, params.relatedTarget);
|
72 | return e;
|
73 | });
|
74 | if (origMouseEvent) {
|
75 |
|
76 | for (const j in origMouseEvent) {
|
77 |
|
78 | window.MouseEvent[j] = origMouseEvent[j];
|
79 | }
|
80 | }
|
81 | window['MouseEvent'].prototype = origMouseEvent.prototype;
|
82 | }
|
83 |
|
\ | No newline at end of file |