Skip to content

Instantly share code, notes, and snippets.

@cpojer
Created September 11, 2010 19:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cpojer/575481 to your computer and use it in GitHub Desktop.
Save cpojer/575481 to your computer and use it in GitHub Desktop.
(function(){
if (!Browser.Features.Touch) return;
var start, end, moved;
var events = {
touchstart: function(event){
moved = false;
end = null;
start = event.touches[0].pageY;
},
touchmove: function(event){
end = event.touches[0].pageY;
// Allows a small delta
if (end && Math.abs(start - end) > 3) moved = true;
},
touchcancel: function(){
moved = true;
}
};
var handleEvent = function(event){
var method = events[event.type];
if (method) method(event);
};
document.addEventListener('touchstart', handleEvent, true);
document.addEventListener('touchmove', handleEvent, true);
document.addEventListener('touchcancel', handleEvent, true);
Element.defineCustomEvent('click', {
base: 'click',
condition: function(){
return !moved;
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment