move checks for pointer support into browserfeature module
This commit is contained in:
@@ -159,7 +159,30 @@ ol.BrowserFeature.HAS_GEOLOCATION = 'geolocation' in goog.global.navigator;
|
|||||||
*/
|
*/
|
||||||
ol.BrowserFeature.HAS_TOUCH = ol.ASSUME_TOUCH ||
|
ol.BrowserFeature.HAS_TOUCH = ol.ASSUME_TOUCH ||
|
||||||
(goog.global.document &&
|
(goog.global.document &&
|
||||||
'ontouchstart' in goog.global.document.documentElement) ||
|
'ontouchstart' in goog.global.document.documentElement);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* True if browser supports pointer events.
|
||||||
|
*
|
||||||
|
* `navigation.pointerEnabled` is actually not part of the
|
||||||
|
* spec: https://www.w3.org/Bugs/Public/show_bug.cgi?id=22890#c3
|
||||||
|
*
|
||||||
|
* @const
|
||||||
|
* @type {boolean}
|
||||||
|
* @todo stability experimental
|
||||||
|
*/
|
||||||
|
ol.BrowserFeature.HAS_POINTER =
|
||||||
|
!!(goog.global.navigator['pointerEnabled']);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* True if browser supports ms pointer events (IE 10).
|
||||||
|
* @const
|
||||||
|
* @type {boolean}
|
||||||
|
* @todo stability experimental
|
||||||
|
*/
|
||||||
|
ol.BrowserFeature.HAS_MSPOINTER =
|
||||||
!!(goog.global.navigator.msPointerEnabled);
|
!!(goog.global.navigator.msPointerEnabled);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ goog.require('goog.events.Event');
|
|||||||
goog.require('goog.events.EventTarget');
|
goog.require('goog.events.EventTarget');
|
||||||
goog.require('goog.structs.Map');
|
goog.require('goog.structs.Map');
|
||||||
|
|
||||||
|
goog.require('ol.BrowserFeature');
|
||||||
goog.require('ol.pointer.MouseSource');
|
goog.require('ol.pointer.MouseSource');
|
||||||
goog.require('ol.pointer.MsSource');
|
goog.require('ol.pointer.MsSource');
|
||||||
goog.require('ol.pointer.NativeSource');
|
goog.require('ol.pointer.NativeSource');
|
||||||
@@ -89,15 +90,15 @@ goog.inherits(ol.pointer.PointerEventHandler, goog.events.EventTarget);
|
|||||||
* that generate pointer events.
|
* that generate pointer events.
|
||||||
*/
|
*/
|
||||||
ol.pointer.PointerEventHandler.prototype.registerSources = function() {
|
ol.pointer.PointerEventHandler.prototype.registerSources = function() {
|
||||||
if (this.isPointerEnabled_()) {
|
if (ol.BrowserFeature.HAS_POINTER) {
|
||||||
this.registerSource('native', new ol.pointer.NativeSource(this));
|
this.registerSource('native', new ol.pointer.NativeSource(this));
|
||||||
} else if (this.isMsPointerEnabled_()) {
|
} else if (ol.BrowserFeature.HAS_MSPOINTER) {
|
||||||
this.registerSource('ms', new ol.pointer.MsSource(this));
|
this.registerSource('ms', new ol.pointer.MsSource(this));
|
||||||
} else {
|
} else {
|
||||||
var mouseSource = new ol.pointer.MouseSource(this);
|
var mouseSource = new ol.pointer.MouseSource(this);
|
||||||
this.registerSource('mouse', mouseSource);
|
this.registerSource('mouse', mouseSource);
|
||||||
|
|
||||||
if (this.isTouchDefined_()) {
|
if (ol.BrowserFeature.HAS_TOUCH) {
|
||||||
this.registerSource('touch',
|
this.registerSource('touch',
|
||||||
new ol.pointer.TouchSource(this, mouseSource));
|
new ol.pointer.TouchSource(this, mouseSource));
|
||||||
}
|
}
|
||||||
@@ -108,39 +109,6 @@ ol.pointer.PointerEventHandler.prototype.registerSources = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @private
|
|
||||||
* @return {boolean} Returns true if the browser supports
|
|
||||||
* native pointer events.
|
|
||||||
*/
|
|
||||||
ol.pointer.PointerEventHandler.prototype.isPointerEnabled_ = function() {
|
|
||||||
/* TODO navigation.pointerEnabled is actually not part of the
|
|
||||||
* spec: https://www.w3.org/Bugs/Public/show_bug.cgi?id=22890#c3
|
|
||||||
*/
|
|
||||||
return window.navigator['pointerEnabled'] !== undefined;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @private
|
|
||||||
* @return {boolean} Returns true if the browser supports
|
|
||||||
* ms pointer events (IE10).
|
|
||||||
*/
|
|
||||||
ol.pointer.PointerEventHandler.prototype.isMsPointerEnabled_ = function() {
|
|
||||||
return window.navigator['msPointerEnabled'] !== undefined;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @private
|
|
||||||
* @return {boolean} Returns true if the browser supports
|
|
||||||
* touch events.
|
|
||||||
*/
|
|
||||||
ol.pointer.PointerEventHandler.prototype.isTouchDefined_ = function() {
|
|
||||||
return window['ontouchstart'] !== undefined;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a new event source that will generate pointer events.
|
* Add a new event source that will generate pointer events.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user