forked from AlloyTeam/PhyTouch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alloy_touch.button.js
55 lines (42 loc) · 1.46 KB
/
alloy_touch.button.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
; (function () {
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);
setTimeout(function () {
removeClass(element, active);
}, 150);
};
option.touchMove = function () {
removeClass(element, active);
};
option.touchEnd = function () {
removeClass(element, active);
};
option.touchCancel = function () {
removeClass(element, active);
};
}
new AlloyTouch(option)
}
})();