Skip to content

Commit

Permalink
Updated touch.js to support IE10 touch
Browse files Browse the repository at this point in the history
Updated the Touch module to support IE touch.
Areas which use swipes should have the following CSS applied in order to function properly in IE.
-ms-touch-action: none;
  • Loading branch information
charsleysa committed May 9, 2013
1 parent 342d490 commit 38b5869
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions src/touch.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,31 @@

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

$(document.body)
.bind('touchstart', function(e){
.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)
})
.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 +107,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 38b5869

Please sign in to comment.