Permalink
Browse files

updates tests to do everything async, updates touch to fix some logic…

… errors with single/double tapping. TODO: touch.js minor refactor
  • Loading branch information...
1 parent 80392e9 commit f1b0b84e3ef32cf113b9e0dbc352c1e1482a520e @hunterloftis hunterloftis committed with Apr 30, 2012
Showing with 37 additions and 16 deletions.
  1. +14 −11 src/touch.js
  2. +23 −5 test/touch.html
View
@@ -58,13 +58,8 @@
}).bind('touchend', function(e){
cancelLongTap()
- // double tap (tapped twice within 250ms)
- if (touch.isDoubleTap) {
- touch.el.trigger('doubleTap')
- touch = {}
-
// swipe
- } else if ((touch.x2 && Math.abs(touch.x1 - touch.x2) > 30) ||
+ if ((touch.x2 && Math.abs(touch.x1 - touch.x2) > 30) ||
(touch.y2 && Math.abs(touch.y1 - touch.y2) > 30)) {
swipeTimeout = setTimeout(function() {
touch.el.trigger('swipe') &&
@@ -78,13 +73,21 @@
var event = $.Event('tap');
event.cancelTouch = cancelAll;
touch.el.trigger(event)
+
+ if (touch.isDoubleTap) {
+ touch.el.trigger('doubleTap')
+ touch = {}
+ }
+ else {
+ touchTimeout = setTimeout(function(){
+ touchTimeout = null
+ touch.el.trigger('singleTap')
+ touch = {}
+ }, 250)
+ }
+
}, 0);
- touchTimeout = setTimeout(function(){
- touchTimeout = null
- touch.el.trigger('singleTap')
- touch = {}
- }, 250)
}
}).bind('touchcancel', cancelAll)
View
@@ -79,7 +79,12 @@
down(element, 10, 10)
up(element)
- t.assertEqual(1, count)
+ t.pause()
+ setTimeout(function(){
+ t.resume(function(){
+ t.assertEqual(1, count)
+ })
+ }, 50)
},
testSingleTapDoesNotInterfereWithTappingTwice: function(t){
@@ -92,15 +97,16 @@
down(element, 10, 10)
up(element)
+
t.pause()
setTimeout(function(){
down(element, 10, 10)
+ up(element)
t.resume(function(){
t.pause()
setTimeout(function(){
- up(element)
t.resume(function(){
t.assertEqual(2, count)
})
@@ -150,8 +156,14 @@
up(element)
t.resume(function(){
- t.assertEqual(0, singleCount)
- t.assertEqual(1, doubleCount)
+ t.pause()
+
+ setTimeout(function(){
+ t.resume(function(){
+ t.assertEqual(0, singleCount)
+ t.assertEqual(1, doubleCount)
+ })
+ }, 100)
})
}, 100)
},
@@ -215,7 +227,13 @@
up(element)
t.resume(function(){
- t.assertEqual(1, swipeCount)
+ t.pause()
+
+ setTimeout(function(){
+ t.resume(function(){
+ t.assertEqual(1, swipeCount)
+ })
+ }, 50)
})
}, 50)
}

0 comments on commit f1b0b84

Please sign in to comment.