-
Notifications
You must be signed in to change notification settings - Fork 0
/
vue-finger.js
90 lines (82 loc) · 2.32 KB
/
vue-finger.js
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
84
85
86
87
88
89
90
;(function () {
var vueFinger = {}
var AlloyFinger = typeof require === 'function'
? require('alloyfinger')
: window.AlloyFinger
var gestures = {
touchstart: 'touchStart',
touchmove: 'touchMove',
touchend: 'touchEnd',
touchcancel: 'touchCancel',
multipointstart: 'multipointStart',
multipointend: 'multipointEnd',
tap: 'tap',
doubletap: 'doubleTap',
longtap: 'longTap',
singletap: 'singleTap',
rotate: 'rotate',
pinch: 'pinch',
pressmove: 'pressMove',
swipe: 'swipe'
}
if (!AlloyFinger) {
throw new Error('[vue-touch] cannot locate alloyfinger.')
}
// exposed global options
vueFinger.config = {}
vueFinger.install = function (Vue) {
Vue.directive('finger', {
bind: function (el, binding) {
var event = binding.arg
var fn = binding.value
var gs = Object.keys( gestures )
var recognizerType, i
if (!event) {
console.warn('[vue-finger] event type argument is required.')
} else if (typeof fn !== 'function') {
console.warn(
'[vue-finger] invalid handler function for v-finger: ' +
event + '="' + fn
)
return
} else {
for (i = 0; i < gs.length; i++) {
if (event.indexOf(gs[i]) === 0) {
recognizerType = gestures[gs[i]]
break
}
}
if (!recognizerType) {
console.warn('[vue-finger] invalid event type: ' + event)
return
}
}
// built-in event
if (!el.alloyfinger) {
el.alloyfinger = new AlloyFinger(el, _defineProperty({}, recognizerType, fn))
} else {
el.alloyfinger[recognizerType] = fn
}
},
unbind: function (el) {
el.alloyfinger = null
}
})
}
function _defineProperty (obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true })
} else {
obj[key] = value;
}
return obj
}
if (typeof exports == "object") {
module.exports = vueFinger
} else if (typeof define == "function" && define.amd) {
define([], function(){ return vueFinger })
} else if (window.Vue) {
window.VueFinger = vueFinger
Vue.use(vueFinger)
}
})()