Skip to content

Commit

Permalink
Merge branch 'ie-touch' of https://github.com/charsleysa/zepto into c…
Browse files Browse the repository at this point in the history
…harsleysa-ie-touch
  • Loading branch information
madrobby committed Sep 15, 2013
2 parents 351226f + d7198e7 commit 299aa61
Showing 1 changed file with 31 additions and 13 deletions.
44 changes: 31 additions & 13 deletions src/touch.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,30 +38,48 @@
touch = {}
}

var gesture;
if ('undefined' !== typeof(MSGesture)) {
gesture = new MSGesture();
gesture.target = document.body;
}

$(document).ready(function(){
var now, delta

$(document.body)
.bind('touchstart', function(e){
.bind('MSGestureEnd', function(e){
var swipe_dir = e.velocityX > 1 ? 'Right' : e.velocityX < -1 ? 'Left' : e.velocityY > 1 ? 'Down' : e.velocityY < -1 ? 'Up' : null;
if (swipe_dir) {
touch.el.trigger('swipe')
touch.el.trigger('swipe'+ swipe_dir)
}
})
.on('touchstart MSPointerDown', function(e){
if(e.type == 'MSPointerDown' && (e.pointerType != e.MSPOINTER_TYPE_TOUCH || !e.isPrimary)) return;
now = Date.now()
delta = now - (touch.last || now)
touch.el = $(parentIfText(e.touches[0].target))
touch.el = $(parentIfText(e.type == 'MSPointerDown' ? e.target : e.touches[0].target))
touchTimeout && clearTimeout(touchTimeout)
touch.x1 = e.touches[0].pageX
touch.y1 = e.touches[0].pageY
touch.x1 = (e.type == 'MSPointerDown' ? e.pageX : e.touches[0].pageX)
touch.y1 = (e.type == 'MSPointerDown' ? e.pageY : e.touches[0].pageY)
if (delta > 0 && delta <= 250) touch.isDoubleTap = true
touch.last = now
longTapTimeout = setTimeout(longTap, longTapDelay)
// adds the current touch contact for IE gesture recognition
if (gesture && e.type == 'MSPointerDown') gesture.addPointer(e.pointerId);
})
.bind('touchmove', function(e){
.on('touchmove MSPointerMove', function(e){
if(e.type == 'MSPointerMove' && (e.pointerType != e.MSPOINTER_TYPE_TOUCH || !e.isPrimary)) return;
cancelLongTap()
touch.x2 = e.touches[0].pageX
touch.y2 = e.touches[0].pageY
touch.x2 = (e.type == 'MSPointerMove' ? e.pageX : e.touches[0].pageX)
touch.y2 = (e.type == 'MSPointerMove' ? e.pageY : e.touches[0].pageY)
if (Math.abs(touch.x1 - touch.x2) > 10)
e.preventDefault()
})
.bind('touchend', function(e){
cancelLongTap()
.on('touchend MSPointerUp', function(e){
if(e.type == 'MSPointerUp' && (e.pointerType != e.MSPOINTER_TYPE_TOUCH || !e.isPrimary)) return;
cancelLongTap()

// swipe
if ((touch.x2 && Math.abs(touch.x1 - touch.x2) > 30) ||
Expand Down Expand Up @@ -104,12 +122,12 @@
}, 0)

})
.bind('touchcancel', cancelAll)
.on('touchcancel MSPointerCancel', cancelAll)

$(window).bind('scroll', cancelAll)
$(window).on('scroll', cancelAll)
})

;['swipe', 'swipeLeft', 'swipeRight', 'swipeUp', 'swipeDown', 'doubleTap', 'tap', 'singleTap', 'longTap'].forEach(function(m){
$.fn[m] = function(callback){ return this.bind(m, callback) }
$.fn[m] = function(callback){ return this.on(m, callback) }
})
})(Zepto)

0 comments on commit 299aa61

Please sign in to comment.