Skip to content

Commit

Permalink
Fixes #1041, Android WebView triggers two clicks at once. This calls
Browse files Browse the repository at this point in the history
L.DomEvent.stop(event) on the second if two clicks are triggered within 400ms
of each other. Double click is unaffected however.

There are other workarounds that focus on _fireMouseEvent(), however I had to
resolve it at the click event level as my map, markers, controls, were all
affected.
  • Loading branch information
jerel committed Dec 21, 2012
1 parent 2a0eec9 commit cf94612
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/dom/DomEvent.js
Expand Up @@ -41,6 +41,13 @@ L.DomEvent = {

obj.addEventListener(newType, handler, false);

} else if (type === 'click') {
originalHandler = handler;
handler = function(e) {
return L.DomEvent._filterClick(e, originalHandler);
};

obj.addEventListener(type, handler, false);
} else {
obj.addEventListener(type, handler, false);
}
Expand Down Expand Up @@ -179,6 +186,21 @@ 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) {
// are they closer together than 400ms?
// Android typically triggers them ~300ms apart
if ((e.timeStamp - L.DomEvent._lastClick) < 400) {
L.DomEvent.stop(e);
return;
}
L.DomEvent._lastClick = e.timeStamp;

return handler(e);
}
};

Expand Down

0 comments on commit cf94612

Please sign in to comment.