1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
| export default {
| methods: {
| touchtrack: function (method) {
| const self = this
| let x0 = 0
| let y0 = 0
| let x1 = 0
| let y1 = 0
| const fn = function ($event, state, x, y) {
| if (self[method]({
| target: $event.target,
| currentTarget: $event.currentTarget,
| stopPropagation: $event.stopPropagation.bind($event),
| touches: $event.touches,
| changedTouches: $event.changedTouches,
| detail: {
| state,
| x0: x,
| y0: y,
| dx: x - x0,
| dy: y - y0,
| ddx: x - x1,
| ddy: y - y1,
| timeStamp: $event.timeStamp
| }
| }) === false) {
| return false
| }
| }
|
| let $eventOld = null
| this.addListener('touchstart', function ($event) {
| if (!$eventOld) {
| $eventOld = $event
| x0 = x1 = $event.touches[0].pageX
| y0 = y1 = $event.touches[0].pageY
| return fn($event, 'start', x0, y0)
| }
| })
| this.addListener('touchmove', function ($event) {
| if ($eventOld) {
| const res = fn($event, 'move', $event.touches[0].pageX, $event.touches[0].pageY)
| x1 = $event.touches[0].pageX
| y1 = $event.touches[0].pageY
| return res
| }
| })
| this.addListener('touchend', function ($event) {
| if ($eventOld) {
| $eventOld = null
| return fn($event, 'end', $event.changedTouches[0].pageX, $event.changedTouches[0].pageY)
| }
| })
| },
| touchstart ($event) {
| this.callback('touchstart', $event)
| },
| touchmove ($event) {
| this.callback('touchmove', $event)
| },
| touchend ($event) {
| this.callback('touchend', $event)
| },
| addListener (type, callback) {
| this.__event[type] = function ($event) {
| if (typeof callback === 'function') {
| $event.touches = $event.changedTouches
| if (callback($event) === false) {
| $event.stopPropagation()
| }
| }
| }
| },
| callback (type, $event) {
| if (this.__event[type]) {
| this.__event[type]($event)
| }
| }
| },
| created () {
| this.__event = {}
| }
| }
|
|