Skip to content

Commit

Permalink
updates tests to do everything async, updates touch to fix some logic…
Browse files Browse the repository at this point in the history
… errors with single/double tapping. TODO: touch.js minor refactor
  • Loading branch information
hunterloftis authored and madrobby committed Jul 14, 2012
1 parent 80392e9 commit f1b0b84
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 16 deletions.
25 changes: 14 additions & 11 deletions src/touch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') &&
Expand All @@ -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)

Expand Down
28 changes: 23 additions & 5 deletions test/touch.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ <h1>Touch tests</h1>
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){
Expand All @@ -92,15 +97,16 @@ <h1>Touch tests</h1>
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)
})
Expand Down Expand Up @@ -150,8 +156,14 @@ <h1>Touch tests</h1>
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)
},
Expand Down Expand Up @@ -215,7 +227,13 @@ <h1>Touch tests</h1>
up(element)

t.resume(function(){
t.assertEqual(1, swipeCount)
t.pause()

setTimeout(function(){
t.resume(function(){
t.assertEqual(1, swipeCount)
})
}, 50)
})
}, 50)
}
Expand Down

0 comments on commit f1b0b84

Please sign in to comment.