CSS-based outline prevention

This commit is contained in:
John Firebaugh 2014-11-18 14:21:28 -08:00 committed by Vladimir Agafonkin
parent 63753d8564
commit a865d2b649
3 changed files with 18 additions and 3 deletions

View File

@ -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);
};
})();

View File

@ -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; }

View File

@ -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);