browser.js (1387B)
1 /** 2 * @license Apache-2.0 3 * 4 * Copyright (c) 2021 The Stdlib Authors. 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 'use strict'; 20 21 // MODULES // 22 23 var IS_BROWSER = require( './../../is-browser' ); 24 var getGlobal = require( '@stdlib/utils/global' ); 25 26 27 // VARIABLES // 28 29 var Global = getGlobal(); 30 31 32 // MAIN // 33 34 /** 35 * Returns a boolean indicating if an environment is a touch device. 36 * 37 * @private 38 * @returns {boolean} boolean indicating if an environment is a touch-enabled environment 39 */ 40 function isTouchDevice() { 41 if ( !IS_BROWSER ) { 42 return false; 43 } 44 return !!( 45 'ontouchstart' in Global || 46 ( 47 Global.DocumentTouch && 48 Global.document && 49 Global.document instanceof Global.DocumentTouch 50 ) || 51 ( 52 Global.navigator && 53 ( 54 Global.navigator.maxTouchPoints > 0 || 55 Global.navigator.msMaxTouchPoints > 0 56 ) 57 ) 58 ); 59 } 60 61 62 // EXPORTS // 63 64 module.exports = isTouchDevice;