diff --git a/src/dom/DomUtil.js b/src/dom/DomUtil.js index 489e9bee..67de1558 100644 --- a/src/dom/DomUtil.js +++ b/src/dom/DomUtil.js @@ -219,4 +219,19 @@ L.DomUtil = { L.DomUtil.enableImageDrag = function () { L.DomEvent.off(window, 'dragstart', L.DomEvent.preventDefault); }; + + L.DomUtil.preventOutline = function (element) { + L.DomUtil.restoreOutline(); + this._outlineElement = element; + this._outlineStyle = element.style.outline; + element.style.outline = 'none'; + L.DomEvent.on(window, 'keydown', L.DomUtil.restoreOutline, this); + }; + L.DomUtil.restoreOutline = function () { + if (!this._outlineElement) { return; } + this._outlineElement.style.outline = this._outlineStyle; + delete this._outlineElement; + delete this._outlineStyle; + L.DomEvent.off(window, 'keydown', L.DomUtil.restoreOutline, this); + }; })(); diff --git a/src/dom/Draggable.js b/src/dom/Draggable.js index 7e6748f0..428a2b58 100644 --- a/src/dom/Draggable.js +++ b/src/dom/Draggable.js @@ -51,7 +51,7 @@ L.Draggable = L.Evented.extend({ L.DomEvent.stopPropagation(e); if (this._preventOutline) { - L.DomEvent.preventDefault(e); + L.DomUtil.preventOutline(this._element); } if (L.DomUtil.hasClass(this._element, 'leaflet-zoom-anim')) { return; } diff --git a/src/map/Map.js b/src/map/Map.js index c78d71a2..b07b50c1 100644 --- a/src/map/Map.js +++ b/src/map/Map.js @@ -581,8 +581,8 @@ L.Map = L.Evented.extend({ !L.DomEvent._checkMouse(this._container, e)) { return; } // prevents outline when clicking on keyboard-focusable element - if (target && type === 'mousedown') { - L.DomEvent.preventDefault(e); + if (type === 'mousedown') { + L.DomUtil.preventOutline(e.target || e.srcElement); } this._fireDOMEvent(target || this, e, type);