Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ However, there are exceptions to this pattern. Please see below.
### touchy-longpress

phase: "start" or "end"
(No data object)

data:

* startPoint

### touchy-drag

Expand Down Expand Up @@ -159,6 +162,7 @@ As shown in the example, the settings are accessed through the camelCased name o
* requiredTouches: 1
* msThresh: 800 (the number of milliseconds the user must touch the element before the event is fired)
* triggerStartPhase: false (whether to trigger the event during the start phase)
* moveTolerance: 2 (distance in pixel allowed during the delay, use negative value for infinite distance)

### touchy-drag

Expand Down
24 changes: 20 additions & 4 deletions jquery.touchy.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@
requiredTouches: 1,
msThresh: 800,
triggerStartPhase: false,
moveTolerance: 2,
data: {
startDate: null
startDate: null,
startPoint: null
},
proxyEvents: ["TouchStart", "TouchEnd"]
proxyEvents: ["TouchStart", "TouchEnd", "TouchMove"]
},
drag: { // the user touches the element and then moves his or her finger across the screen
preventDefault: {
Expand Down Expand Up @@ -175,10 +177,10 @@
};
data.startDate = e.timeStamp;
if (settings.triggerStartPhase) {
$target.trigger('touchy-longpress', ['start', $target]);
$target.trigger('touchy-longpress', ['start', $target, data]);
}
data.timer = setTimeout($.proxy(function(){
$target.trigger('touchy-longpress', ['end', $target]);
$target.trigger('touchy-longpress', ['end', $target, data]);
}, this), settings.msThresh);
break;

Expand Down Expand Up @@ -293,6 +295,20 @@
}
break;

//////////////// LONG PRESS ////////////////
case 'longpress':
if (settings.moveTolerance >= 0) {
var distance = Math.sqrt( Math.pow( (touches[0].pageX - data.startPoint.x), 2 ) + Math.pow( (touches[0].pageY - data.startPoint.y), 2 ) );
if (settings.moveTolerance == 0 || distance > settings.moveTolerance) {
// Invalidate the longpress
clearTimeout(data.timer);
$.extend(data, {
"startDate":null
});
}
}
break;

//////////////// ROTATE ////////////////
case 'rotate':
var lastMovePoint,
Expand Down