Created
December 13, 2013 18:21
-
-
Save cagerton/7948779 to your computer and use it in GitHub Desktop.
Generate click events on touchstart; kill the mouse events that the browser cooks 200+ms afterwards.
This file contains 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
(function touchJack(){ | |
var lastTouch = 0; | |
document.addEventListener("touchstart", function(e){ | |
lastTouch = Date.now(); | |
var touch = e.touches[0], | |
synth_event = document.createEvent("MouseEvents"); | |
synth_event.fab=true; | |
synth_event.initMouseEvent("click", true, true, window, | |
0, touch.screenX, touch.screenY, touch.clientX, touch.clientY, | |
false, false, false, false, 0, null); | |
e.target.dispatchEvent(synth_event); | |
}); | |
["click", "mouseout", "mouseover"].forEach(function(event_type){ | |
document.addEventListener(event_type, function(e){ | |
if(!e.fab && Date.now() < lastTouch + 500){ | |
e.stopPropagation(); | |
e.stopImmediatePropagation(); | |
e.preventDefault(); | |
return false; | |
} | |
}, true); // capture phase. | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment