1 | "use strict";
|
2 |
|
3 | module.exports = {
|
4 | Event,
|
5 | CustomEvent
|
6 | };
|
7 |
|
8 | function Event(type = "", {bubbles} = {bubbles: false}) {
|
9 | let defaultPrevented;
|
10 | let cancelBubble;
|
11 |
|
12 | const event = {
|
13 | type,
|
14 | bubbles,
|
15 | preventDefault,
|
16 | stopPropagation,
|
17 | get defaultPrevented() {
|
18 | return defaultPrevented;
|
19 | },
|
20 | get cancelBubble() {
|
21 | return cancelBubble;
|
22 | },
|
23 | path: []
|
24 | };
|
25 |
|
26 | event.initCustomEvent = (customType = "") => {
|
27 | event.type = customType;
|
28 | };
|
29 |
|
30 | Object.setPrototypeOf(event, Event.prototype);
|
31 |
|
32 | return event;
|
33 |
|
34 | function preventDefault() {
|
35 | defaultPrevented = true;
|
36 | }
|
37 |
|
38 | function stopPropagation() {
|
39 | cancelBubble = true;
|
40 | }
|
41 | }
|
42 |
|
43 | function CustomEvent(type = "", customEventInit = {}) {
|
44 | const customEvent = Event(type);
|
45 | let detail = customEventInit.detail || null;
|
46 |
|
47 | Object.defineProperty(customEvent, "detail", {
|
48 | get() {
|
49 | return detail;
|
50 | }
|
51 | });
|
52 |
|
53 | customEvent.initCustomEvent = (customType = "", canBubble, cancelable, customDetail = null) => {
|
54 | customEvent.type = customType;
|
55 | detail = customDetail;
|
56 | };
|
57 |
|
58 | Object.setPrototypeOf(customEvent, CustomEvent.prototype);
|
59 |
|
60 | return customEvent;
|
61 | }
|