test_touch.html
5.54 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
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,maximum-scale=1,minimum-scale=1,user-scalable=no" />
<title>Dojo Touch Testing</title>
<style type="text/css">
#test {
width: 300px;
height: 150px;
border: 1px solid #7FB0DB;
background-color: #7FB0DB;
}
#innertest {
border: 1px solid white;
width: 100px;
heigh: 75px;
background-color: white;
}
#test2 {
/* for testing touch.move */
width: 200px;
height: 50px;
border: 1px solid yellow;
background-color: yellow;
}
#current, #log {
width: 300px;
height: 200px;
float: left;
}
#dohDiv{
display: none;
}
</style>
<script type="text/javascript" src="../dojo.js" data-dojo-config="async: true"></script>
<script>
require([
"dojo/_base/array",
"dojo/dom",
"dojo/_base/lang",
"dojo/touch",
"dojo/on",
"dojo/has",
"dojo/domReady!"
], function(array, dom, lang, touch, on, has){
var mspointer = navigator.msPointerEnabled; // IE10+ PSPointer events?
var action = function(comment, e){
// summary:
// Callback to display into when events fire
// Detailed log of the most recent event:
dom.byId("current").innerHTML = "Most recent non touch.move event:";
var info = "[Touch Event]: " + e.type + " on " + comment +
"<br/> ------ Event Properties: ------<br/>";
for(var i in e){
if(i == "touches" || i == "targetTouches" || i == "changedTouches"){
info += i + ": " + e[i].length + "<br/>";
}else{
if(typeof e[i] != "function"){
info += " " + i + ": " + e[i] + "<br/>";
}
}
}
dom.byId("current").innerHTML += info + "<br/>";
// This is a log of all events, most recent first:
dom.byId("log").innerHTML = comment + "{type:" +
e.type + ", target:" + (e.target.id||e.target.tagName) +
"}<br/>" + dom.byId("log").innerHTML;
e.preventDefault();
};
var node = dom.byId("test"),
innerNode = dom.byId("innertest");
//1. should work well on PC and touch devices
array.forEach(["test", "innertest"], function(name){
for(var event in touch){
if(event != "move"){
on(dom.byId(name), touch[event], lang.hitch(null, action, "on("+name+", touch."+event+")-->"));
}
}
});
on(dom.byId("test2"), touch.move, function(e){
dom.byId("log").innerHTML = "on(touch2, touch.move)--> {type:" +
e.type + ", target:" + (e.target.id||e.target.tagName) +
", pageX = " + e.pageX + ", pageY = " + e.pageY +
"}<br/>" + dom.byId("log").innerHTML;
// this should stop scrolling
e.preventDefault();
// stopPropagation() should work too
e.stopPropagation();
});
// //2. should work well across touch devices
// on(node, "touchstart", action);
// on(node, "touchmove", action);
// on(node, "touchend", action);
// on(node, "touchcancel", action);
// on(node, "orientationchange", action);
//================================= DoH tests - only running on desktop ======================
if(has("touch")){
//FIXME - DoH not supported on touch device
return;
}
require(["doh/runner", "dojo/dom-style"], function(doh, domStyle){
var dohDiv = dom.byId('dohDiv');
domStyle.set(dohDiv, {display: 'block'});
function setObj(obj, e){
obj.type = e.type;
obj.target = e.target;
}
function assert(obj, type, target){
doh.assertEqual(type, obj.type);
doh.assertEqual(target, obj.target);
}
doh.register("dojo.touch", [
function press(){
var executed, obj = {};
on(dohDiv, touch.press, function(e){
//console.log(e.type);
executed = true;
setObj(obj, e);
});
on.emit(dohDiv, mspointer?'MSPointerDown':'mousedown', {});
doh.assertTrue(executed, 'dojo.touch.press not fired');
assert(obj, mspointer?'MSPointerDown':'mousedown', dohDiv);
},
function move(){
var executed, obj = {};
on(dohDiv, touch.move, function(e){
//console.log(e.type);
executed = true;
setObj(obj, e);
});
on.emit(dohDiv, mspointer?'MSPointerMove':'mousemove', {});
doh.assertTrue(executed, 'dojo.touch.move not fired');
assert(obj, mspointer?'MSPointerMove':'mousemove', dohDiv);
},
function release(){
var executed, obj = {};
on(dohDiv, touch.release, function(e){
//console.log(e.type);
executed = true;
setObj(obj, e);
});
on.emit(dohDiv, mspointer?'MSPointerUp':'mouseup', {screenX: 0, screenY: 50});
doh.assertTrue(executed, 'dojo.touch.release not fired');
assert(obj, mspointer?'MSPointerUp':'mouseup', dohDiv);
},
function cancel(){
var executed, obj = {};
on(dohDiv, touch.cancel, function(e){
executed = true;
setObj(obj, e);
});
on.emit(dohDiv, 'mouseout', {screenX: 0, screenY: 50});
doh.assertTrue(executed, 'dojo.touch.cancel not fired');
assert(obj, 'mouseout', dohDiv);
}
]);
doh.run();
});
});
</script>
</head>
<body>
<div id="test">
test
<div id="innertest">
inner test
</div>
</div>
<div id="test2">
touch.move
</div>
<div id="current"></div>
<div id="log"></div>
<br style="clear:both"/>
<div id="dohDiv">doh</div>
</body>
</html>