]> git.proxmox.com Git - mirror_novnc.git/blame - core/util/browser.js
Move UI.isSafari into core/util/browser.js
[mirror_novnc.git] / core / util / browser.js
CommitLineData
6d6f0db0
SR
1/*
2 * noVNC: HTML5 VNC client
84586c0f 3 * Copyright (C) 2018 The noVNC Authors
6d6f0db0
SR
4 * Licensed under MPL 2.0 (see LICENSE.txt)
5 *
6 * See README.md for usage and integration instructions.
7 */
8
9import * as Log from './logging.js';
10
6d6f0db0 11// Touch detection
2b5f94fa 12export let isTouchDevice = ('ontouchstart' in document.documentElement) ||
6d6f0db0
SR
13 // requried for Chrome debugger
14 (document.ontouchstart !== undefined) ||
15 // required for MS Surface
16 (navigator.maxTouchPoints > 0) ||
17 (navigator.msMaxTouchPoints > 0);
18window.addEventListener('touchstart', function onFirstTouch() {
19 isTouchDevice = true;
20 window.removeEventListener('touchstart', onFirstTouch, false);
21}, false);
22
3b7c4741
SM
23
24// The goal is to find a certain physical width, the devicePixelRatio
25// brings us a bit closer but is not optimal.
26export let dragThreshold = 10 * (window.devicePixelRatio || 1);
27
2b5f94fa 28let _cursor_uris_supported = null;
6d6f0db0 29
2c5491e1 30export function supportsCursorURIs() {
6d6f0db0
SR
31 if (_cursor_uris_supported === null) {
32 try {
2b5f94fa 33 const target = document.createElement('canvas');
6d6f0db0
SR
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;
8727f598 50}
59ef2916
JD
51
52export function isMac() {
53 return navigator && !!(/mac/i).exec(navigator.platform);
54}
55
97e23ebb
SM
56export function isWindows() {
57 return navigator && !!(/win/i).exec(navigator.platform);
58}
59
60export 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
47b3eac8
SM
67export function isSafari() {
68 return navigator && (navigator.userAgent.indexOf('Safari') !== -1 &&
69 navigator.userAgent.indexOf('Chrome') === -1);
70}
71
59ef2916
JD
72export function isIE() {
73 return navigator && !!(/trident/i).exec(navigator.userAgent);
74}
75
76export function isEdge() {
77 return navigator && !!(/edge/i).exec(navigator.userAgent);
78}
79
3a7c0c67
PO
80export function isFirefox() {
81 return navigator && !!(/firefox/i).exec(navigator.userAgent);
82}
83