-
Notifications
You must be signed in to change notification settings - Fork 4
/
touch.html
135 lines (123 loc) · 3.7 KB
/
touch.html
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=0" />
<title>jQueryTouch test page</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<script type="text/javascript" src="jquery.touch.js"></script>
</head>
<style>
body
{
-ms-content-zoom-boundary-max: 100%;
-ms-content-zoom-boundary-min: 100%;
}
#test-area
{
background-color: black;
color: white;
height: 400px;
text-align: center;
}
#last-event
{
background-color: white;
position: absolute;
top: 0;
}
#original-event
{
background-color: white;
position: absolute;
top: 0;
right: 0;
height: 300px;
overflow: hidden;
}
.string
{
color: green;
}
.number
{
color: darkorange;
}
.boolean
{
color: blue;
}
.null
{
color: magenta;
}
.key
{
color: red;
}
</style>
<body>
<div id="test-area">
Test area</div>
<div id="last-event">
<p id="last-event-name">
</p>
<pre id="last-event-detail"></pre>
</div>
<div id="original-event">
</div>
<script>
function syntaxHighlight(json) {
if (typeof json != 'string') {
json = JSON.stringify(json, undefined, 2);
}
json = json.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
var cls = 'number';
if (/^"/.test(match)) {
if (/:$/.test(match)) {
cls = 'key';
} else {
cls = 'string';
}
} else if (/true|false/.test(match)) {
cls = 'boolean';
} else if (/null/.test(match)) {
cls = 'null';
}
return '<span class="' + cls + '">' + match + '</span>';
});
}
$("#test-area").touchInit();
var timeout_id = null;
var last_original_event = null;
var handler = function (e) {
$("#last-event-name").text(e.type);
var showData =
{
clientX: e.clientX,
clientY: e.clientY,
pageX: e.pageX,
pageY: e.pageY,
screenX: e.screenX,
screenY: e.screenY,
touches: e.touches
};
$("#last-event-detail").html(syntaxHighlight(JSON.stringify(showData, undefined, 2)));
if (last_original_event != e.originalType) {
last_original_event = e.originalType;
$("#original-event").html(e.originalType + "<br/>" + $("#original-event").html());
if (timeout_id !== null) window.clearTimeout(timeout_id);
timeout_id = window.setTimeout(
function () {
$("#original-event").html("");
},
5000);
}
};
$("#test-area").on("touch_start", handler);
$("#test-area").on("touch_move", handler);
$("#test-area").on("touch_end", handler);
</script>
</body>
</html>