Skip to content

Commit

Permalink
bring back the horrible timeout hack for Android, close Leaflet#1785
Browse files Browse the repository at this point in the history
  • Loading branch information
mourner committed Jun 25, 2013
1 parent 7c6c701 commit c56e376
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/dom/DomEvent.js
Expand Up @@ -199,10 +199,22 @@ L.DomEvent = {
return e;
},

// this solves a bug in Android WebView where a single touch triggers two click events.
// this is a horrible workaround for a bug in Android where a single touch triggers two click events
_filterClick: function (e, handler) {
// check if click is simulated on the element, and if it is, reject any non-simulated events
if (e.target._simulatedClick && !e._simulated) { return; }
var timeStamp = (e.timeStamp || e.originalEvent.timeStamp),
elapsed = L.DomEvent._lastClick && (timeStamp - L.DomEvent._lastClick);

// are they closer together than 1000ms yet more than 100ms?
// Android typically triggers them ~300ms apart while multiple listeners
// on the same event should be triggered far faster;
// or check if click is simulated on the element, and if it is, reject any non-simulated events

if ((elapsed && elapsed > 100 && elapsed < 1000) || (e.target._simulatedClick && !e._simulated)) {
L.DomEvent.stop(e);
return;
}
L.DomEvent._lastClick = timeStamp;

return handler(e);
}
};
Expand Down

0 comments on commit c56e376

Please sign in to comment.