Skip to content

Commit

Permalink
Merge branch 'master' into ie10
Browse files Browse the repository at this point in the history
Conflicts:
	src/touch.js
	test/touch.html
  • Loading branch information
madrobby committed Sep 17, 2013
2 parents 439a49a + 9937686 commit ecdeb09
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 24 deletions.
59 changes: 35 additions & 24 deletions src/touch.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
}

$(document).ready(function(){
var now, delta, firstTouch
var now, delta, deltaX = 0, deltaY = 0, firstTouch

if ('MSGesture' in window) {
gesture = new MSGesture()
Expand Down Expand Up @@ -78,6 +78,9 @@
cancelLongTap()
touch.x2 = firstTouch.pageX
touch.y2 = firstTouch.pageY

deltaX += Math.abs(touch.x1 - touch.x2)
deltaY += Math.abs(touch.y1 - touch.y2)
})
.on('touchend MSPointerUp', function(e){
if(e.type == 'MSPointerUp' && !isPrimaryTouch(e)) return;
Expand All @@ -95,31 +98,39 @@

// normal tap
else if ('last' in touch)
// delay by one tick so we can cancel the 'tap' event if 'scroll' fires
// ('tap' fires before 'scroll')
tapTimeout = setTimeout(function() {

// trigger universal 'tap' with the option to cancelTouch()
// (cancelTouch cancels processing of single vs double taps for faster 'tap' response)
var event = $.Event('tap')
event.cancelTouch = cancelAll
touch.el.trigger(event)

// trigger double tap immediately
if (touch.isDoubleTap) {
touch.el.trigger('doubleTap')
touch = {}
}

// trigger single tap after 250ms of inactivity
else
touchTimeout = setTimeout(function(){
touchTimeout = null
touch.el.trigger('singleTap')
// don't fire tap when delta position changed by more than 30 pixels,
// for instance when moving to a point and back to origin
if (deltaX < 30 && deltaY < 30) {
// delay by one tick so we can cancel the 'tap' event if 'scroll' fires
// ('tap' fires before 'scroll')
tapTimeout = setTimeout(function() {

// trigger universal 'tap' with the option to cancelTouch()
// (cancelTouch cancels processing of single vs double taps for faster 'tap' response)
var event = $.Event('tap')
event.cancelTouch = cancelAll
touch.el.trigger(event)

// trigger double tap immediately
if (touch.isDoubleTap) {
touch.el.trigger('doubleTap')
touch = {}
}, 250)
}

// trigger single tap after 250ms of inactivity
else {
touchTimeout = setTimeout(function(){
touchTimeout = null
touch.el.trigger('singleTap')
touch = {}
}, 250)
}
}, 0)
} else {
touch = {}
}
deltaX = deltaY = 0

}, 0)
})
// when the browser window loses focus,
// for example when a modal dialog is shown,
Expand Down
24 changes: 24 additions & 0 deletions test/touch.html
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,30 @@ <h1>Touch tests</h1>
}, 50)
})
}, 50)
},

testTapDoNotFireWhenMoveToPointAndBack: function (t) {
var tapCount = 0, element = $('#test').get(0)

$('#test').on('tap', function(){
tapCount++
})
down(element, 10, 10)
move(element, 60, 10)

t.pause()
setTimeout(function(){
t.resume(function(){
move(element, 10, 10)
up(element)
t.pause()
setTimeout(function(){
t.resume( function () {
t.assertEqual(0, tapCount)
})
}, 100)
})
}, 100)
}

// TODO: test swipes in specific directions
Expand Down

0 comments on commit ecdeb09

Please sign in to comment.