From ac78c7e1448bfb26f133198659e3b46d96145ea1 Mon Sep 17 00:00:00 2001 From: Samat K Jain Date: Fri, 14 Oct 2011 17:11:00 -0600 Subject: [PATCH 1/2] Better touch feature detection Rewrite L.Browser.Touch to support feature detection in more browsers (Firefox in particular). Based on Juriy Zaytsev code: https://github.com/kangax/iseventsupported --- src/core/Browser.js | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/core/Browser.js b/src/core/Browser.js index f0ae4b57..36906fb9 100644 --- a/src/core/Browser.js +++ b/src/core/Browser.js @@ -22,6 +22,31 @@ mobileOpera: mobile && opera, mobile: mobile, - touch: ('ontouchstart' in document.documentElement) + touch: (function() { + var touchSupported = false;; + + // WebKit, etc + if ('ontouchstart' in document.documentElement) { + return true; + } + + // Firefox/Gecko + var e = document.createElement('div'); + + // If no support for basic event stuff, unlikely to have touch support + if (!e.setAttribute || !e.removeAttribute) { + return false; + } + + e.setAttribute('ontouchstart', 'return;'); + if (typeof e['ontouchstart'] == 'function') { + touchSupported = true; + } + + e.removeAttribute('ontouchstart'); + e = null; + + return touchSupported; + })() }; -})(); \ No newline at end of file +})(); From c59e8b3239781de20a1d480b49750dea6cf8b3f1 Mon Sep 17 00:00:00 2001 From: Samat K Jain Date: Fri, 14 Oct 2011 17:16:13 -0600 Subject: [PATCH 2/2] Ignore shift key for touch-enabled browsers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Firefox Mobile (née Fennec) has a bug that sets Event.shiftKey to true even though the shift key is not depressed: https://bugzilla.mozilla.org/show_bug.cgi?id=694268 As a workaround, ignore whether the shift key is depressed for touch-enabled browsers. This breaks Leaflet’s drag-zoom, but besides being awkward I’m unsure it consistently worked on other touch-enabled browsers (did not work for me on Android 2.3 devices w/ Bluetooth keyboard). --- src/dom/Draggable.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dom/Draggable.js b/src/dom/Draggable.js index 9b1bc9a2..8d0f42d9 100644 --- a/src/dom/Draggable.js +++ b/src/dom/Draggable.js @@ -30,7 +30,7 @@ L.Draggable = L.Class.extend({ }, _onDown: function(e) { - if (e.shiftKey || ((e.which != 1) && (e.button != 1) && !e.touches)) { return; } + if ((!L.Browser.touch && e.shiftKey) || ((e.which != 1) && (e.button != 1) && !e.touches)) { return; } if (e.touches && e.touches.length > 1) { return; }