-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtouch.js
More file actions
91 lines (78 loc) · 2.29 KB
/
touch.js
File metadata and controls
91 lines (78 loc) · 2.29 KB
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
// touch events
var switchbar;
var nicklist;
document.addEventListener('touchstart', handleTouchStart, false);
document.addEventListener('touchmove', handleTouchMove, false);
document.addEventListener("DOMContentLoaded", function () {
switchbar = document.getElementById('switchbar');
nicklist = document.getElementById('nicklist');
updateScreenSize();
switchbar.addEventListener('mouseleave', function (e) {
if (innerWidth < 500) {
switchbar.style.display = 'none';
}
});
nicklist.addEventListener('mouseleave', function (e) {
if (innerWidth < 500) {
nicklist.style.display = 'none';
}
});
});
addEventListener("resize", updateScreenSize);
function updateScreenSize() {
if (innerWidth < 500) {
switchbar.style.display = 'none';
nicklist.style.display = 'none';
}
else {
switchbar.style.display = '';
nicklist.style.display = '';
}
}
var xDown = null;
var yDown = null;
function handleTouchStart(evt) {
xDown = evt.touches[0].clientX;
yDown = evt.touches[0].clientY;
}
function handleTouchMove(evt) {
if (!xDown || !yDown) {
return;
}
var xUp = evt.touches[0].clientX;
var yUp = evt.touches[0].clientY;
var xDiff = xDown - xUp;
var yDiff = yDown - yUp;
if (Math.abs(xDiff) > Math.abs(yDiff)) {/*most significant*/
// left
if (xDiff > 0) {
BS.log('left', xDiff, yDiff, xDown / innerWidth);
if (xDown / innerWidth > .85) {
nicklist.style.display = '';
}
else if (xDown / innerWidth < .40) {
switchbar.style.display = 'none';
}
// right
} else {
BS.log('right', xDiff, yDiff, xDown / innerWidth);
if (xDown / innerWidth > .60) {
nicklist.style.display = 'none';
}
else if (xDown / innerWidth < .15) {
switchbar.style.display = '';
}
}
/* reset values */
xDown = null;
yDown = null;
}
}
addEventListener('mousemove', function (e) {
if (e.clientX < innerWidth * 0.05) {
switchbar.style.display = '';
}
if (e.clientX > innerWidth * 0.95) {
nicklist.style.display = '';
}
});