Skip to content

Instantly share code, notes, and snippets.

@djwglpuppy
Created October 11, 2012 19:00
Show Gist options
  • Save djwglpuppy/3874736 to your computer and use it in GitHub Desktop.
Save djwglpuppy/3874736 to your computer and use it in GitHub Desktop.
touchend event
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;
}
});
};
@djwglpuppy
Copy link
Author

Make sure to run Jquery and underscore.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment