Skip to content

Commit

Permalink
Reset start time on first move, to fix use case where use mousedowns,
Browse files Browse the repository at this point in the history
touchstarts but doesn't move their finger for a while.

Fixes #2530187

Still need to fix the case where user changes direction before
mouseup/touchend. See #2530220.
  • Loading branch information
sdesai committed Jul 24, 2011
1 parent 449d9d2 commit 1fed2eb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/event-gestures/HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ Gestures
3.4.0
-----

* No changes
* For flick, reset start time on first move, to handle
case where user mousesdown/touchstarts but then doesn't
move their finger for 5s leading to inaccurate velocity.

3.3.0
-----
Expand Down
32 changes: 26 additions & 6 deletions src/event-gestures/js/Flick.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@

var EVENT = ("ontouchstart" in Y.config.win && !Y.UA.chrome) ? {
start: "touchstart",
end: "touchend"
end: "touchend",
move: "touchmove"
} : {
start: "mousedown",
end: "mouseup"
end: "mouseup",
move: "mousemove"
},

START = "start",
END = "end",
MOVE = "move",

OWNER_DOCUMENT = "ownerDocument",
MIN_VELOCITY = "minVelocity",
Expand All @@ -36,6 +39,7 @@ var EVENT = ("ontouchstart" in Y.config.win && !Y.UA.chrome) ? {
_FLICK_START = "_fs",
_FLICK_START_HANDLE = "_fsh",
_FLICK_END_HANDLE = "_feh",
_FLICK_MOVE_HANDLE = "_fmh",

NODE_TYPE = "nodeType";

Expand Down Expand Up @@ -122,6 +126,7 @@ Y.Event.define('flick', {

var start = true, // always true for mouse
endHandle,
moveHandle,
doc,
preventDefault = subscriber._extra.preventDefault,
origE = e;
Expand All @@ -148,12 +153,22 @@ Y.Event.define('flick', {

endHandle = subscriber[_FLICK_END_HANDLE];

doc = (node.get(NODE_TYPE) === 9) ? node : node.get(OWNER_DOCUMENT);
if (!endHandle) {
doc = (node.get(NODE_TYPE) === 9) ? node : node.get(OWNER_DOCUMENT);

endHandle = doc.on(EVENT[END], Y.bind(this._onEnd, this), null, node, subscriber, ce);
subscriber[_FLICK_END_HANDLE] = endHandle;
}

subscriber[_FLICK_MOVE_HANDLE] = doc.once(EVENT[MOVE], Y.bind(this._onMove, this), null, node, subscriber, ce);
}
},

_onMove: function(e, node, subscriber, ce) {
var start = subscriber[_FLICK_START];

// Start timing from first move.
if (start && start.flick) {
start.flick.time = new Date().getTime();
}
},

Expand All @@ -170,7 +185,13 @@ Y.Event.define('flick', {
xyDistance,
distance,
velocity,
axis;
axis,
moveHandle = subscriber[_FLICK_MOVE_HANDLE];

if (moveHandle) {
moveHandle.detach();
delete subscriber[_FLICK_MOVE_HANDLE];
}

if (valid) {

Expand Down Expand Up @@ -198,7 +219,6 @@ Y.Event.define('flick', {
endTime = new Date().getTime();
time = endTime - startTime;


xyDistance = [
endEvent.pageX - start.pageX,
endEvent.pageY - start.pageY
Expand Down

0 comments on commit 1fed2eb

Please sign in to comment.