Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

L.Browser.touch should be retired #6978

Open
johnd0e opened this issue Jan 23, 2020 · 3 comments
Open

L.Browser.touch should be retired #6978

johnd0e opened this issue Jan 23, 2020 · 3 comments
Labels
api compatibility Cross-browser/device/environment compatibility mobile

Comments

@johnd0e
Copy link
Collaborator

johnd0e commented Jan 23, 2020

// @property touch: Boolean
// `true` for all browsers supporting [touch events](https://developer.mozilla.org/docs/Web/API/Touch_events).
// This does not necessarily mean that the browser is running in a computer with
// a touchscreen, it only means that the browser is capable of understanding
// touch events.
export var touch = !window.L_NO_TOUCH && (pointer || 'ontouchstart' in window ||
(window.DocumentTouch && document instanceof window.DocumentTouch));

At the moment ~95% of browsers support touch events, so this property is not really helpful anymore.
Even more: it is confusing and often mistreated (see #5407, #5266, #3944 and many other).

Currently we have only 9 occurrences in code.

Some are definitely not important

var START = Browser.touch ? 'touchstart mousedown' : 'mousedown';

Leaflet/src/map/Map.js

Lines 1117 to 1118 in d1a1e97

DomUtil.addClass(container, 'leaflet-container' +
(Browser.touch ? ' leaflet-touch' : '') +

Other occurrences should be revised, and most probably we'll find that there will be no harm to consider touch as unconditionally supported.

Control.Layers.js

(this is addressed by #7057)

if (Browser.touch) {
DomEvent.on(link, 'click', DomEvent.stop);
DomEvent.on(link, 'click', this.expand, this);
} else {
DomEvent.on(link, 'focus', this.expand, this);
}

Tooltip.js

(this is addressed by #7535)

if (Browser.touch && !this.options.permanent) {
events.preclick = this._close;
}

if (Browser.touch) {
events.click = this._openTooltip;
}

So I propose to retire L.Browser.touch usage in leaflet codebase.
For compatibility purposes we have to leave L.Browser.touch as true (and describe that in documentation).
More compromise solution is proposed in #7029.

@johnd0e

This comment has been minimized.

@johnd0e
Copy link
Collaborator Author

johnd0e commented Mar 16, 2020

Compare: 'touchevents' test is marked deprecated in modernizr.

More info: Modernizr/Modernizr#2432

@johnd0e
Copy link
Collaborator Author

johnd0e commented Apr 1, 2020

Currently in most places of code touch property check is used to prevent attaching excessive listeners if touch is unsupported.
May be that makes sense for legacy devices (though I doubt that it has any impact on performance with modern ones).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api compatibility Cross-browser/device/environment compatibility mobile
Projects
None yet
Development

No branches or pull requests

1 participant