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
|
/*
Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
Available via Academic Free License >= 2.1 OR the modified BSD license.
see: http://dojotoolkit.org/license for details
*/
dojo._xdResourceLoaded(function(dojo, dijit, dojox){
return {depends: [["provide", "dojox.mobile.app._event"]],
defineResource: function(dojo, dijit, dojox){if(!dojo._hasResource["dojox.mobile.app._event"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.mobile.app._event"] = true;
dojo.provide("dojox.mobile.app._event");
dojo.experimental("dojox.mobile.app._event.js");
dojo.mixin(dojox.mobile.app, {
eventMap: {},
connectFlick: function(target, context, method){
// summary:
// Listens for a flick event on a DOM node. If the mouse/touch
// moves more than 15 pixels in any given direction it is a flick.
// The synthetic event fired specifies the direction as
// <ul>
// <li><b>'ltr'</b> Left To Right</li>
// <li><b>'rtl'</b> Right To Left</li>
// <li><b>'ttb'</b> Top To Bottom</li>
// <li><b>'btt'</b> Bottom To Top</li>
// </ul>
// target: Node
// The DOM node to connect to
var startX;
var startY;
var isFlick = false;
var currentX;
var currentY;
var connMove;
var connUp;
var direction;
var time;
// Listen to to the mousedown/touchstart event
var connDown = dojo.connect("onmousedown", target, function(event){
isFlick = false;
startX = event.targetTouches ? event.targetTouches[0].clientX : event.clientX;
startY = event.targetTouches ? event.targetTouches[0].clientY : event.clientY;
time = (new Date()).getTime();
connMove = dojo.connect(target, "onmousemove", onMove);
connUp = dojo.connect(target, "onmouseup", onUp);
});
// The function that handles the mousemove/touchmove event
var onMove = function(event){
dojo.stopEvent(event);
currentX = event.targetTouches ? event.targetTouches[0].clientX : event.clientX;
currentY = event.targetTouches ? event.targetTouches[0].clientY : event.clientY;
if(Math.abs(Math.abs(currentX) - Math.abs(startX)) > 15){
isFlick = true;
direction = (currentX > startX) ? "ltr" : "rtl";
}else if(Math.abs(Math.abs(currentY) - Math.abs(startY)) > 15){
isFlick = true;
direction = (currentY > startY) ? "ttb" : "btt";
}
};
var onUp = function(event){
dojo.stopEvent(event);
connMove && dojo.disconnect(connMove);
connUp && dojo.disconnect(connUp);
if(isFlick){
var flickEvt = {
target: target,
direction: direction,
duration: (new Date()).getTime() - time
};
if(context && method){
context[method](flickEvt);
}else{
method(flickEvt);
}
}
};
}
});
dojox.mobile.app.isIPhone = (dojo.isSafari
&& (navigator.userAgent.indexOf("iPhone") > -1 ||
navigator.userAgent.indexOf("iPod") > -1
));
dojox.mobile.app.isWebOS = (navigator.userAgent.indexOf("webOS") > -1);
dojox.mobile.app.isAndroid = (navigator.userAgent.toLowerCase().indexOf("android") > -1);
if(dojox.mobile.app.isIPhone || dojox.mobile.app.isAndroid){
// We are touchable.
// Override the dojo._connect function to replace mouse events with touch events
dojox.mobile.app.eventMap = {
onmousedown: "ontouchstart",
mousedown: "ontouchstart",
onmouseup: "ontouchend",
mouseup: "ontouchend",
onmousemove: "ontouchmove",
mousemove: "ontouchmove"
};
}
dojo._oldConnect = dojo._connect;
dojo._connect = function(obj, event, context, method, dontFix){
event = dojox.mobile.app.eventMap[event] || event;
if(event == "flick" || event == "onflick"){
if(dojo.global["Mojo"]){
event = Mojo.Event.flick;
}else{
return dojox.mobile.app.connectFlick(obj, context, method);
}
}
return dojo._oldConnect(obj, event, context, method, dontFix);
}
}
}};});
|