fix Android firing click twice on buttons, close #1785, related #1694

This commit is contained in:
Vladimir Agafonkin 2013-06-25 09:45:35 -04:00
parent 3076210fd1
commit 89d0730254
2 changed files with 3 additions and 13 deletions

View File

@ -195,19 +195,8 @@ L.DomEvent = {
// this solves a bug in Android WebView where a single touch triggers two click events. // this solves a bug in Android WebView where a single touch triggers two click events.
_filterClick: function (e, handler) { _filterClick: function (e, handler) {
var timeStamp = (e.timeStamp || e.originalEvent.timeStamp); // check if click is simulated on the element, and if it is, reject any non-simulated events
var elapsed = L.DomEvent._lastClick && (timeStamp - L.DomEvent._lastClick); if (e.target._simulatedClick && !e._simulated) { return; }
// are they closer together than 400ms yet more than 100ms?
// Android typically triggers them ~300ms apart while multiple listeners
// on the same event should be triggered far faster.
if (elapsed && elapsed > 100 && elapsed < 400) {
L.DomEvent.stop(e);
return;
}
L.DomEvent._lastClick = timeStamp;
return handler(e); return handler(e);
} }
}; };

View File

@ -90,6 +90,7 @@ L.Map.Tap = L.Handler.extend({
var simulatedEvent = document.createEvent('MouseEvents'); var simulatedEvent = document.createEvent('MouseEvents');
simulatedEvent._simulated = true; simulatedEvent._simulated = true;
e.target._simulatedClick = true;
simulatedEvent.initMouseEvent( simulatedEvent.initMouseEvent(
type, true, true, window, 1, type, true, true, window, 1,