-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathextendUI.js
56 lines (55 loc) · 1.57 KB
/
extendUI.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
const extendUI = function(comp) { // onuidown, onuimove, onuiup
const istouch = 'ontouchstart' in window;
const usecapture = false;
if (!comp.ratio) {
comp.ratio = 1;
}
if (istouch) {
comp.addEventListener("touchstart", function(e) {
if (this.onuidown != null) {
if (!this.onuidown(
(e.changedTouches[0].pageX - this.offsetLeft) * this.ratio,
(e.changedTouches[0].pageY - this.offsetTop) * this.ratio
)) {
e.preventDefault();
}
}
}, usecapture);
comp.addEventListener("touchmove", function(e) {
if (this.onuimove != null) {
if (!this.onuimove(
(e.changedTouches[0].pageX - this.offsetLeft) * this.ratio,
(e.changedTouches[0].pageY - this.offsetTop) * this.ratio
)) {
e.preventDefault();
}
}
}, usecapture);
comp.addEventListener("touchend", function(e) {
if (this.onuiup != null) {
if (!this.onuiup(
(e.changedTouches[0].pageX - this.offsetLeft) * this.ratio,
(e.changedTouches[0].pageY - this.offsetTop) * this.ratio
)) {
e.preventDefault();
}
}
}, usecapture);
}
comp.addEventListener("mousedown", function(e) {
if (this.onuidown != null) {
this.onuidown(e.offsetX * this.ratio, e.offsetY * this.ratio);
}
}, usecapture);
comp.addEventListener("mousemove", function(e) {
if (this.onuimove != null) {
this.onuimove(e.offsetX * this.ratio, e.offsetY * this.ratio);
}
}, usecapture);
comp.addEventListener("mouseup", function(e) {
if (this.onuiup != null) {
this.onuiup(e.offsetX * this.ratio, e.offsetY * this.ratio);
}
}, usecapture);
};
export { extendUI };