Skip to content

Instantly share code, notes, and snippets.

@incompl
Created September 25, 2013 21:56
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 incompl/6706640 to your computer and use it in GitHub Desktop.
Save incompl/6706640 to your computer and use it in GitHub Desktop.
jquery custom event to normalize mousedown and touchstart
/* global $ */
// Custom jQuery event that normalizes mousedown and touchstart
// based on http://stackoverflow.com/questions/8503453/click-event-called-twice-on-touchend-in-ipad
$.event.special.poke = {
setup: function() {
var isTouchSupported = "ontouchstart" in document;
var poke = isTouchSupported ? "touchstart" : "mousedown";
$(this).bind(poke + ".poke-event", function(event) {
event.type = "poke";
($.event.dispatch||$.event.handle).call(this, event);
});
},
teardown: function() {
$(this).unbind(".poke-event");
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment