]> git.proxmox.com Git - mirror_novnc.git/blob - core/util/browser.js
Add eslint and fix reported issues
[mirror_novnc.git] / core / util / browser.js
1 /*
2 * noVNC: HTML5 VNC client
3 * Copyright (C) 2012 Joel Martin
4 * Licensed under MPL 2.0 (see LICENSE.txt)
5 *
6 * See README.md for usage and integration instructions.
7 */
8
9 import * as Log from './logging.js';
10
11 // Touch detection
12 export var isTouchDevice = ('ontouchstart' in document.documentElement) ||
13 // requried for Chrome debugger
14 (document.ontouchstart !== undefined) ||
15 // required for MS Surface
16 (navigator.maxTouchPoints > 0) ||
17 (navigator.msMaxTouchPoints > 0);
18 window.addEventListener('touchstart', function onFirstTouch() {
19 isTouchDevice = true;
20 window.removeEventListener('touchstart', onFirstTouch, false);
21 }, false);
22
23 var _cursor_uris_supported = null;
24
25 export function supportsCursorURIs () {
26 if (_cursor_uris_supported === null) {
27 try {
28 var target = document.createElement('canvas');
29 target.style.cursor = 'url("data:image/x-icon;base64,AAACAAEACAgAAAIAAgA4AQAAFgAAACgAAAAIAAAAEAAAAAEAIAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAD/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////AAAAAAAAAAAAAAAAAAAAAA==") 2 2, default';
30
31 if (target.style.cursor) {
32 Log.Info("Data URI scheme cursor supported");
33 _cursor_uris_supported = true;
34 } else {
35 Log.Warn("Data URI scheme cursor not supported");
36 _cursor_uris_supported = false;
37 }
38 } catch (exc) {
39 Log.Error("Data URI scheme cursor test exception: " + exc);
40 _cursor_uris_supported = false;
41 }
42 }
43
44 return _cursor_uris_supported;
45 }
46
47 export function isMac() {
48 return navigator && !!(/mac/i).exec(navigator.platform);
49 }
50
51 export function isIE() {
52 return navigator && !!(/trident/i).exec(navigator.userAgent);
53 }
54
55 export function isEdge() {
56 return navigator && !!(/edge/i).exec(navigator.userAgent);
57 }
58
59 export function isFirefox() {
60 return navigator && !!(/firefox/i).exec(navigator.userAgent);
61 }
62
63 export function isWindows() {
64 return navigator && !!(/win/i).exec(navigator.platform);
65 }
66
67 export function isIOS() {
68 return navigator &&
69 (!!(/ipad/i).exec(navigator.platform) ||
70 !!(/iphone/i).exec(navigator.platform) ||
71 !!(/ipod/i).exec(navigator.platform));
72 }
73