Merge pull request #650 from kanaka/touchdetect
New way of detecting touch
This commit is contained in:
commit
5826ab6f6a
22
app/ui.js
22
app/ui.js
|
@ -51,7 +51,6 @@ var UI;
|
||||||
controlbarMouseDownOffsetY: 0,
|
controlbarMouseDownOffsetY: 0,
|
||||||
keyboardVisible: false,
|
keyboardVisible: false,
|
||||||
|
|
||||||
isTouchDevice: false,
|
|
||||||
isSafari: false,
|
isSafari: false,
|
||||||
rememberedClipSetting: null,
|
rememberedClipSetting: null,
|
||||||
lastKeyboardinput: null,
|
lastKeyboardinput: null,
|
||||||
|
@ -67,14 +66,13 @@ var UI;
|
||||||
start: function(callback) {
|
start: function(callback) {
|
||||||
|
|
||||||
// Setup global variables first
|
// Setup global variables first
|
||||||
UI.isTouchDevice = 'ontouchstart' in document.documentElement;
|
|
||||||
UI.isSafari = (navigator.userAgent.indexOf('Safari') !== -1 &&
|
UI.isSafari = (navigator.userAgent.indexOf('Safari') !== -1 &&
|
||||||
navigator.userAgent.indexOf('Chrome') === -1);
|
navigator.userAgent.indexOf('Chrome') === -1);
|
||||||
|
|
||||||
UI.initSettings();
|
UI.initSettings();
|
||||||
|
|
||||||
// Adapt the interface for touch screen devices
|
// Adapt the interface for touch screen devices
|
||||||
if (UI.isTouchDevice) {
|
if (Util.isTouchDevice) {
|
||||||
document.documentElement.classList.add("noVNC_touch");
|
document.documentElement.classList.add("noVNC_touch");
|
||||||
// Remove the address bar
|
// Remove the address bar
|
||||||
setTimeout(function() { window.scrollTo(0, 1); }, 100);
|
setTimeout(function() { window.scrollTo(0, 1); }, 100);
|
||||||
|
@ -160,7 +158,7 @@ var UI;
|
||||||
UI.initSetting('password', '');
|
UI.initSetting('password', '');
|
||||||
UI.initSetting('encrypt', (window.location.protocol === "https:"));
|
UI.initSetting('encrypt', (window.location.protocol === "https:"));
|
||||||
UI.initSetting('true_color', true);
|
UI.initSetting('true_color', true);
|
||||||
UI.initSetting('cursor', !UI.isTouchDevice);
|
UI.initSetting('cursor', !Util.isTouchDevice);
|
||||||
UI.initSetting('resize', 'off');
|
UI.initSetting('resize', 'off');
|
||||||
UI.initSetting('shared', true);
|
UI.initSetting('shared', true);
|
||||||
UI.initSetting('view_only', false);
|
UI.initSetting('view_only', false);
|
||||||
|
@ -400,7 +398,7 @@ var UI;
|
||||||
if (Util.browserSupportsCursorURIs()) {
|
if (Util.browserSupportsCursorURIs()) {
|
||||||
document.getElementById('noVNC_setting_cursor').disabled = UI.connected;
|
document.getElementById('noVNC_setting_cursor').disabled = UI.connected;
|
||||||
} else {
|
} else {
|
||||||
UI.updateSetting('cursor', !UI.isTouchDevice);
|
UI.updateSetting('cursor', !Util.isTouchDevice);
|
||||||
document.getElementById('noVNC_setting_cursor').disabled = true;
|
document.getElementById('noVNC_setting_cursor').disabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -769,7 +767,7 @@ var UI;
|
||||||
if (Util.browserSupportsCursorURIs()) {
|
if (Util.browserSupportsCursorURIs()) {
|
||||||
UI.updateSetting('cursor');
|
UI.updateSetting('cursor');
|
||||||
} else {
|
} else {
|
||||||
UI.updateSetting('cursor', !UI.isTouchDevice);
|
UI.updateSetting('cursor', !Util.isTouchDevice);
|
||||||
document.getElementById('noVNC_setting_cursor').disabled = true;
|
document.getElementById('noVNC_setting_cursor').disabled = true;
|
||||||
}
|
}
|
||||||
UI.updateSetting('clip');
|
UI.updateSetting('clip');
|
||||||
|
@ -1224,11 +1222,11 @@ var UI;
|
||||||
// Restore view clip to what it was before fullscreen on IE
|
// Restore view clip to what it was before fullscreen on IE
|
||||||
UI.setViewClip(UI.rememberedClipSetting);
|
UI.setViewClip(UI.rememberedClipSetting);
|
||||||
document.getElementById('noVNC_setting_clip').disabled =
|
document.getElementById('noVNC_setting_clip').disabled =
|
||||||
UI.connected || UI.isTouchDevice;
|
UI.connected || Util.isTouchDevice;
|
||||||
} else {
|
} else {
|
||||||
document.getElementById('noVNC_setting_clip').disabled =
|
document.getElementById('noVNC_setting_clip').disabled =
|
||||||
UI.connected || UI.isTouchDevice;
|
UI.connected || Util.isTouchDevice;
|
||||||
if (UI.isTouchDevice) {
|
if (Util.isTouchDevice) {
|
||||||
UI.setViewClip(true);
|
UI.setViewClip(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1286,7 +1284,7 @@ var UI;
|
||||||
|
|
||||||
// Different behaviour for touch vs non-touch
|
// Different behaviour for touch vs non-touch
|
||||||
// The button is disabled instead of hidden on touch devices
|
// The button is disabled instead of hidden on touch devices
|
||||||
if (UI.isTouchDevice) {
|
if (Util.isTouchDevice) {
|
||||||
viewDragButton.classList.remove("noVNC_hidden");
|
viewDragButton.classList.remove("noVNC_hidden");
|
||||||
|
|
||||||
if (clipping) {
|
if (clipping) {
|
||||||
|
@ -1312,7 +1310,7 @@ var UI;
|
||||||
* ------v------*/
|
* ------v------*/
|
||||||
|
|
||||||
showVirtualKeyboard: function() {
|
showVirtualKeyboard: function() {
|
||||||
if (!UI.isTouchDevice) return;
|
if (!Util.isTouchDevice) return;
|
||||||
|
|
||||||
var input = document.getElementById('noVNC_keyboardinput');
|
var input = document.getElementById('noVNC_keyboardinput');
|
||||||
|
|
||||||
|
@ -1331,7 +1329,7 @@ var UI;
|
||||||
},
|
},
|
||||||
|
|
||||||
hideVirtualKeyboard: function() {
|
hideVirtualKeyboard: function() {
|
||||||
if (!UI.isTouchDevice) return;
|
if (!Util.isTouchDevice) return;
|
||||||
|
|
||||||
var input = document.getElementById('noVNC_keyboardinput');
|
var input = document.getElementById('noVNC_keyboardinput');
|
||||||
|
|
||||||
|
|
|
@ -346,7 +346,7 @@
|
||||||
grab: function () {
|
grab: function () {
|
||||||
var c = this._target;
|
var c = this._target;
|
||||||
|
|
||||||
if ('ontouchstart' in document.documentElement) {
|
if (Util.isTouchDevice) {
|
||||||
c.addEventListener('touchstart', this._eventHandlers.mousedown);
|
c.addEventListener('touchstart', this._eventHandlers.mousedown);
|
||||||
window.addEventListener('touchend', this._eventHandlers.mouseup);
|
window.addEventListener('touchend', this._eventHandlers.mouseup);
|
||||||
c.addEventListener('touchend', this._eventHandlers.mouseup);
|
c.addEventListener('touchend', this._eventHandlers.mouseup);
|
||||||
|
@ -368,7 +368,7 @@
|
||||||
ungrab: function () {
|
ungrab: function () {
|
||||||
var c = this._target;
|
var c = this._target;
|
||||||
|
|
||||||
if ('ontouchstart' in document.documentElement) {
|
if (Util.isTouchDevice) {
|
||||||
c.removeEventListener('touchstart', this._eventHandlers.mousedown);
|
c.removeEventListener('touchstart', this._eventHandlers.mousedown);
|
||||||
window.removeEventListener('touchend', this._eventHandlers.mouseup);
|
window.removeEventListener('touchend', this._eventHandlers.mouseup);
|
||||||
c.removeEventListener('touchend', this._eventHandlers.mouseup);
|
c.removeEventListener('touchend', this._eventHandlers.mouseup);
|
||||||
|
|
12
core/util.js
12
core/util.js
|
@ -241,6 +241,18 @@ Util.stopEvent = function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Touch detection
|
||||||
|
Util.isTouchDevice = ('ontouchstart' in document.documentElement) ||
|
||||||
|
// requried for Chrome debugger
|
||||||
|
(document.ontouchstart !== undefined) ||
|
||||||
|
// required for MS Surface
|
||||||
|
(navigator.maxTouchPoints > 0) ||
|
||||||
|
(navigator.msMaxTouchPoints > 0);
|
||||||
|
window.addEventListener('touchstart', function onFirstTouch() {
|
||||||
|
Util.isTouchDevice = true;
|
||||||
|
window.removeEventListener('touchstart', onFirstTouch, false);
|
||||||
|
}, false);
|
||||||
|
|
||||||
Util._cursor_uris_supported = null;
|
Util._cursor_uris_supported = null;
|
||||||
|
|
||||||
Util.browserSupportsCursorURIs = function () {
|
Util.browserSupportsCursorURIs = function () {
|
||||||
|
|
|
@ -119,7 +119,7 @@
|
||||||
mouse.grab();
|
mouse.grab();
|
||||||
message("Display initialized");
|
message("Display initialized");
|
||||||
|
|
||||||
if ('ontouchstart' in document.documentElement) {
|
if (Util.isTouchDevice) {
|
||||||
message("Touch device detected");
|
message("Touch device detected");
|
||||||
document.getElementById('button-selection').style.display = "inline";
|
document.getElementById('button-selection').style.display = "inline";
|
||||||
document.getElementById('button1').onclick = function(){ selectButton(1) };
|
document.getElementById('button1').onclick = function(){ selectButton(1) };
|
||||||
|
|
Loading…
Reference in New Issue