]> git.proxmox.com Git - mirror_novnc.git/blob - core/util/browser.js
Move UI.isSafari into core/util/browser.js
[mirror_novnc.git] / core / util / browser.js
1 /*
2 * noVNC: HTML5 VNC client
3 * Copyright (C) 2018 The noVNC Authors
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 let 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
24 // The goal is to find a certain physical width, the devicePixelRatio
25 // brings us a bit closer but is not optimal.
26 export let dragThreshold = 10 * (window.devicePixelRatio || 1);
27
28 let _cursor_uris_supported = null;
29
30 export function supportsCursorURIs() {
31 if (_cursor_uris_supported === null) {
32 try {
33 const target = document.createElement('canvas');
34 target.style.cursor = 'url("data:image/x-icon;base64,AAACAAEACAgAAAIAAgA4AQAAFgAAACgAAAAIAAAAEAAAAAEAIAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAD/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////AAAAAAAAAAAAAAAAAAAAAA==") 2 2, default';
35
36 if (target.style.cursor) {
37 Log.Info("Data URI scheme cursor supported");
38 _cursor_uris_supported = true;
39 } else {
40 Log.Warn("Data URI scheme cursor not supported");
41 _cursor_uris_supported = false;
42 }
43 } catch (exc) {
44 Log.Error("Data URI scheme cursor test exception: " + exc);
45 _cursor_uris_supported = false;
46 }
47 }
48
49 return _cursor_uris_supported;
50 }
51
52 export function isMac() {
53 return navigator && !!(/mac/i).exec(navigator.platform);
54 }
55
56 export function isWindows() {
57 return navigator && !!(/win/i).exec(navigator.platform);
58 }
59
60 export function isIOS() {
61 return navigator &&
62 (!!(/ipad/i).exec(navigator.platform) ||
63 !!(/iphone/i).exec(navigator.platform) ||
64 !!(/ipod/i).exec(navigator.platform));
65 }
66
67 export function isSafari() {
68 return navigator && (navigator.userAgent.indexOf('Safari') !== -1 &&
69 navigator.userAgent.indexOf('Chrome') === -1);
70 }
71
72 export function isIE() {
73 return navigator && !!(/trident/i).exec(navigator.userAgent);
74 }
75
76 export function isEdge() {
77 return navigator && !!(/edge/i).exec(navigator.userAgent);
78 }
79
80 export function isFirefox() {
81 return navigator && !!(/firefox/i).exec(navigator.userAgent);
82 }
83