tap fires twice with live("tap")
On mobile safari with live("tap"), tap event fires twice.
And this causes kinds of bugs such as opening dialog twice, sending ajax request twice, etc...
The most notable one is, when you tap a text field, safari sometimes focuses nowhere.
The following is a minimum code that reproduces it.
- <!DOCTYPE html>
<html>
<head>
<title>tap twice</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.5.min.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.css" />
<script src="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.js"></script>
</head>
<body>
<form><br />
<input name="a" type="text" /><br />
</form>
</body>
<script type="text/javascript">
$(function(){$("#no_such_element").live("tap", function(e){});});
</script>
</html>
After loading this page, tap just above/below the text field (not inside it). Normally this focuses on the textfield
because safari mobile has some margin around textfield for usability.
But in this case after keyboard slides up, focus is not on the text field and tapping keyboard prints no text on it,
even Done button doesn't work.
At this point, focus is actually on BODY tag. You can see it by alert(document.activeElement).
My guess is that this is caused by the doubly fired tap events.
On the first tap event, focus is on the textfield and safari start preparing keyboard slides up.
But on the second tap event, focus is moved to body tag (i don't know why but should be related to the margin around textfield) and when the keyboard is ready it works oddly.
The reason why tap fires twice is,
in the definition of $.event.special.tap, event handler is bound to both mouseXXX and touchYYY like
.one( "mouseup touchend", function( event )
and each handler fires tap event.
I think this should be the following.
.one( touchStopEvent, function( event )
Is there any reason why it isn't?
Thanks.