From 2df61998ab44ca0645cf7e19fa51e77dd83ccb18 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Tue, 29 Dec 2015 12:43:46 -0800 Subject: [PATCH] [Mobile] Detect touch support --- platform/commonUI/mobile/src/AgentService.js | 9 +++++++++ platform/commonUI/mobile/src/DeviceClassifier.js | 1 + platform/commonUI/mobile/src/DeviceMatchers.js | 3 +++ platform/commonUI/mobile/src/MCTDevice.js | 1 + 4 files changed, 14 insertions(+) diff --git a/platform/commonUI/mobile/src/AgentService.js b/platform/commonUI/mobile/src/AgentService.js index 109520d8bd..3251950ff4 100644 --- a/platform/commonUI/mobile/src/AgentService.js +++ b/platform/commonUI/mobile/src/AgentService.js @@ -46,6 +46,7 @@ define( this.userAgent = userAgent; this.mobileName = matches[0]; this.$window = $window; + this.touchEnabled = ($window.ontouchstart !== undefined); } /** @@ -92,6 +93,14 @@ define( return !this.isPortrait(); }; + /** + * Check if the user's device supports a touch interface. + * @returns {boolean} true if touch is supported + */ + AgentService.prototype.isTouch = function () { + return this.touchEnabled; + }; + /** * Check if the user agent matches a certain named device, * as indicated by checking for a case-insensitive substring diff --git a/platform/commonUI/mobile/src/DeviceClassifier.js b/platform/commonUI/mobile/src/DeviceClassifier.js index 881a3be191..ac275fa4d0 100644 --- a/platform/commonUI/mobile/src/DeviceClassifier.js +++ b/platform/commonUI/mobile/src/DeviceClassifier.js @@ -37,6 +37,7 @@ define( * * `desktop`: Non-mobile devices. * * `portrait`: Devices in a portrait-style orientation. * * `landscape`: Devices in a landscape-style orientation. + * * `touch`: Device supports touch events. * * @param {platform/commonUI/mobile.AgentService} agentService * the service used to examine the user agent diff --git a/platform/commonUI/mobile/src/DeviceMatchers.js b/platform/commonUI/mobile/src/DeviceMatchers.js index 363662a73e..9292625a79 100644 --- a/platform/commonUI/mobile/src/DeviceMatchers.js +++ b/platform/commonUI/mobile/src/DeviceMatchers.js @@ -52,6 +52,9 @@ define(function () { }, landscape: function (agentService) { return agentService.isLandscape(); + }, + touch: function (agentService) { + return agentService.isTouch(); } }; }); \ No newline at end of file diff --git a/platform/commonUI/mobile/src/MCTDevice.js b/platform/commonUI/mobile/src/MCTDevice.js index bcecee3f28..704f665a22 100644 --- a/platform/commonUI/mobile/src/MCTDevice.js +++ b/platform/commonUI/mobile/src/MCTDevice.js @@ -47,6 +47,7 @@ define( * * `desktop`: Non-mobile devices. * * `portrait`: Devices in a portrait-style orientation. * * `landscape`: Devices in a landscape-style orientation. + * * `touch`: Device supports touch events. * * @param {AgentService} agentService used to detect device type * based on information about the user agent