Skip to content

Instantly share code, notes, and snippets.

@sstephenson
Created June 22, 2010 17:45
Show Gist options
  • Select an option

  • Save sstephenson/448808 to your computer and use it in GitHub Desktop.

Select an option

Save sstephenson/448808 to your computer and use it in GitHub Desktop.
// Mobile Safari doesn't fire touchstart or touchend events for
// input[type=text], input[type=password], input[type=search],
// and textarea elements.
(function() {
if (!("createTouch" in document)) return;
var selector = "input[type=text], input[type=password], input[type=search], textarea";
function fire(element, type, identifier) {
var touch = document.createTouch(window, element, identifier, 0, 0, 0, 0);
var touches = document.createTouchList(touch);
var targetTouches = document.createTouchList(touch);
var changedTouches = document.createTouchList(touch);
var event = document.createEvent("TouchEvent");
event.initTouchEvent(type, true, true, window, null, 0, 0, 0, 0, false, false, false, false,
touches, targetTouches, changedTouches, 1, 0);
element.dispatchEvent(event);
}
document.on("mouseup", selector, function(event, element) {
var identifier = new Date().getTime();
fire.defer(element, "touchstart", identifier);
fire.defer(element, "touchend", identifier);
});
})();
@KrofDrakula

Copy link
Copy Markdown

Yeah, it's missing exactly what I need to complete my proof of concept. Thanks for replying though. Got any more tips on where to look for more info?

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