Skip to content

Commit 4f97d20

Browse files
author
@soyjavi
committed
Remove unnecesary events: tap/singleTap ... "touch" improved.
1 parent a1fd003 commit 4f97d20

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

source/quo.gestures.basic.coffee

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
###
2-
Quo Basic Gestures: tap, hold, singleTap, doubleTap
2+
Quo Basic Gestures: touch, hold, doubleTap
33
44
@namespace Quo.Gestures
55
@class Basic
@@ -11,17 +11,16 @@ Quo Basic Gestures: tap, hold, singleTap, doubleTap
1111

1212
Quo.Gestures.add
1313
name : "basic"
14-
events : ["tap", "hold", "singleTap", "doubleTap", "touch"]
14+
events : ["touch", "hold", "doubleTap"]
1515

1616
handler : do (base = Quo.Gestures) ->
1717
GAP = 15
1818
DELAY =
19-
TAP : 250
19+
TAP : 200
2020
DOUBLE_TAP: 400
2121
HOLD : 400
2222

2323
_hold_timeout = null
24-
_simpletap_timeout = null
2524
_valid = true
2625
_target = null
2726
_start = null
@@ -38,33 +37,36 @@ Quo.Gestures.add
3837

3938
move = (target, data) ->
4039
if _start isnt null
41-
xDiff = data[0].x - _start.x
42-
yDiff = data[0].y - _start.y
43-
if xDiff > GAP or yDiff > GAP or data.length > 1
44-
do cancel
40+
diff = _calculateDiff _start, data[0]
41+
do cancel if diff.x > GAP or diff.y > GAP or data.length > 1
4542

4643
end = (target, data) ->
47-
base.trigger(target, "touch", data[0])
4844
return unless _start
45+
46+
diff = _calculateDiff _start, data[0]
47+
return cancel() if diff.x isnt 0 or diff.y isnt 0
48+
49+
# base.trigger target, "touch", data[0]
4950
clearTimeout _hold_timeout
5051
now = new Date()
5152
if (now - _start.time) < DELAY.TAP
5253
if (now - _last_tap) < DELAY.DOUBLE_TAP
53-
clearTimeout _simpletap_timeout
54-
base.trigger(target, "doubleTap", data[0])
54+
base.trigger target, "doubleTap", data[0]
5555
_last_tap = null
5656
else
5757
_last_tap = now
58-
base.trigger(target, "tap", data[0])
59-
_simpletap_timeout = setTimeout ->
60-
base.trigger(target, "singleTap", data[0])
61-
, DELAY.DOUBLE_TAP + 5
58+
# base.trigger target, "tap", data[0]
59+
base.trigger target, "touch", data[0]
6260

6361
cancel = () ->
6462
_start = null
6563
_valid = false
6664
clearTimeout _hold_timeout
67-
clearTimeout _simpletap_timeout
65+
66+
_calculateDiff = (start, end) ->
67+
diff =
68+
x: end.x - start.x
69+
y: end.y - start.y
6870

6971
start : start
7072
move : move

0 commit comments

Comments
 (0)