Skip to content

Commit

Permalink
revert touch changes (bug)
Browse files Browse the repository at this point in the history
  • Loading branch information
madrobby committed Feb 9, 2011
1 parent 5c145c3 commit f4e92d3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 28 deletions.
25 changes: 6 additions & 19 deletions src/touch.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(function($){
var touch = {}, touchTimeout, longTapTimeout;
var touch = {}, touchTimeout;

function parentIfText(node){
return 'tagName' in node ? node : node.parentNode;
Expand All @@ -11,31 +11,18 @@
touch.target = parentIfText(e.touches[0].target);
touchTimeout && clearTimeout(touchTimeout);
touch.x1 = e.touches[0].pageX;
touch.y1 = e.touches[0].pageY;
if (delta > 0 && delta <= 250) touch.isDoubleTap = true;
touch.last = now;
longTapTimeout = setTimeout(function(){
longTapTimeout = null;
$(touch.target).trigger('longTap')
touch = {};
}, 1000);
}).bind('touchmove', function(e){
touch.x2 = e.touches[0].pageX
touch.y2 = e.touches[0].pageY
}).bind('touchend', function(e){
clearTimeout(longTapTimeout);
if (touch.isDoubleTap) {
$(touch.target).trigger('doubleTap');
touch = {};
} else if (touch.x2 > 0 || touch.y2 > 0) {
} else if (touch.x2 > 0) {
Math.abs(touch.x1 - touch.x2) > 30 && $(touch.target).trigger('swipe') &&
$(touch.target).trigger('swipe' + (touch.x1 - touch.x2 > 0 ? 'Left' : 'Right'));
touch.x1 = touch.x2 = touch.last = 0
if (Zepto.enableUpDownSwipe) {
Math.abs(touch.y1 - touch.y2) > 30 && $(touch.target).trigger('swipe') &&
$(touch.target).trigger('swipe' + (touch.y1 - touch.y2 > 0 ? 'Up' : 'Down'));
touch.y1 = touch.y2 = 0;
}
$(touch.target).trigger('swipe' + (touch.x1 - touch.x2 > 0 ? 'Left' : 'Right'));
touch.x1 = touch.x2 = touch.last = 0;
} else if ('last' in touch) {
touchTimeout = setTimeout(function(){
touchTimeout = null;
Expand All @@ -46,7 +33,7 @@
}).bind('touchcancel', function(){ touch = {} });
});

['swipe', 'swipeLeft', 'swipeRight', 'swipeUp', 'swipeDown', 'doubleTap', 'tap', 'longTap'].forEach(function(m){
['swipe', 'swipeLeft', 'swipeRight', 'doubleTap', 'tap'].forEach(function(m){
$.fn[m] = function(callback){ return this.bind(m, callback) }
});
})(Zepto);
})(Zepto);
9 changes: 0 additions & 9 deletions test/touch_functional.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ <h1>Zepto touch functional test</h1>
.tap(function(){
$(this).append(' | tap!');
})
.longTap(function(){
$(this).append(' | long tap!');
})
.doubleTap(function(){
$(this).append(' | double tap!');
})
Expand All @@ -35,12 +32,6 @@ <h1>Zepto touch functional test</h1>
})
.swipeRight(function(){
$(this).append(' | swipe right!');
})
.swipeUp(function(){
$(this).append(' | swipe up!');
})
.swipeDown(function(){
$(this).append(' | swipe down!');
});
</script>
</body>
Expand Down

0 comments on commit f4e92d3

Please sign in to comment.