]>
git.wh0rd.org - tt-rss.git/blob - lib/dojo/touch.js.uncompressed.js
1 define("dojo/touch", ["./_base/kernel", "./aspect", "./dom", "./on", "./has", "./mouse", "./ready", "./_base/window"],
2 function(dojo
, aspect
, dom
, on
, has
, mouse
, ready
, win
){
7 var hasTouch
= has("touch");
9 // TODO: get iOS version from dojo/sniff after #15827 is fixed
12 var ua
= navigator
.userAgent
;
13 var v
= ua
.match(/OS ([\d_]+)/) ? RegExp
.$1 : "1";
14 var os
= parseFloat(v
.replace(/_/, '.').replace(/_
/g
, ''));
18 var touchmove
, hoveredNode
;
22 // Keep track of currently hovered node
23 hoveredNode
= win
.body(); // currently hovered node
25 win
.doc
.addEventListener("touchstart", function(evt
){
26 // Precede touchstart event with touch.over event. DnD depends on this.
27 // Use addEventListener(cb, true) to run cb before any touchstart handlers on node run,
28 // and to ensure this code runs even if the listener on the node does event.stop().
29 var oldNode
= hoveredNode
;
30 hoveredNode
= evt
.target
;
31 on
.emit(oldNode
, "dojotouchout", {
33 relatedTarget
: hoveredNode
,
36 on
.emit(hoveredNode
, "dojotouchover", {
38 relatedTarget
: oldNode
,
43 // Fire synthetic touchover and touchout events on nodes since the browser won't do it natively.
44 on(win
.doc
, "touchmove", function(evt
){
45 var newNode
= win
.doc
.elementFromPoint(
46 evt
.pageX
- (ios4
? 0 : win
.global
.pageXOffset
), // iOS 4 expects page coords
47 evt
.pageY
- (ios4
? 0 : win
.global
.pageYOffset
)
49 if(newNode
&& hoveredNode
!== newNode
){
50 // touch out on the old node
51 on
.emit(hoveredNode
, "dojotouchout", {
53 relatedTarget
: newNode
,
57 // touchover on the new node
58 on
.emit(newNode
, "dojotouchover", {
60 relatedTarget
: hoveredNode
,
64 hoveredNode
= newNode
;
69 // Define synthetic touch.move event that unlike the native touchmove, fires for the node the finger is
70 // currently dragging over rather than the node where the touch started.
71 touchmove = function(node
, listener
){
72 return on(win
.doc
, "touchmove", function(evt
){
73 if(node
=== win
.doc
|| dom
.isDescendant(hoveredNode
, node
)){
74 evt
.target
= hoveredNode
;
75 listener
.call(this, evt
);
82 function _handle(type
){
84 // press | move | release | cancel
86 return function(node
, listener
){//called by on(), see dojo.on
87 return on(node
, type
, listener
);
91 //device neutral events - touch.press|move|release|cancel/over/out
93 press
: _handle(hasTouch
? "touchstart": "mousedown"),
94 move: hasTouch
? touchmove
:_handle("mousemove"),
95 release
: _handle(hasTouch
? "touchend": "mouseup"),
96 cancel
: hasTouch
? _handle("touchcancel") : mouse
.leave
,
97 over
: _handle(hasTouch
? "dojotouchover": "mouseover"),
98 out
: _handle(hasTouch
? "dojotouchout": "mouseout"),
99 enter
: mouse
._eventHandler(hasTouch
? "dojotouchover" : "mouseover"),
100 leave
: mouse
._eventHandler(hasTouch
? "dojotouchout" : "mouseout")
105 // This module provides unified touch event handlers by exporting
106 // press, move, release and cancel which can also run well on desktop.
107 // Based on http://dvcs.w3.org/hg/webevents/raw-file/tip/touchevents.html
111 // | define(["dojo/on", "dojo/touch"], function(on, touch){
112 // | on(node, touch.press, function(e){});
113 // | on(node, touch.move, function(e){});
114 // | on(node, touch.release, function(e){});
115 // | on(node, touch.cancel, function(e){});
117 // Used with touch.* directly
118 // | touch.press(node, function(e){});
119 // | touch.move(node, function(e){});
120 // | touch.release(node, function(e){});
121 // | touch.cancel(node, function(e){});
123 press: function(node, listener){
125 // Register a listener to 'touchstart'|'mousedown' for the given node
127 // Target node to listen to
128 // listener: Function
131 // A handle which will be used to remove the listener by handle.remove()
133 move: function(node, listener){
135 // Register a listener to 'touchmove'|'mousemove' for the given node
137 // Target node to listen to
138 // listener: Function
141 // A handle which will be used to remove the listener by handle.remove()
143 release: function(node, listener){
145 // Register a listener to 'touchend'|'mouseup' for the given node
147 // Target node to listen to
148 // listener: Function
151 // A handle which will be used to remove the listener by handle.remove()
153 cancel: function(node, listener){
155 // Register a listener to 'touchcancel'|'mouseleave' for the given node
157 // Target node to listen to
158 // listener: Function
161 // A handle which will be used to remove the listener by handle.remove()
163 over: function(node, listener){
165 // Register a listener to 'mouseover' or touch equivalent for the given node
167 // Target node to listen to
168 // listener: Function
171 // A handle which will be used to remove the listener by handle.remove()
173 out: function(node, listener){
175 // Register a listener to 'mouseout' or touch equivalent for the given node
177 // Target node to listen to
178 // listener: Function
181 // A handle which will be used to remove the listener by handle.remove()
183 enter: function(node, listener){
185 // Register a listener to mouse.enter or touch equivalent for the given node
187 // Target node to listen to
188 // listener: Function
191 // A handle which will be used to remove the listener by handle.remove()
193 leave: function(node, listener){
195 // Register a listener to mouse.leave or touch equivalent for the given node
197 // Target node to listen to
198 // listener: Function
201 // A handle which will be used to remove the listener by handle.remove()
206 1 && (dojo
.touch
= touch
);