https://developer.mozilla.org/en-US/docs/Web/API/Event/initEvent
Unified · Split
| @@ -84,36 +84,18 @@ $.off = function (el, event, callback, useCapture) { · 83 unmodified lines | ||
| 84 | 84 | }; |
| 85 | 85 | |
| 86 | 86 | $.trigger = function (el, type, canBubble, cancelable) { |
| 87 | − if (canBubble == null) { | |
| 88 | − canBubble = true; | |
| 89 | − } | |
| 90 | − if (cancelable == null) { | |
| 91 | − cancelable = true; | |
| 92 | − } | |
| 93 | − const event = document.createEvent("Event"); | |
| 94 | − event.initEvent(type, canBubble, cancelable); | |
| 87 | + const event = new Event(type, { | |
| 88 | + bubbles: canBubble ?? true, | |
| 89 | + cancelable: cancelable ?? true, | |
| 90 | + }); | |
| 95 | 91 | el.dispatchEvent(event); |
| 96 | 92 | }; |
| 97 | 93 | |
| 98 | 94 | $.click = function (el) { |
| 99 | − const event = document.createEvent("MouseEvent"); | |
| 100 | − event.initMouseEvent( | |
| 101 | − "click", | |
| 102 | − true, | |
| 103 | − true, | |
| 104 | − window, | |
| 105 | − null, | |
| 106 | − 0, | |
| 107 | − 0, | |
| 108 | − 0, | |
| 109 | − 0, | |
| 110 | − false, | |
| 111 | − false, | |
| 112 | − false, | |
| 113 | − false, | |
| 114 | − 0, | |
| 115 | − null, | |
| 116 | − ); | |
| 95 | + const event = new MouseEvent("click", { | |
| 96 | + bubbles: true, | |
| 97 | + cancelable: true, | |
| 98 | + }); | |
| 117 | 99 | el.dispatchEvent(event); |
| 118 | 100 | }; |
| 119 | 101 | |