-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
31 lines (26 loc) · 844 Bytes
/
index.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
exports.install = function (Vue, options) {
if (!options) options = {}
if (!options.duration) options.duration = 2000
Vue.directive('long-press', {
bind: function (el, binding) {
var self = this
this._timeout = null
this._onmouseup = function () {
clearTimeout(self._timeout)
}
this._onmousedown = function (e) {
var context = this
self._timeout = setTimeout(function () {
binding.value.call(context, e)
}, options.duration)
}
el.addEventListener('mousedown', this._onmousedown)
document.addEventListener('mouseup', this._onmouseup)
},
unbind: function (el) {
clearTimeout(this._timeout)
el.removeEventListener('mousedown', this._onmousedown)
document.removeEventListener('mouseup', this._onmouseup)
}
})
}