Merge pull request #1227 from jerel/patch/android-webview
A bug in Android WebView triggers two clicks at once.
This commit is contained in:
commit
72ad6912e6
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user