@next2d/events 1.18.12 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +8 -24
- package/src/Event.d.ts +222 -0
- package/src/Event.js +337 -0
- package/src/EventDispatcher/service/EventDispatcherAddEventListenerService.d.ts +14 -0
- package/src/EventDispatcher/service/EventDispatcherAddEventListenerService.js +87 -0
- package/src/EventDispatcher/service/EventDispatcherDispatchEventService.d.ts +13 -0
- package/src/EventDispatcher/service/EventDispatcherDispatchEventService.js +189 -0
- package/src/EventDispatcher/service/EventDispatcherHasEventListenerService.d.ts +12 -0
- package/src/EventDispatcher/service/EventDispatcherHasEventListenerService.js +25 -0
- package/src/EventDispatcher/service/EventDispatcherRemoveAllEventListenerService.d.ts +13 -0
- package/src/EventDispatcher/service/EventDispatcherRemoveAllEventListenerService.js +83 -0
- package/src/EventDispatcher/service/EventDispatcherRemoveEventListenerService.d.ts +14 -0
- package/src/EventDispatcher/service/EventDispatcherRemoveEventListenerService.js +80 -0
- package/src/EventDispatcher/service/EventDispatcherWillTriggerService.d.ts +12 -0
- package/src/EventDispatcher/service/EventDispatcherWillTriggerService.js +28 -0
- package/{dist → src}/EventDispatcher.d.ts +13 -62
- package/src/EventDispatcher.js +120 -0
- package/src/EventPhase.d.ts +39 -0
- package/src/EventPhase.js +45 -0
- package/src/EventUtil.d.ts +42 -0
- package/src/EventUtil.js +59 -0
- package/src/FocusEvent.d.ts +42 -0
- package/src/FocusEvent.js +71 -0
- package/src/HTTPStatusEvent.d.ts +63 -0
- package/src/HTTPStatusEvent.js +99 -0
- package/src/IOErrorEvent.d.ts +39 -0
- package/src/IOErrorEvent.js +49 -0
- package/src/JobEvent.d.ts +29 -0
- package/src/JobEvent.js +33 -0
- package/src/KeyboardEvent.d.ts +37 -0
- package/src/KeyboardEvent.js +66 -0
- package/src/PointerEvent.d.ts +84 -0
- package/src/PointerEvent.js +127 -0
- package/src/ProgressEvent.d.ts +53 -0
- package/src/ProgressEvent.js +69 -0
- package/src/VideoEvent.d.ts +47 -0
- package/src/VideoEvent.js +55 -0
- package/src/WheelEvent.d.ts +28 -0
- package/src/WheelEvent.js +49 -0
- package/{dist → src}/index.d.ts +5 -1
- package/{dist → src}/index.js +5 -1
- package/src/interface/IEvent.d.ts +2 -0
- package/src/interface/IEvent.js +1 -0
- package/src/interface/IEventDispatcher.d.ts +2 -0
- package/src/interface/IEventDispatcher.js +1 -0
- package/src/interface/IEventListener.d.ts +7 -0
- package/src/interface/IEventListener.js +1 -0
- package/src/interface/IURLRequestHeader.d.ts +4 -0
- package/src/interface/IURLRequestHeader.js +1 -0
- package/dist/Event.d.ts +0 -424
- package/dist/Event.js +0 -560
- package/dist/EventDispatcher.js +0 -622
- package/dist/EventPhase.d.ts +0 -80
- package/dist/EventPhase.js +0 -94
- package/dist/FocusEvent.d.ts +0 -89
- package/dist/FocusEvent.js +0 -103
- package/dist/HTTPStatusEvent.d.ts +0 -107
- package/dist/HTTPStatusEvent.js +0 -139
- package/dist/IOErrorEvent.d.ts +0 -82
- package/dist/IOErrorEvent.js +0 -101
- package/dist/MouseEvent.d.ts +0 -163
- package/dist/MouseEvent.js +0 -207
- package/dist/ProgressEvent.d.ts +0 -97
- package/dist/ProgressEvent.js +0 -123
- package/dist/VideoEvent.d.ts +0 -145
- package/dist/VideoEvent.js +0 -181
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { Event } from "../../Event";
|
|
2
|
+
import { KeyboardEvent } from "../../KeyboardEvent";
|
|
3
|
+
import { $broadcastEvents, $getArray } from "../../EventUtil";
|
|
4
|
+
/**
|
|
5
|
+
* @description 指定イベントに関数を登録、既に登録されている場合は上書。
|
|
6
|
+
* Register a function in the specified event, or overwrite if already registered.
|
|
7
|
+
*
|
|
8
|
+
* @param {EventDispatcher} scope
|
|
9
|
+
* @param {string} type
|
|
10
|
+
* @param {Function} listener
|
|
11
|
+
* @param {boolean} [use_capture = false]
|
|
12
|
+
* @param {number} [priority = 0]
|
|
13
|
+
* @method
|
|
14
|
+
* @protected
|
|
15
|
+
*/
|
|
16
|
+
export const execute = (scope, type, listener, use_capture = false, priority = 0) => {
|
|
17
|
+
let listenerObjects;
|
|
18
|
+
switch (type) {
|
|
19
|
+
// broadcast event
|
|
20
|
+
case Event.ENTER_FRAME:
|
|
21
|
+
case KeyboardEvent.KEY_DOWN:
|
|
22
|
+
case KeyboardEvent.KEY_UP:
|
|
23
|
+
if (!$broadcastEvents.size
|
|
24
|
+
|| !$broadcastEvents.has(type)) {
|
|
25
|
+
$broadcastEvents.set(type, $getArray());
|
|
26
|
+
}
|
|
27
|
+
listenerObjects = $broadcastEvents.get(type);
|
|
28
|
+
break;
|
|
29
|
+
// normal event
|
|
30
|
+
default:
|
|
31
|
+
if (!scope._$events) {
|
|
32
|
+
scope._$events = new Map();
|
|
33
|
+
}
|
|
34
|
+
if (!scope._$events.size || !scope._$events.has(type)) {
|
|
35
|
+
scope._$events.set(type, $getArray());
|
|
36
|
+
}
|
|
37
|
+
listenerObjects = scope._$events.get(type);
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
// duplicate check
|
|
41
|
+
const length = listenerObjects.length;
|
|
42
|
+
let index = 0;
|
|
43
|
+
for (; index < length; ++index) {
|
|
44
|
+
const object = listenerObjects[index];
|
|
45
|
+
if (use_capture !== object.useCapture) {
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (object.target !== scope) {
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (object.listener !== listener) {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
// add or overwrite
|
|
57
|
+
if (length === index) {
|
|
58
|
+
// add
|
|
59
|
+
listenerObjects.push({
|
|
60
|
+
"listener": listener,
|
|
61
|
+
"priority": priority,
|
|
62
|
+
"useCapture": use_capture,
|
|
63
|
+
"target": scope
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
// overwrite
|
|
68
|
+
const object = listenerObjects[index];
|
|
69
|
+
object.listener = listener;
|
|
70
|
+
object.priority = priority;
|
|
71
|
+
object.useCapture = use_capture;
|
|
72
|
+
object.target = scope;
|
|
73
|
+
}
|
|
74
|
+
if (listenerObjects.length > 1) {
|
|
75
|
+
// sort(DESC)
|
|
76
|
+
listenerObjects.sort((a, b) => {
|
|
77
|
+
switch (true) {
|
|
78
|
+
case a.priority > b.priority:
|
|
79
|
+
return -1;
|
|
80
|
+
case a.priority < b.priority:
|
|
81
|
+
return 1;
|
|
82
|
+
default:
|
|
83
|
+
return 0;
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { EventDispatcher } from "../../EventDispatcher";
|
|
2
|
+
import { Event } from "../../Event";
|
|
3
|
+
/**
|
|
4
|
+
* @description 指定のイベントを実行します。
|
|
5
|
+
* Executes the specified event.
|
|
6
|
+
*
|
|
7
|
+
* @param {EventDispatcher} scope
|
|
8
|
+
* @param {Event} event
|
|
9
|
+
* @return {boolean}
|
|
10
|
+
* @method
|
|
11
|
+
* @protected
|
|
12
|
+
*/
|
|
13
|
+
export declare const execute: <D extends EventDispatcher, E extends Event>(scope: D, event: E) => boolean;
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { Event } from "../../Event";
|
|
2
|
+
import { KeyboardEvent } from "../../KeyboardEvent";
|
|
3
|
+
import { EventPhase } from "../../EventPhase";
|
|
4
|
+
import { $broadcastEvents, $getArray, $poolArray } from "../../EventUtil";
|
|
5
|
+
/**
|
|
6
|
+
* @description 指定のイベントを実行します。
|
|
7
|
+
* Executes the specified event.
|
|
8
|
+
*
|
|
9
|
+
* @param {EventDispatcher} scope
|
|
10
|
+
* @param {Event} event
|
|
11
|
+
* @return {boolean}
|
|
12
|
+
* @method
|
|
13
|
+
* @protected
|
|
14
|
+
*/
|
|
15
|
+
export const execute = (scope, event) => {
|
|
16
|
+
switch (event.type) {
|
|
17
|
+
case Event.ENTER_FRAME:
|
|
18
|
+
case KeyboardEvent.KEY_DOWN:
|
|
19
|
+
case KeyboardEvent.KEY_UP:
|
|
20
|
+
{
|
|
21
|
+
if (!$broadcastEvents.size
|
|
22
|
+
|| !$broadcastEvents.has(event.type)) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
const listenerObjects = $broadcastEvents.get(event.type);
|
|
26
|
+
if (!listenerObjects.length) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
for (let idx = 0; idx < listenerObjects.length; ++idx) {
|
|
30
|
+
const object = listenerObjects[idx];
|
|
31
|
+
// start target
|
|
32
|
+
event.eventPhase = EventPhase.AT_TARGET;
|
|
33
|
+
// event execute
|
|
34
|
+
event.target = event.currentTarget = object.target;
|
|
35
|
+
try {
|
|
36
|
+
event.listener = object.listener;
|
|
37
|
+
object.listener(event);
|
|
38
|
+
}
|
|
39
|
+
catch (e) {
|
|
40
|
+
console.error(e);
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return true;
|
|
46
|
+
default:
|
|
47
|
+
{
|
|
48
|
+
event.target = scope;
|
|
49
|
+
let currentEvents = null;
|
|
50
|
+
if (scope._$events
|
|
51
|
+
&& scope._$events.size
|
|
52
|
+
&& scope._$events.has(event.type)) {
|
|
53
|
+
const events = scope._$events.get(event.type);
|
|
54
|
+
if (events) {
|
|
55
|
+
currentEvents = events.slice(0);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
// parent
|
|
59
|
+
const parentEvents = $getArray();
|
|
60
|
+
if ("parent" in scope) {
|
|
61
|
+
let parent = scope.parent;
|
|
62
|
+
while (parent) {
|
|
63
|
+
if (parent.hasEventListener(event.type)) {
|
|
64
|
+
const events = parent._$events && parent._$events.has(event.type)
|
|
65
|
+
? parent._$events.get(event.type)
|
|
66
|
+
: null;
|
|
67
|
+
if (events) {
|
|
68
|
+
parentEvents.push(events);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (!("parent" in parent)) {
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
parent = parent.parent;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (!currentEvents && !parentEvents.length) {
|
|
78
|
+
if (currentEvents) {
|
|
79
|
+
$poolArray(currentEvents);
|
|
80
|
+
}
|
|
81
|
+
$poolArray(parentEvents);
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
// stage => child... end
|
|
85
|
+
if (parentEvents.length) {
|
|
86
|
+
// start capture
|
|
87
|
+
event.eventPhase = EventPhase.CAPTURING_PHASE;
|
|
88
|
+
switch (true) {
|
|
89
|
+
case event._$stopImmediatePropagation:
|
|
90
|
+
case event._$stopPropagation:
|
|
91
|
+
break;
|
|
92
|
+
default:
|
|
93
|
+
for (let idx = parentEvents.length - 1; idx > -1; --idx) {
|
|
94
|
+
const events = parentEvents[idx];
|
|
95
|
+
for (let idx = 0; idx < events.length; ++idx) {
|
|
96
|
+
const object = events[idx];
|
|
97
|
+
if (!object.useCapture) {
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
// event execute
|
|
101
|
+
event.currentTarget = object.target;
|
|
102
|
+
try {
|
|
103
|
+
event.listener = object.listener;
|
|
104
|
+
object.listener.call(null, event);
|
|
105
|
+
}
|
|
106
|
+
catch (e) {
|
|
107
|
+
console.error(e);
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
if (event._$stopImmediatePropagation) {
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (event._$stopImmediatePropagation) {
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (currentEvents
|
|
122
|
+
&& !event._$stopImmediatePropagation
|
|
123
|
+
&& !event._$stopPropagation) {
|
|
124
|
+
// start target
|
|
125
|
+
event.eventPhase = EventPhase.AT_TARGET;
|
|
126
|
+
for (let idx = 0; idx < currentEvents.length; ++idx) {
|
|
127
|
+
const object = currentEvents[idx];
|
|
128
|
+
if (object.useCapture) {
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
// event execute
|
|
132
|
+
event.currentTarget = object.target;
|
|
133
|
+
try {
|
|
134
|
+
event.listener = object.listener;
|
|
135
|
+
object.listener.call(null, event);
|
|
136
|
+
}
|
|
137
|
+
catch (e) {
|
|
138
|
+
console.error(e);
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
if (event._$stopImmediatePropagation) {
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
$poolArray(currentEvents);
|
|
146
|
+
}
|
|
147
|
+
if (parentEvents.length) {
|
|
148
|
+
// start bubbling
|
|
149
|
+
event.eventPhase = EventPhase.BUBBLING_PHASE;
|
|
150
|
+
switch (true) {
|
|
151
|
+
case event._$stopImmediatePropagation:
|
|
152
|
+
case event._$stopPropagation:
|
|
153
|
+
case !event.bubbles:
|
|
154
|
+
break;
|
|
155
|
+
default:
|
|
156
|
+
// this => parent... => stage end
|
|
157
|
+
for (let idx = 0; idx < parentEvents.length; ++idx) {
|
|
158
|
+
const events = parentEvents[idx];
|
|
159
|
+
for (let idx = 0; idx < events.length; ++idx) {
|
|
160
|
+
const object = events[idx];
|
|
161
|
+
if (object.useCapture) {
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
// event execute
|
|
165
|
+
event.currentTarget = object.target;
|
|
166
|
+
try {
|
|
167
|
+
event.listener = object.listener;
|
|
168
|
+
object.listener.call(null, event);
|
|
169
|
+
}
|
|
170
|
+
catch (e) {
|
|
171
|
+
console.error(e);
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
if (event._$stopImmediatePropagation) {
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
if (event._$stopImmediatePropagation) {
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
$poolArray(parentEvents);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return true;
|
|
188
|
+
}
|
|
189
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { EventDispatcher } from "../../EventDispatcher";
|
|
2
|
+
/**
|
|
3
|
+
* @description 指定イベントが登録されているかを返却。
|
|
4
|
+
* Returns whether the specified event is registered.
|
|
5
|
+
*
|
|
6
|
+
* @param {EventDispatcher} scope
|
|
7
|
+
* @param {string} type
|
|
8
|
+
* @return {boolean}
|
|
9
|
+
* @method
|
|
10
|
+
* @protected
|
|
11
|
+
*/
|
|
12
|
+
export declare const execute: <D extends EventDispatcher>(scope: D, type: string) => boolean;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { KeyboardEvent } from "../../KeyboardEvent";
|
|
2
|
+
import { Event } from "../../Event";
|
|
3
|
+
import { $broadcastEvents } from "../../EventUtil";
|
|
4
|
+
/**
|
|
5
|
+
* @description 指定イベントが登録されているかを返却。
|
|
6
|
+
* Returns whether the specified event is registered.
|
|
7
|
+
*
|
|
8
|
+
* @param {EventDispatcher} scope
|
|
9
|
+
* @param {string} type
|
|
10
|
+
* @return {boolean}
|
|
11
|
+
* @method
|
|
12
|
+
* @protected
|
|
13
|
+
*/
|
|
14
|
+
export const execute = (scope, type) => {
|
|
15
|
+
switch (type) {
|
|
16
|
+
case Event.ENTER_FRAME:
|
|
17
|
+
case KeyboardEvent.KEY_DOWN:
|
|
18
|
+
case KeyboardEvent.KEY_UP:
|
|
19
|
+
return $broadcastEvents.size && $broadcastEvents.has(type) ? true : false;
|
|
20
|
+
default:
|
|
21
|
+
return !!(scope._$events
|
|
22
|
+
&& scope._$events.size
|
|
23
|
+
&& scope._$events.has(type));
|
|
24
|
+
}
|
|
25
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { EventDispatcher } from "../../EventDispatcher";
|
|
2
|
+
/**
|
|
3
|
+
* @description イベントリスナーを全て削除。
|
|
4
|
+
* Remove all event listeners.
|
|
5
|
+
*
|
|
6
|
+
* @param {EventDispatcher} scope
|
|
7
|
+
* @param {string} type
|
|
8
|
+
* @param {boolean} use_capture
|
|
9
|
+
* @return {void}
|
|
10
|
+
* @method
|
|
11
|
+
* @protected
|
|
12
|
+
*/
|
|
13
|
+
export declare const execute: <D extends EventDispatcher>(scope: D, type: string, use_capture?: boolean) => void;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { KeyboardEvent } from "../../KeyboardEvent";
|
|
2
|
+
import { Event } from "../../Event";
|
|
3
|
+
import { $broadcastEvents, $getArray, $poolArray } from "../../EventUtil";
|
|
4
|
+
/**
|
|
5
|
+
* @description イベントリスナーを全て削除。
|
|
6
|
+
* Remove all event listeners.
|
|
7
|
+
*
|
|
8
|
+
* @param {EventDispatcher} scope
|
|
9
|
+
* @param {string} type
|
|
10
|
+
* @param {boolean} use_capture
|
|
11
|
+
* @return {void}
|
|
12
|
+
* @method
|
|
13
|
+
* @protected
|
|
14
|
+
*/
|
|
15
|
+
export const execute = (scope, type, use_capture = false) => {
|
|
16
|
+
let listenerObjects;
|
|
17
|
+
switch (type) {
|
|
18
|
+
case Event.ENTER_FRAME:
|
|
19
|
+
case KeyboardEvent.KEY_DOWN:
|
|
20
|
+
case KeyboardEvent.KEY_UP:
|
|
21
|
+
if (!$broadcastEvents.size
|
|
22
|
+
|| !$broadcastEvents.has(type)) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
listenerObjects = $broadcastEvents.get(type);
|
|
26
|
+
break;
|
|
27
|
+
default:
|
|
28
|
+
if (!scope._$events
|
|
29
|
+
|| !scope._$events.size
|
|
30
|
+
|| !scope._$events.has(type)) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
listenerObjects = scope._$events.get(type);
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
if (!listenerObjects) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
// remove listener
|
|
40
|
+
const results = $getArray();
|
|
41
|
+
for (let idx = 0; idx < listenerObjects.length; ++idx) {
|
|
42
|
+
// event object
|
|
43
|
+
const object = listenerObjects[idx];
|
|
44
|
+
if (use_capture === object.useCapture) {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
results.push(object);
|
|
48
|
+
}
|
|
49
|
+
if (!results.length) {
|
|
50
|
+
if ($broadcastEvents.has(type)) {
|
|
51
|
+
$broadcastEvents.delete(type);
|
|
52
|
+
}
|
|
53
|
+
if (scope._$events && scope._$events.has(type)) {
|
|
54
|
+
scope._$events.delete(type);
|
|
55
|
+
if (!scope._$events.size) {
|
|
56
|
+
scope._$events = null;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
$poolArray(results);
|
|
60
|
+
$poolArray(listenerObjects);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (results.length > 1) {
|
|
64
|
+
// event sort (DESC)
|
|
65
|
+
results.sort((a, b) => {
|
|
66
|
+
switch (true) {
|
|
67
|
+
case a.priority > b.priority:
|
|
68
|
+
return -1;
|
|
69
|
+
case a.priority < b.priority:
|
|
70
|
+
return 1;
|
|
71
|
+
default:
|
|
72
|
+
return 0;
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
if ($broadcastEvents.has(type)) {
|
|
77
|
+
$broadcastEvents.set(type, results);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
scope._$events?.set(type, results);
|
|
81
|
+
}
|
|
82
|
+
$poolArray(listenerObjects);
|
|
83
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { EventDispatcher } from "../../EventDispatcher";
|
|
2
|
+
/**
|
|
3
|
+
* @description イベントリスナーを削除。
|
|
4
|
+
* Remove the event listener.
|
|
5
|
+
*
|
|
6
|
+
* @param {EventDispatcher} scope
|
|
7
|
+
* @param {string} type
|
|
8
|
+
* @param {Function} listener
|
|
9
|
+
* @param {boolean} [use_capture = false]
|
|
10
|
+
* @return {void}
|
|
11
|
+
* @method
|
|
12
|
+
* @protected
|
|
13
|
+
*/
|
|
14
|
+
export declare const execute: <D extends EventDispatcher>(scope: D, type: string, listener: Function, use_capture?: boolean) => void;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { Event } from "../../Event";
|
|
2
|
+
import { KeyboardEvent } from "../../KeyboardEvent";
|
|
3
|
+
import { $broadcastEvents, $poolArray } from "../../EventUtil";
|
|
4
|
+
/**
|
|
5
|
+
* @description イベントリスナーを削除。
|
|
6
|
+
* Remove the event listener.
|
|
7
|
+
*
|
|
8
|
+
* @param {EventDispatcher} scope
|
|
9
|
+
* @param {string} type
|
|
10
|
+
* @param {Function} listener
|
|
11
|
+
* @param {boolean} [use_capture = false]
|
|
12
|
+
* @return {void}
|
|
13
|
+
* @method
|
|
14
|
+
* @protected
|
|
15
|
+
*/
|
|
16
|
+
export const execute = (scope, type, listener, use_capture = false) => {
|
|
17
|
+
let listenerObjects;
|
|
18
|
+
switch (type) {
|
|
19
|
+
case Event.ENTER_FRAME:
|
|
20
|
+
case KeyboardEvent.KEY_DOWN:
|
|
21
|
+
case KeyboardEvent.KEY_UP:
|
|
22
|
+
if (!$broadcastEvents.size
|
|
23
|
+
|| !$broadcastEvents.has(type)) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
listenerObjects = $broadcastEvents.get(type);
|
|
27
|
+
break;
|
|
28
|
+
default:
|
|
29
|
+
if (!scope._$events
|
|
30
|
+
|| !scope._$events.size
|
|
31
|
+
|| !scope._$events.has(type)) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
listenerObjects = scope._$events.get(type);
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
if (!listenerObjects) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
// remove listener
|
|
41
|
+
for (let idx = 0; idx < listenerObjects.length; ++idx) {
|
|
42
|
+
// event object
|
|
43
|
+
const object = listenerObjects[idx];
|
|
44
|
+
if (use_capture !== object.useCapture) {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (object.listener !== listener) {
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
// delete if match
|
|
51
|
+
listenerObjects.splice(idx, 1);
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
if (!listenerObjects.length) {
|
|
55
|
+
if ($broadcastEvents.has(type)) {
|
|
56
|
+
$broadcastEvents.delete(type);
|
|
57
|
+
}
|
|
58
|
+
if (scope._$events && scope._$events.has(type)) {
|
|
59
|
+
scope._$events.delete(type);
|
|
60
|
+
if (!scope._$events.size) {
|
|
61
|
+
scope._$events = null;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
$poolArray(listenerObjects);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (listenerObjects.length > 1) {
|
|
68
|
+
// event sort(DESC)
|
|
69
|
+
listenerObjects.sort((a, b) => {
|
|
70
|
+
switch (true) {
|
|
71
|
+
case a.priority > b.priority:
|
|
72
|
+
return -1;
|
|
73
|
+
case a.priority < b.priority:
|
|
74
|
+
return 1;
|
|
75
|
+
default:
|
|
76
|
+
return 0;
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { EventDispatcher } from "../../EventDispatcher";
|
|
2
|
+
/**
|
|
3
|
+
* @description 先祖も含めてイベントリスナーが登録されているかどうかを判定。
|
|
4
|
+
* Determine whether an event listener is registered, including ancestors.
|
|
5
|
+
*
|
|
6
|
+
* @param {EventDispatcher} scope
|
|
7
|
+
* @param {string} type
|
|
8
|
+
* @return {boolean}
|
|
9
|
+
* @method
|
|
10
|
+
* @protected
|
|
11
|
+
*/
|
|
12
|
+
export declare const execute: <D extends EventDispatcher>(scope: D, type: string) => boolean;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description 先祖も含めてイベントリスナーが登録されているかどうかを判定。
|
|
3
|
+
* Determine whether an event listener is registered, including ancestors.
|
|
4
|
+
*
|
|
5
|
+
* @param {EventDispatcher} scope
|
|
6
|
+
* @param {string} type
|
|
7
|
+
* @return {boolean}
|
|
8
|
+
* @method
|
|
9
|
+
* @protected
|
|
10
|
+
*/
|
|
11
|
+
export const execute = (scope, type) => {
|
|
12
|
+
if (scope.hasEventListener(type)) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
if ("parent" in scope) {
|
|
16
|
+
let parent = scope.parent;
|
|
17
|
+
while (parent) {
|
|
18
|
+
if (parent.hasEventListener(type)) {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
if (!("parent" in parent)) {
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
parent = parent.parent;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
};
|