Created
September 25, 2013 21:56
-
-
Save incompl/6706640 to your computer and use it in GitHub Desktop.
jquery custom event to normalize mousedown and touchstart
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
/* 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