Created
May 31, 2019 12:28
-
-
Save fredj/72c63d5b2452505e6b8bafc8ff33a83b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commit 1f495ed69eb49d6bed3f9bee0d24ad087ad688b9 | |
Author: Frédéric Junod <frederic.junod@camptocamp.com> | |
Date: Fri May 31 13:29:35 2019 +0200 | |
Remove TOUCH, POINTER and MSPOINTER from ol/has | |
diff --git a/changelog/upgrade-notes.md b/changelog/upgrade-notes.md | |
index 3825d1df6..19c397bb7 100644 | |
--- a/changelog/upgrade-notes.md | |
+++ b/changelog/upgrade-notes.md | |
@@ -4,9 +4,19 @@ | |
#### Backwards incompatible changes | |
+#### Removal of `TOUCH` constant from `ol/has` | |
+ | |
+If you were previously using this constant, you can check if `'ontouchstart'` is defined in `window` instead. | |
+ | |
+```js | |
+if ('ontouchstart' in window) { | |
+ // ... | |
+} | |
+``` | |
+ | |
#### Removal of `GEOLOCATION` constant from `ol/has` | |
-If you were previously using this constant, you can check if `'geolocation'` is define in `navigator` instead. | |
+If you were previously using this constant, you can check if `'geolocation'` is defined in `navigator` instead. | |
```js | |
if ('geolocation' in navigator) { | |
diff --git a/src/ol/PluggableMap.js b/src/ol/PluggableMap.js | |
index d4c57c4d4..e6035259c 100644 | |
--- a/src/ol/PluggableMap.js | |
+++ b/src/ol/PluggableMap.js | |
@@ -22,7 +22,7 @@ import {listen, unlistenByKey, unlisten} from './events.js'; | |
import EventType from './events/EventType.js'; | |
import {createEmpty, clone, createOrUpdateEmpty, equals, getForViewAndSize, isEmpty} from './extent.js'; | |
import {TRUE} from './functions.js'; | |
-import {DEVICE_PIXEL_RATIO, TOUCH} from './has.js'; | |
+import {DEVICE_PIXEL_RATIO} from './has.js'; | |
import LayerGroup from './layer/Group.js'; | |
import {hasArea} from './size.js'; | |
import {DROP} from './structs/PriorityQueue.js'; | |
@@ -230,7 +230,7 @@ class PluggableMap extends BaseObject { | |
* @type {!HTMLElement} | |
*/ | |
this.viewport_ = document.createElement('div'); | |
- this.viewport_.className = 'ol-viewport' + (TOUCH ? ' ol-touch' : ''); | |
+ this.viewport_.className = 'ol-viewport' + ('ontouchstart' in window ? ' ol-touch' : ''); | |
this.viewport_.style.position = 'relative'; | |
this.viewport_.style.overflow = 'hidden'; | |
this.viewport_.style.width = '100%'; | |
diff --git a/src/ol/has.js b/src/ol/has.js | |
index 93b1e9343..c59288907 100644 | |
--- a/src/ol/has.js | |
+++ b/src/ol/has.js | |
@@ -39,30 +39,4 @@ export const MAC = ua.indexOf('macintosh') !== -1; | |
*/ | |
export const DEVICE_PIXEL_RATIO = window.devicePixelRatio || 1; | |
- | |
-/** | |
- * True if browser supports touch events. | |
- * @const | |
- * @type {boolean} | |
- * @api | |
- */ | |
-export const TOUCH = 'ontouchstart' in window; | |
- | |
- | |
-/** | |
- * True if browser supports pointer events. | |
- * @const | |
- * @type {boolean} | |
- */ | |
-export const POINTER = 'PointerEvent' in window; | |
- | |
- | |
-/** | |
- * True if browser supports ms pointer events (IE 10). | |
- * @const | |
- * @type {boolean} | |
- */ | |
-export const MSPOINTER = !!(navigator.msPointerEnabled); | |
- | |
- | |
export {HAS as WEBGL} from './webgl.js'; | |
diff --git a/src/ol/pointer/PointerEventHandler.js b/src/ol/pointer/PointerEventHandler.js | |
index 2501efa12..7f983ef9d 100644 | |
--- a/src/ol/pointer/PointerEventHandler.js | |
+++ b/src/ol/pointer/PointerEventHandler.js | |
@@ -34,7 +34,6 @@ | |
import {listen, unlisten} from '../events.js'; | |
import EventTarget from '../events/Target.js'; | |
-import {POINTER, MSPOINTER, TOUCH} from '../has.js'; | |
import PointerEventType from './EventType.js'; | |
import MouseSource, {prepareEvent as prepareMouseEvent} from './MouseSource.js'; | |
import MsSource from './MsSource.js'; | |
@@ -124,15 +123,15 @@ class PointerEventHandler extends EventTarget { | |
* that generate pointer events. | |
*/ | |
registerSources() { | |
- if (POINTER) { | |
+ if ('PointerEvent' in window) { | |
this.registerSource('native', new NativeSource(this)); | |
- } else if (MSPOINTER) { | |
+ } else if (window.navigator.msPointerEnabled) { | |
this.registerSource('ms', new MsSource(this)); | |
} else { | |
const mouseSource = new MouseSource(this); | |
this.registerSource('mouse', mouseSource); | |
- if (TOUCH) { | |
+ if ('ontouchstart' in window) { | |
this.registerSource('touch', new TouchSource(this, mouseSource)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment