diff --git a/src/dom/DomEvent.js b/src/dom/DomEvent.js index 6246a7be..3ab42867 100644 --- a/src/dom/DomEvent.js +++ b/src/dom/DomEvent.js @@ -41,6 +41,13 @@ L.DomEvent = { obj.addEventListener(newType, handler, false); + } else if (type === 'click' && L.Browser.android) { + originalHandler = handler; + handler = function(e) { + return L.DomEvent._filterClick(e, originalHandler); + }; + + obj.addEventListener(type, handler, false); } else { obj.addEventListener(type, handler, false); } @@ -179,6 +186,23 @@ L.DomEvent = { } } return e; + }, + /*jshint noarg:false */ + + // this solves a bug in Android WebView where + // a single touch triggers two click events. + _filterClick: function(e, handler) { + var elapsed = (typeof(L.DomEvent._lastClick) === 'undefined') ? null : (e.timeStamp - L.DomEvent._lastClick); + // 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 > 100 && elapsed < 400) { + L.DomEvent.stop(e); + return; + } + L.DomEvent._lastClick = e.timeStamp; + + return handler(e); } };