-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
93 lines (78 loc) · 2.34 KB
/
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
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
91
92
93
;
(function () {
var AlloyTouch = typeof require === 'function' ? require('./lib/alloytouch/alloy_touch') : window.AlloyTouch
function addClass (element, className) {
if (element.classList) {
element.classList.add(className)
} else {
element.className += ' ' + className
}
}
function removeClass (element, className) {
if (element.classList) {
element.classList.remove(className)
} else {
element.className = element.className.replace(new RegExp('(^|\\b)' + className.split(' ').join('|') + '(\\b|$)', 'gi'), ' ')
}
}
AlloyTouch.Button = function (selector, tap, active) {
var element = typeof selector === 'string' ? document.querySelector(selector) : selector
var option = {
touch: selector,
tap: tap,
preventDefault: false
}
if (active !== undefined) {
option.touchStart = function () {
addClass(element, active)
}
option.touchMove = function () {
removeClass(element, active)
}
option.touchEnd = function () {
removeClass(element, active)
}
option.touchCancel = function () {
removeClass(element, active)
}
}
new AlloyTouch(option)
}
let vueAlloyTouch = {}
vueAlloyTouch.install = function (Vue) {
var isVue2 = !!(Vue.version.substr(0, 1) == 2)
if (!AlloyTouch) {
throw new Error('you need include alloy_touch.js')
}
var directiveBinding = null
if (isVue2) {
directiveBinding = {
bind: function (el, binding) {
// 注册时的赋值 value, el已经挂载
let classNmae = binding.expression ? binding.expression : 'active'
classNmae=classNmae.replace(/\'/g,"")
new AlloyTouch.Button(el, function () {}, classNmae)
},
update: function (el, binding) {},
unbind: function (el) {}
}
} else {
directiveBinding = {
bind: function () {
console.log('vue 1 没有测试')
new AlloyTouch.Button(el, function () {
}, 'active')
},
update: function (binding) {
},
unbind: function () {}
}
}
Vue.directive('vtac', directiveBinding)
}
if (typeof module !== 'undefined' && typeof exports === 'object') {
module.exports = vueAlloyTouch
} else {
window.vueAlloyTouch = vueAlloyTouch
}
})()