Created
May 9, 2012 10:27
-
-
Save danielmahal/2643602 to your computer and use it in GitHub Desktop.
Tap/Click override
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if(Modernizr.touch) { | |
$.event.special.click = { | |
tapThreshold: 750, | |
setup: function() { | |
$(this).on('touchstart', $.event.special.click.touchstart); | |
}, | |
teardown: function() { | |
$(this).off('touchstart', $.event.special.click.touchstart); | |
}, | |
touchstart: function(e) { | |
if ((e.which && e.which !== 1) || !e.originalEvent.touches.length) return false; | |
var $el = $(this); | |
var moved = false; | |
var startX = e.originalEvent.touches[0].clientX; | |
var startY = e.originalEvent.touches[0].clientY; | |
var touchmove = function() { | |
var x = e.originalEvent.touches[0].clientX; | |
var y = e.originalEvent.touches[0].clientY; | |
if (Math.abs(x - startX) > 10 || Math.abs(y - startY) > 10) { | |
moved = true; | |
} | |
}; | |
var touchend = function(e) { | |
if(!moved) { | |
e.type = "click"; | |
$.event.handle.apply(this, arguments); | |
} | |
$el.off('touchmove', touchmove); | |
$el.off('touchend', touchend); | |
}; | |
$el.on('touchmove', touchmove); | |
$el.on('touchend', touchend); | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not currently working. Just saying…