Touch and tap gestures working

This commit is contained in:
Max Lynch
2013-08-26 15:59:50 -05:00
parent 672007d332
commit 90ea2fd684

View File

@ -11,11 +11,13 @@
// Simple touch gesture that triggers an event when an element is touched // Simple touch gesture that triggers an event when an element is touched
framework.Gesture.Touch = { framework.Gesture.Touch = {
handle: function(e) { handle: function(e) {
if(e.type == 'touchstart') {
framework.EventController.trigger('touch', { framework.EventController.trigger('touch', {
cancelable: true, cancelable: true,
bubbles: true bubbles: true
}); });
} }
}
}; };
// Simple tap gesture // Simple tap gesture
@ -23,20 +25,21 @@
handle: function(e) { handle: function(e) {
switch(e.type) { switch(e.type) {
case 'touchstart': case 'touchstart':
this._touchStartX = e.touches[0].clientX;
this._touchStartY = e.touches[0].clientY;
// We are now touching // We are now touching
this._isTouching = true; this._isTouching = true;
// Reset the movement indicator // Reset the movement indicator
this._hasMoved = false; this._hasMoved = false;
break; break;
case 'touchmove': case 'touchmove':
this._touchStartX = e.type === 'touchstart' ? e.touches[0].clientX : e.clientX; var x = e.touches[0].clientX;
this._touchStartY = e.type === 'touchstart' ? e.touches[0].clientY : e.clientY; y = e.touches[0].clientY;
var x = e.type === 'touchmove' ? e.touches[0].clientX : e.clientX,
y = e.type === 'touchmove' ? e.touches[0].clientY : e.clientY;
// Check if the finger moved more than 10px, and then indicate we should cancel the tap // Check if the finger moved more than 10px, and then indicate we should cancel the tap
if (Math.abs(x - this._touchStartX) > 10 || Math.abs(y - this._touchStartY) > 10) { if (Math.abs(x - this._touchStartX) > 10 || Math.abs(y - this._touchStartY) > 10) {
console.log('HAS MOVED');
this._hasMoved = true; this._hasMoved = true;
} }
break; break;