Created
October 11, 2012 19:00
-
-
Save djwglpuppy/3874736 to your computer and use it in GitHub Desktop.
touchend event
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
isMobile = function() { | |
return /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent); | |
}; | |
jQuery.fn.touchend = function(cb) { | |
return _.each(this, function(item) { | |
var isvalidend, newcb, touchevent, validend; | |
if (isMobile()) { | |
isvalidend = true; | |
validend = null; | |
newcb = _.clone(cb); | |
newcb = _.bind(cb, item); | |
touchevent = function(e) { | |
if (!isvalidend) { | |
return false; | |
} | |
return newcb(e); | |
}; | |
item.ontouchmove = function() { | |
isvalidend = false; | |
return _.delay((function() { | |
return isvalidend = true; | |
}), 100); | |
}; | |
return item.ontouchend = touchevent; | |
} else { | |
return item.onclick = cb; | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Make sure to run Jquery and underscore.js