targetj 1.0.74 → 1.0.76
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/babel.config.json +17 -0
- package/build/$Dom.js +424 -0
- package/build/App.js +187 -0
- package/build/Bracket.js +157 -0
- package/build/BracketGenerator.js +86 -0
- package/build/Browser.js +105 -0
- package/build/ColorUtil.js +182 -0
- package/build/Dim.js +31 -0
- package/build/Easing.js +59 -0
- package/build/EventListener.js +664 -0
- package/build/LoadingManager.js +366 -0
- package/build/LocationManager.js +211 -0
- package/build/Moves.js +71 -0
- package/build/PageManager.js +113 -0
- package/build/SearchUtil.js +196 -0
- package/build/TModel.js +1000 -0
- package/build/TModelManager.js +605 -0
- package/build/TUtil.js +188 -0
- package/build/TargetExecutor.js +117 -0
- package/build/TargetManager.js +197 -0
- package/build/TargetUtil.js +299 -0
- package/build/Viewport.js +163 -0
- package/package.json +11 -4
- package/webpack.config.js +14 -1
- package/src/$Dom.js +0 -380
- package/src/App.js +0 -224
- package/src/Bracket.js +0 -212
- package/src/Browser.js +0 -122
- package/src/ColorUtil.js +0 -166
- package/src/Dim.js +0 -21
- package/src/Easing.js +0 -41
- package/src/EventListener.js +0 -570
- package/src/LoadingManager.js +0 -368
- package/src/LocationManager.js +0 -236
- package/src/Moves.js +0 -59
- package/src/PageManager.js +0 -87
- package/src/SearchUtil.js +0 -210
- package/src/TModel.js +0 -937
- package/src/TModelManager.js +0 -575
- package/src/TUtil.js +0 -162
- package/src/TargetExecutor.js +0 -113
- package/src/TargetManager.js +0 -191
- package/src/TargetUtil.js +0 -307
- package/src/Viewport.js +0 -180
package/src/EventListener.js
DELETED
|
@@ -1,570 +0,0 @@
|
|
|
1
|
-
import { $Dom } from "./$Dom.js";
|
|
2
|
-
import { browser } from "./Browser.js";
|
|
3
|
-
import { SearchUtil } from "./SearchUtil.js";
|
|
4
|
-
import { TUtil } from "./TUtil.js";
|
|
5
|
-
import { tapp } from "./App.js";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
function EventListener() {
|
|
9
|
-
|
|
10
|
-
this.currentTouch = {
|
|
11
|
-
deltaY: 0,
|
|
12
|
-
deltaX: 0,
|
|
13
|
-
pinchDelta: 0,
|
|
14
|
-
key: '',
|
|
15
|
-
manualMomentumFlag: false,
|
|
16
|
-
orientation: "none" ,
|
|
17
|
-
dir: "",
|
|
18
|
-
source: ""
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
this.touchTimeStamp = 0;
|
|
22
|
-
|
|
23
|
-
this.cursor = { x: 0, y: 0};
|
|
24
|
-
this.start0 = undefined;
|
|
25
|
-
this.start1 = undefined;
|
|
26
|
-
this.end0 = undefined;
|
|
27
|
-
this.end1 = undefined;
|
|
28
|
-
this.touchCount = 0;
|
|
29
|
-
|
|
30
|
-
this.currentEvent = "";
|
|
31
|
-
this.currentHandlers = { touch: null, scrollLeft: null, scrollTop: null, pinch: null };
|
|
32
|
-
|
|
33
|
-
this.eventQueue = [];
|
|
34
|
-
|
|
35
|
-
this.eventMap = {
|
|
36
|
-
touchstart: { to: 'touchstart', inputType: 'touch', eventType: 'start', order: 1, windowEvent: false },
|
|
37
|
-
touchmove: { to: 'touchmove', inputType: 'touch', eventType: 'move', order: 1, windowEvent: false },
|
|
38
|
-
touchend: { to: 'touchend', inputType: 'touch', eventType: 'end', order: 1, windowEvent: false },
|
|
39
|
-
touchcancel: { to: 'touchend', inputType: 'touch', eventType: 'cancel', order: 1, windowEvent: false },
|
|
40
|
-
|
|
41
|
-
mousedown: { to: 'mousedown', inputType: 'mouse', eventType: 'start', order: 2, windowEvent: false },
|
|
42
|
-
mousemove: { to: 'mousemove', inputType: 'mouse', eventType: 'move', order: 2, windowEvent: false },
|
|
43
|
-
mouseup: { to: 'mouseup', inputType: 'mouse', eventType: 'end', order: 2, windowEvent: false },
|
|
44
|
-
mousecancel: { to: 'mouseup', inputType: 'mouse', eventType: 'cancel', order: 2, windowEvent: false },
|
|
45
|
-
|
|
46
|
-
pointerdown: { to: 'mousedown', inputType: 'pointer', eventType: 'start', order: 3, windowEvent: false },
|
|
47
|
-
pointermove: { to: 'mousemove', inputType: 'pointer', eventType: 'move', order: 3, windowEvent: false },
|
|
48
|
-
pointerup: { to: 'mouseup', inputType: 'pointer', eventType: 'end', order: 3, windowEvent: false },
|
|
49
|
-
pointercancel: { to: 'mousecancel', inputType: 'pointer', eventType: 'cancel', order: 3, windowEvent: false },
|
|
50
|
-
|
|
51
|
-
wheel: { to: 'wheel', inputType: '', eventType: 'wheel', order: 1, windowEvent: false },
|
|
52
|
-
DOMMouseScroll: { to: 'wheel', inputType: '', eventType: 'wheel', order: 1, windowEvent: false },
|
|
53
|
-
mousewheel: { to: 'wheel', inputType: '', eventType: 'wheel', order: 1, windowEvent: false },
|
|
54
|
-
|
|
55
|
-
keyup: { to: 'key', inputType: '', eventType: 'key', order: 1, windowEvent: true },
|
|
56
|
-
keydown: { to: 'key', inputType: '', eventType: 'key', order: 1, windowEvent: true },
|
|
57
|
-
resize: { to: 'resize', inputType: '', eventType: 'resize', order: 1, windowEvent: true },
|
|
58
|
-
orientationchange: { to: 'resize', inputType: '', eventType: 'resize', order: 1, windowEvent: true }
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
var self = this;
|
|
62
|
-
this.domEvents = Object.keys(this.eventMap).filter(function(key) { return self.eventMap[key].windowEvent === false; });
|
|
63
|
-
this.windowEvents = Object.keys(this.eventMap).filter(function(key) { return self.eventMap[key].windowEvent; });
|
|
64
|
-
|
|
65
|
-
this.bindedHandleEvent = this.bindedHandleEvent ? this.bindedHandleEvent : this.handleEvent.bind(this);
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
EventListener.prototype.removeHandlers = function ($dom) {
|
|
70
|
-
|
|
71
|
-
var self = this;
|
|
72
|
-
this.domEvents.forEach(function(key) {
|
|
73
|
-
$dom.detachEvent(key, self.bindedHandleEvent);
|
|
74
|
-
});
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
EventListener.prototype.addHandlers = function ($dom) {
|
|
78
|
-
var self = this;
|
|
79
|
-
this.domEvents.forEach(function(key) {
|
|
80
|
-
$dom.addEvent(key, self.bindedHandleEvent);
|
|
81
|
-
});
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
EventListener.prototype.removeWindowHandlers = function () {
|
|
85
|
-
var self = this;
|
|
86
|
-
this.windowEvents.forEach(function(key) {
|
|
87
|
-
tapp.$window.detachEvent(key, self.bindedHandleEvent);
|
|
88
|
-
});
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
EventListener.prototype.addWindowHandlers = function () {
|
|
92
|
-
var self = this;
|
|
93
|
-
this.windowEvents.forEach(function(key) {
|
|
94
|
-
tapp.$window.addEvent(key, self.bindedHandleEvent);
|
|
95
|
-
});
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
EventListener.prototype.captureEvents = function() {
|
|
99
|
-
|
|
100
|
-
if (this.eventQueue.length === 0) {
|
|
101
|
-
this.currentEvent = "";
|
|
102
|
-
this.currentKey = "";
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
var lastEvent = this.eventQueue.shift();
|
|
106
|
-
|
|
107
|
-
if (lastEvent.eventName === 'resize') {
|
|
108
|
-
tapp.dim.measureScreen();
|
|
109
|
-
} else {
|
|
110
|
-
if (lastEvent.tmodel) {
|
|
111
|
-
this.findEventHandlers(lastEvent.tmodel);
|
|
112
|
-
}
|
|
113
|
-
this.currentEvent = lastEvent.eventName;
|
|
114
|
-
this.currentKey = this.currentTouch.key;
|
|
115
|
-
this.currentTouch.key = "";
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
tapp.manager.scheduleRun(10, 'captureEvents' + '-' + lastEvent);
|
|
119
|
-
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
EventListener.prototype.handleEvent = function (event) {
|
|
123
|
-
if (!event) {
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
var eventName, inputType, eventType, eventOrder;
|
|
128
|
-
|
|
129
|
-
var originalName = event.type;
|
|
130
|
-
var eventItem = this.eventMap[originalName];
|
|
131
|
-
|
|
132
|
-
if (eventItem) {
|
|
133
|
-
eventName = eventItem.to;
|
|
134
|
-
inputType = eventItem.inputType;
|
|
135
|
-
eventType = eventItem.eventType;
|
|
136
|
-
eventOrder = eventItem.order;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
var now = browser.now();
|
|
140
|
-
this.touchTimeStamp = now > this.touchTimeStamp ? now : this.touchTimeStamp;
|
|
141
|
-
|
|
142
|
-
var tmodel = this.getTModelFromEvent(event);
|
|
143
|
-
|
|
144
|
-
var lastEvent = this.eventQueue.length > 0 ? this.eventQueue[this.eventQueue.length - 1] : null;
|
|
145
|
-
|
|
146
|
-
if (lastEvent) {
|
|
147
|
-
var lastEventItem = lastEvent.eventItem;
|
|
148
|
-
var rate = now - lastEvent.timeStamp;
|
|
149
|
-
|
|
150
|
-
if ((inputType && lastEventItem.inputType && lastEventItem.inputType !== inputType && eventOrder > lastEventItem.order)) {
|
|
151
|
-
return;
|
|
152
|
-
} else if (this.eventQueue.length > 10 && rate < 50) {
|
|
153
|
-
var capacity = 0, i;
|
|
154
|
-
for (i = this.eventQueue.length - 1; i >= 0 && this.eventQueue[i].eventItem.eventType === eventType; i--) {
|
|
155
|
-
if (++capacity > 5) {
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
this.eventQueue.push({ eventName: eventName, eventItem: eventItem, originalName: originalName, tmodel: tmodel, timeStamp: now });
|
|
163
|
-
|
|
164
|
-
switch (eventName) {
|
|
165
|
-
|
|
166
|
-
case 'mousedown':
|
|
167
|
-
case 'touchstart':
|
|
168
|
-
this.clearStart();
|
|
169
|
-
this.clearTouch();
|
|
170
|
-
|
|
171
|
-
this.touchCount = this.countTouches(event);
|
|
172
|
-
if (this.preventDefault(tmodel, eventName)) {
|
|
173
|
-
event.preventDefault();
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
this.start0 = this.getTouch(event);
|
|
177
|
-
this.start1 = this.getTouch(event, 1);
|
|
178
|
-
|
|
179
|
-
this.cursor.x = this.start0.x;
|
|
180
|
-
this.cursor.y = this.start0.y;
|
|
181
|
-
|
|
182
|
-
event.stopPropagation();
|
|
183
|
-
break;
|
|
184
|
-
|
|
185
|
-
case 'mousemove':
|
|
186
|
-
case 'touchmove':
|
|
187
|
-
|
|
188
|
-
var touch = this.getTouch(event);
|
|
189
|
-
this.cursor.x = touch.x;
|
|
190
|
-
this.cursor.y = touch.y;
|
|
191
|
-
if (this.preventDefault(tmodel, eventName)) {
|
|
192
|
-
event.preventDefault();
|
|
193
|
-
}
|
|
194
|
-
if (this.touchCount > 0) {
|
|
195
|
-
this.move(event);
|
|
196
|
-
event.stopPropagation();
|
|
197
|
-
}
|
|
198
|
-
break;
|
|
199
|
-
|
|
200
|
-
case 'mouseup':
|
|
201
|
-
case 'touchend':
|
|
202
|
-
|
|
203
|
-
if (this.preventDefault(tmodel, eventName)) {
|
|
204
|
-
event.preventDefault();
|
|
205
|
-
}
|
|
206
|
-
this.end(event);
|
|
207
|
-
|
|
208
|
-
if (this.start0) {
|
|
209
|
-
var deltaX = 0, deltaY = 0, period = now - this.start0.timeStamp;
|
|
210
|
-
|
|
211
|
-
if (this.end0) {
|
|
212
|
-
deltaX = Math.abs(this.end0.originalX - this.start0.originalX);
|
|
213
|
-
deltaY = Math.abs(this.end0.originalY - this.start0.originalY);
|
|
214
|
-
period = Math.abs(this.end0.timeStamp - this.start0.timeStamp);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
if (deltaX <= 1 && deltaY <= 1 && period <= 300) {
|
|
218
|
-
this.eventQueue.push({ eventName: 'click', eventItem: eventItem, originalName: originalName, tmodel: tmodel, timeStamp: now });
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
this.clearStart();
|
|
223
|
-
this.touchCount = 0;
|
|
224
|
-
|
|
225
|
-
event.stopPropagation();
|
|
226
|
-
break;
|
|
227
|
-
|
|
228
|
-
case 'wheel':
|
|
229
|
-
|
|
230
|
-
if (this.preventDefault(tmodel, eventName)) {
|
|
231
|
-
event.preventDefault();
|
|
232
|
-
}
|
|
233
|
-
this.wheel(event);
|
|
234
|
-
break;
|
|
235
|
-
|
|
236
|
-
case 'key':
|
|
237
|
-
this.currentTouch.key = event.which || event.keyCode;
|
|
238
|
-
break;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
tapp.manager.scheduleRun(0, originalName + '-' + eventName + '-' + (event.target.tagName || "").toUpperCase());
|
|
242
|
-
};
|
|
243
|
-
|
|
244
|
-
EventListener.prototype.findEventHandlers = function(tmodel) {
|
|
245
|
-
|
|
246
|
-
var touchHandler = tmodel ? SearchUtil.findFirstTouchHandler(tmodel) : null;
|
|
247
|
-
var scrollLeftHandler = this.end0 ? this.currentHandlers.scrollLeft : tmodel ? SearchUtil.findFirstScrollLeftHandler(tmodel) : null;
|
|
248
|
-
var scrollTopHandler = this.end0 ? this.currentHandlers.scrollTop : tmodel ? SearchUtil.findFirstScrollTopHandler(tmodel) : null;
|
|
249
|
-
var pinchHandler = tmodel ? SearchUtil.findFirstPinchHandler(tmodel) : null;
|
|
250
|
-
|
|
251
|
-
if (this.currentHandlers.scrollLeft !== scrollLeftHandler || this.currentHandlers.scrollTop !== scrollTopHandler) {
|
|
252
|
-
this.clearTouch();
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
this.currentHandlers.touch = touchHandler;
|
|
256
|
-
this.currentHandlers.scrollLeft = scrollLeftHandler;
|
|
257
|
-
this.currentHandlers.scrollTop = scrollTopHandler;
|
|
258
|
-
this.currentHandlers.pinch = pinchHandler;
|
|
259
|
-
};
|
|
260
|
-
|
|
261
|
-
EventListener.prototype.preventDefault = function(tmodel, eventName) {
|
|
262
|
-
|
|
263
|
-
if (tmodel && (tmodel.keepEventDefault() === true || (Array.isArray(tmodel.keepEventDefault()) && tmodel.keepEventDefault().includes(eventName)))) {
|
|
264
|
-
return false;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
return true;
|
|
268
|
-
};
|
|
269
|
-
|
|
270
|
-
EventListener.prototype.getTModelFromEvent = function(event) {
|
|
271
|
-
var oid = typeof event.target.getAttribute === 'function' ? event.target.getAttribute('id') : '';
|
|
272
|
-
|
|
273
|
-
if (!oid || !tapp.manager.visibleOidMap[oid]) {
|
|
274
|
-
oid = $Dom.findNearestParentWithId(event.target);
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
return tapp.manager.visibleOidMap[oid];
|
|
278
|
-
};
|
|
279
|
-
|
|
280
|
-
EventListener.prototype.clearStart = function() {
|
|
281
|
-
this.start0 = undefined;
|
|
282
|
-
this.start1 = undefined;
|
|
283
|
-
this.end0 = undefined;
|
|
284
|
-
this.end1 = undefined;
|
|
285
|
-
this.touchCount = 0;
|
|
286
|
-
};
|
|
287
|
-
|
|
288
|
-
EventListener.prototype.clearTouch = function() {
|
|
289
|
-
this.currentTouch.deltaY = 0;
|
|
290
|
-
this.currentTouch.deltaX = 0;
|
|
291
|
-
this.currentTouch.pinchDelta = 0;
|
|
292
|
-
this.currentTouch.manualMomentumFlag = false;
|
|
293
|
-
this.currentTouch.dir = "";
|
|
294
|
-
this.currentTouch.orientation = "none";
|
|
295
|
-
this.currentTouch.key = '';
|
|
296
|
-
this.currentTouch.source = '';
|
|
297
|
-
};
|
|
298
|
-
|
|
299
|
-
EventListener.prototype.clearAll = function() {
|
|
300
|
-
this.clearStart();
|
|
301
|
-
this.clearTouch();
|
|
302
|
-
this.eventQueue.length = 0;
|
|
303
|
-
this.touchTimeStamp = 0;
|
|
304
|
-
};
|
|
305
|
-
|
|
306
|
-
EventListener.prototype.resetEventsOnTimeout = function () {
|
|
307
|
-
if (this.touchTimeStamp > 0) {
|
|
308
|
-
|
|
309
|
-
var diff = browser.now() - this.touchTimeStamp;
|
|
310
|
-
var runDelay = 0;
|
|
311
|
-
|
|
312
|
-
if (Math.abs(this.currentTouch.deltaY) > 0.001
|
|
313
|
-
|| Math.abs(this.currentTouch.deltaX) > 0.001
|
|
314
|
-
|| Math.abs(this.currentTouch.pinchDelta) > 0.001)
|
|
315
|
-
{
|
|
316
|
-
if (diff > 70) {
|
|
317
|
-
this.currentTouch.deltaY = 0;
|
|
318
|
-
this.currentTouch.deltaX = 0;
|
|
319
|
-
this.currentTouch.source = '';
|
|
320
|
-
this.currentTouch.pinchDelta = 0;
|
|
321
|
-
} else if (this.currentTouch.manualMomentumFlag) {
|
|
322
|
-
this.currentTouch.deltaY *= 0.85;
|
|
323
|
-
this.currentTouch.deltaX *= 0.85;
|
|
324
|
-
this.currentTouch.source = '';
|
|
325
|
-
|
|
326
|
-
runDelay = 10;
|
|
327
|
-
}
|
|
328
|
-
} else if (diff > 600) {
|
|
329
|
-
this.clearTouch();
|
|
330
|
-
this.touchTimeStamp = 0;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
tapp.manager.scheduleRun(runDelay, "scroll decay");
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
};
|
|
337
|
-
|
|
338
|
-
EventListener.prototype.deltaX = function() {
|
|
339
|
-
return this.currentTouch.deltaX;
|
|
340
|
-
};
|
|
341
|
-
|
|
342
|
-
EventListener.prototype.deltaY = function() {
|
|
343
|
-
return this.currentTouch.deltaY;
|
|
344
|
-
};
|
|
345
|
-
|
|
346
|
-
EventListener.prototype.pinchDelta = function() {
|
|
347
|
-
return this.currentTouch.pinchDelta;
|
|
348
|
-
};
|
|
349
|
-
|
|
350
|
-
EventListener.prototype.dir = function() {
|
|
351
|
-
return this.currentTouch.dir;
|
|
352
|
-
};
|
|
353
|
-
|
|
354
|
-
EventListener.prototype.getScrollLeftHandler = function() {
|
|
355
|
-
return this.currentHandlers.scrollLeft;
|
|
356
|
-
};
|
|
357
|
-
|
|
358
|
-
EventListener.prototype.getScrollTopHandler = function() {
|
|
359
|
-
return this.currentHandlers.scrollTop;
|
|
360
|
-
};
|
|
361
|
-
|
|
362
|
-
EventListener.prototype.getPinchHandler = function() {
|
|
363
|
-
return this.currentHandlers.pinch;
|
|
364
|
-
};
|
|
365
|
-
|
|
366
|
-
EventListener.prototype.getTouchHandler = function() {
|
|
367
|
-
return this.currentHandlers.touch;
|
|
368
|
-
};
|
|
369
|
-
|
|
370
|
-
EventListener.prototype.getTouchHandlerType = function() {
|
|
371
|
-
return this.currentHandlers.touch ? this.currentHandlers.touch.type : null;
|
|
372
|
-
};
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
EventListener.prototype.getTouchHandlerOid = function() {
|
|
376
|
-
return this.currentHandlers.touch ? this.currentHandlers.touch.oid : null;
|
|
377
|
-
};
|
|
378
|
-
|
|
379
|
-
EventListener.prototype.isClickEvent = function() {
|
|
380
|
-
return this.currentEvent === 'click';
|
|
381
|
-
};
|
|
382
|
-
|
|
383
|
-
EventListener.prototype.isResizeEvent = function() {
|
|
384
|
-
return this.currentEvent === 'resize';
|
|
385
|
-
};
|
|
386
|
-
|
|
387
|
-
EventListener.prototype.getCurrentEvent = function() {
|
|
388
|
-
return this.currentEvent;
|
|
389
|
-
};
|
|
390
|
-
|
|
391
|
-
EventListener.prototype.isClickHandler = function(target) {
|
|
392
|
-
return this.getTouchHandler() === target && this.isClickEvent();
|
|
393
|
-
};
|
|
394
|
-
|
|
395
|
-
EventListener.prototype.isClickHandlerType = function(type) {
|
|
396
|
-
return this.getTouchHandlerType() === type && this.isClickEvent();
|
|
397
|
-
};
|
|
398
|
-
|
|
399
|
-
EventListener.prototype.isTouchHandler = function(handler) {
|
|
400
|
-
return this.getTouchHandler() === handler && handler.canHandleEvents('touch');
|
|
401
|
-
};
|
|
402
|
-
|
|
403
|
-
EventListener.prototype.isScrollLeftHandler = function(handler) {
|
|
404
|
-
return this.currentHandlers.scrollLeft === handler;
|
|
405
|
-
};
|
|
406
|
-
|
|
407
|
-
EventListener.prototype.isScrollTopHandler = function(handler) {
|
|
408
|
-
return this.currentHandlers.scrollTop === handler;
|
|
409
|
-
};
|
|
410
|
-
|
|
411
|
-
EventListener.prototype.isPinchHandler = function(handler) {
|
|
412
|
-
return this.currentHandlers.pinch === handler;
|
|
413
|
-
};
|
|
414
|
-
|
|
415
|
-
EventListener.prototype.isCurrentSource = function(source) {
|
|
416
|
-
return this.currentTouch.source === source;
|
|
417
|
-
};
|
|
418
|
-
|
|
419
|
-
EventListener.prototype.isTouchHandlerType = function(type) {
|
|
420
|
-
return this.getTouchHandlerType() === type;
|
|
421
|
-
};
|
|
422
|
-
|
|
423
|
-
EventListener.prototype.isTouchHandlerOrAncestor = function(target) {
|
|
424
|
-
var handler = this.getTouchHandler();
|
|
425
|
-
|
|
426
|
-
while (handler) {
|
|
427
|
-
if (handler === target) {
|
|
428
|
-
return true;
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
handler = handler.getParent();
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
return false;
|
|
435
|
-
};
|
|
436
|
-
|
|
437
|
-
EventListener.prototype.countTouches = function(event) {
|
|
438
|
-
var count = event.touches && event.touches.length ? event.touches.length :
|
|
439
|
-
event.originalEvent && event.originalEvent.touches && event.originalEvent.touches.length ? event.originalEvent.touches.length : 1;
|
|
440
|
-
|
|
441
|
-
return count;
|
|
442
|
-
};
|
|
443
|
-
|
|
444
|
-
EventListener.prototype.getTouch = function (event, index) {
|
|
445
|
-
index = index || 0;
|
|
446
|
-
var e = event.touches && event.touches[index] ? event.touches[index] : event.originalEvent && event.originalEvent.touches && event.originalEvent.touches[index] ? event.originalEvent.touches[index] : event;
|
|
447
|
-
|
|
448
|
-
var x = TUtil.isDefined(e.clientX) ? e.clientX : e.pageX || 0;
|
|
449
|
-
var y = TUtil.isDefined(e.clientY) ? e.clientY : e.pageY || 0;
|
|
450
|
-
return {
|
|
451
|
-
x: x,
|
|
452
|
-
y: y,
|
|
453
|
-
originalX: x,
|
|
454
|
-
originalY: y,
|
|
455
|
-
target: e.target,
|
|
456
|
-
timeStamp: browser.now()
|
|
457
|
-
};
|
|
458
|
-
};
|
|
459
|
-
|
|
460
|
-
EventListener.prototype.move = function (event) {
|
|
461
|
-
|
|
462
|
-
var deltaX, deltaY;
|
|
463
|
-
|
|
464
|
-
if (this.touchCount === 1 ) {
|
|
465
|
-
this.start0.y = this.end0 ? this.end0.y : this.start0.y;
|
|
466
|
-
this.start0.x = this.end0 ? this.end0.x : this.start0.x;
|
|
467
|
-
|
|
468
|
-
this.end0 = this.getTouch(event);
|
|
469
|
-
this.start1 = undefined;
|
|
470
|
-
this.end1 = undefined;
|
|
471
|
-
|
|
472
|
-
if (TUtil.isDefined(this.end0)) {
|
|
473
|
-
deltaX = this.start0.x - this.end0.x;
|
|
474
|
-
deltaY = this.start0.y - this.end0.y;
|
|
475
|
-
|
|
476
|
-
this.setDeltaXDeltaY(deltaX, deltaY, 'touch');
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
} else if (this.touchCount >= 2) {
|
|
480
|
-
|
|
481
|
-
this.end0 = this.getTouch(event);
|
|
482
|
-
this.end1 = this.getTouch(event, 1);
|
|
483
|
-
|
|
484
|
-
var length1 = TUtil.distance(this.start0.x, this.start0.y, this.start1.x, this.start1.y);
|
|
485
|
-
var length2 = TUtil.distance(this.end0.x, this.end0.y, this.end1.x, this.end1.y);
|
|
486
|
-
|
|
487
|
-
var diff = length2 - length1;
|
|
488
|
-
|
|
489
|
-
this.currentTouch.pinchDelta = diff > 0 ? 0.3 : diff < 0 ? -0.3 : 0;
|
|
490
|
-
}
|
|
491
|
-
};
|
|
492
|
-
|
|
493
|
-
EventListener.prototype.end = function () {
|
|
494
|
-
|
|
495
|
-
if (this.touchCount <= 1 && this.start0) {
|
|
496
|
-
|
|
497
|
-
var deltaX = 0, deltaY = 0, period = 0;
|
|
498
|
-
|
|
499
|
-
if (this.end0) {
|
|
500
|
-
deltaX = this.start0.x - this.end0.x;
|
|
501
|
-
deltaY = this.start0.y - this.end0.y;
|
|
502
|
-
period = this.end0.timeStamp - this.start0.timeStamp;
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
var momentum;
|
|
506
|
-
|
|
507
|
-
if (this.currentTouch.orientation === "horizontal" && Math.abs(deltaX) > 1) {
|
|
508
|
-
momentum = TUtil.momentum(0, deltaX, period);
|
|
509
|
-
this.currentTouch.deltaX = momentum.distance;
|
|
510
|
-
this.currentTouch.manualMomentumFlag = true;
|
|
511
|
-
this.touchTimeStamp = browser.now() + momentum.duration;
|
|
512
|
-
} else if (this.currentTouch.orientation === "vertical" && Math.abs(deltaY) > 1) {
|
|
513
|
-
momentum = TUtil.momentum(0, deltaY, period);
|
|
514
|
-
this.currentTouch.deltaY = momentum.distance;
|
|
515
|
-
this.currentTouch.manualMomentumFlag = true;
|
|
516
|
-
this.touchTimeStamp = browser.now() + momentum.duration;
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
}
|
|
520
|
-
};
|
|
521
|
-
|
|
522
|
-
EventListener.prototype.setDeltaXDeltaY = function(deltaX, deltaY, source) {
|
|
523
|
-
var diff = Math.abs(deltaX) - Math.abs(deltaY);
|
|
524
|
-
|
|
525
|
-
if (diff >= 1) {
|
|
526
|
-
if (this.currentTouch.orientation === "none" || (this.currentTouch.orientation === "vertical" && diff > 3) || this.currentTouch.orientation === "horizontal") {
|
|
527
|
-
this.currentTouch.orientation = "horizontal";
|
|
528
|
-
this.currentTouch.dir = deltaX <= -1 ? "left" : deltaX >= 1 ? "right" : this.currentTouch.dir;
|
|
529
|
-
this.currentTouch.source = source;
|
|
530
|
-
this.currentTouch.deltaX = deltaX;
|
|
531
|
-
this.currentTouch.deltaY = 0;
|
|
532
|
-
}
|
|
533
|
-
} else if (this.currentTouch.orientation === "none" || (this.currentTouch.orientation === "horizontal" && diff < -3) || this.currentTouch.orientation === "vertical") {
|
|
534
|
-
this.currentTouch.orientation = "vertical";
|
|
535
|
-
this.currentTouch.dir = deltaY <= -1 ? "up" : deltaY >= 1 ? "down" : this.currentTouch.dir;
|
|
536
|
-
this.currentTouch.source = source;
|
|
537
|
-
this.currentTouch.deltaY = deltaY;
|
|
538
|
-
this.currentTouch.deltaX = 0;
|
|
539
|
-
} else {
|
|
540
|
-
this.currentTouch.deltaY = 0;
|
|
541
|
-
this.currentTouch.deltaX = 0;
|
|
542
|
-
}
|
|
543
|
-
};
|
|
544
|
-
|
|
545
|
-
EventListener.prototype.wheel = function (event) {
|
|
546
|
-
var deltaX = 0, deltaY = 0;
|
|
547
|
-
|
|
548
|
-
this.currentTouch.pinchDelta = 0;
|
|
549
|
-
|
|
550
|
-
this.start0 = this.getTouch(event);
|
|
551
|
-
|
|
552
|
-
if (event.ctrlKey && 'deltaY' in event) {
|
|
553
|
-
this.currentTouch.pinchDelta = -event.deltaY / 10;
|
|
554
|
-
} else if ('deltaX' in event) {
|
|
555
|
-
deltaX = event.deltaX;
|
|
556
|
-
deltaY = event.deltaY;
|
|
557
|
-
} else if ('wheelDeltaX' in event) {
|
|
558
|
-
deltaX = -event.wheelDeltaX / 120;
|
|
559
|
-
deltaY = -event.wheelDeltaY / 120;
|
|
560
|
-
} else if ('wheelDelta' in event) {
|
|
561
|
-
deltaX = -event.wheelDelta / 120;
|
|
562
|
-
} else if ('detail' in event) {
|
|
563
|
-
deltaX = event.detail / 3;
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
this.setDeltaXDeltaY(deltaX, deltaY, 'wheel');
|
|
567
|
-
};
|
|
568
|
-
|
|
569
|
-
export { EventListener };
|
|
570
|
-
|