Clean up virtual keyboard handling
This commit is contained in:
parent
1a15cb5b32
commit
4b30f9ce09
77
app/ui.js
77
app/ui.js
|
@ -231,12 +231,12 @@ var UI;
|
||||||
document.getElementById("noVNC_mouse_button4")
|
document.getElementById("noVNC_mouse_button4")
|
||||||
.addEventListener('click', function () { UI.setMouseButton(0); });
|
.addEventListener('click', function () { UI.setMouseButton(0); });
|
||||||
document.getElementById("noVNC_keyboard_button")
|
document.getElementById("noVNC_keyboard_button")
|
||||||
.addEventListener('click', UI.showKeyboard);
|
.addEventListener('click', UI.toggleVirtualKeyboard);
|
||||||
|
|
||||||
document.getElementById("noVNC_keyboardinput")
|
document.getElementById("noVNC_keyboardinput")
|
||||||
.addEventListener('input', UI.keyInput);
|
.addEventListener('input', UI.keyInput);
|
||||||
document.getElementById("noVNC_keyboardinput")
|
document.getElementById("noVNC_keyboardinput")
|
||||||
.addEventListener('blur', UI.hideKeyboard);
|
.addEventListener('blur', UI.onblurVirtualKeyboard);
|
||||||
document.getElementById("noVNC_keyboardinput")
|
document.getElementById("noVNC_keyboardinput")
|
||||||
.addEventListener('submit', function () { return false; });
|
.addEventListener('submit', function () { return false; });
|
||||||
|
|
||||||
|
@ -1281,45 +1281,64 @@ var UI;
|
||||||
* KEYBOARD
|
* KEYBOARD
|
||||||
* ------v------*/
|
* ------v------*/
|
||||||
|
|
||||||
// On touch devices, show the OS keyboard
|
showVirtualKeyboard: function() {
|
||||||
showKeyboard: function() {
|
if (!UI.isTouchDevice)
|
||||||
var kbi = document.getElementById('noVNC_keyboardinput');
|
return;
|
||||||
var skb = document.getElementById('noVNC_keyboard_button');
|
|
||||||
var l = kbi.value.length;
|
var input = document.getElementById('noVNC_keyboardinput');
|
||||||
if(UI.keyboardVisible === false) {
|
|
||||||
kbi.focus();
|
if (document.activeElement == input)
|
||||||
try { kbi.setSelectionRange(l, l); } // Move the caret to the end
|
return;
|
||||||
catch (err) {} // setSelectionRange is undefined in Google Chrome
|
|
||||||
UI.keyboardVisible = true;
|
UI.keyboardVisible = true;
|
||||||
skb.classList.add("noVNC_selected");
|
document.getElementById('noVNC_keyboard_button')
|
||||||
} else if(UI.keyboardVisible === true) {
|
.classList.add("noVNC_selected");
|
||||||
kbi.blur();
|
input.focus();
|
||||||
skb.classList.remove("noVNC_selected");
|
|
||||||
UI.keyboardVisible = false;
|
try {
|
||||||
|
var l = input.value.length;
|
||||||
|
// Move the caret to the end
|
||||||
|
input.setSelectionRange(l, l);
|
||||||
|
} catch (err) {} // setSelectionRange is undefined in Google Chrome
|
||||||
|
},
|
||||||
|
|
||||||
|
hideVirtualKeyboard: function() {
|
||||||
|
if (!UI.isTouchDevice)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var input = document.getElementById('noVNC_keyboardinput');
|
||||||
|
|
||||||
|
if (document.activeElement != input)
|
||||||
|
return;
|
||||||
|
|
||||||
|
input.blur();
|
||||||
|
},
|
||||||
|
|
||||||
|
toggleVirtualKeyboard: function () {
|
||||||
|
if (UI.keyboardVisible) {
|
||||||
|
UI.hideVirtualKeyboard();
|
||||||
|
} else {
|
||||||
|
UI.showVirtualKeyboard();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
hideKeyboard: function() {
|
onblurVirtualKeyboard: function() {
|
||||||
document.getElementById('noVNC_keyboard_button')
|
|
||||||
.classList.remove("noVNC_selected");
|
|
||||||
//Weird bug in iOS if you change keyboardVisible
|
//Weird bug in iOS if you change keyboardVisible
|
||||||
//here it does not actually occur so next time
|
//here it does not actually occur so next time
|
||||||
//you click keyboard icon it doesnt work.
|
//you click keyboard icon it doesnt work.
|
||||||
UI.hideKeyboardTimeout = setTimeout(function() {
|
UI.hideKeyboardTimeout = setTimeout(function() {
|
||||||
UI.keyboardVisible = false;
|
UI.keyboardVisible = false;
|
||||||
|
document.getElementById('noVNC_keyboard_button')
|
||||||
|
.classList.remove("noVNC_selected");
|
||||||
},100);
|
},100);
|
||||||
},
|
},
|
||||||
|
|
||||||
keepKeyboard: function() {
|
keepKeyboard: function() {
|
||||||
clearTimeout(UI.hideKeyboardTimeout);
|
clearTimeout(UI.hideKeyboardTimeout);
|
||||||
if(UI.keyboardVisible === true) {
|
if(UI.keyboardVisible === true) {
|
||||||
document.getElementById('noVNC_keyboardinput').focus();
|
UI.showVirtualKeyboard();
|
||||||
document.getElementById('noVNC_keyboard_button')
|
|
||||||
.classList.add("noVNC_selected");
|
|
||||||
} else if(UI.keyboardVisible === false) {
|
} else if(UI.keyboardVisible === false) {
|
||||||
document.getElementById('noVNC_keyboardinput').blur();
|
UI.hideVirtualKeyboard();
|
||||||
document.getElementById('noVNC_keyboard_button')
|
|
||||||
.classList.remove("noVNC_selected");
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -1400,6 +1419,12 @@ var UI;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/* ------^-------
|
||||||
|
* /KEYBOARD
|
||||||
|
* ==============
|
||||||
|
* EXTRA KEYS
|
||||||
|
* ------v------*/
|
||||||
|
|
||||||
openExtraKeys: function() {
|
openExtraKeys: function() {
|
||||||
UI.closeAllPanels();
|
UI.closeAllPanels();
|
||||||
UI.openControlbar();
|
UI.openControlbar();
|
||||||
|
@ -1467,7 +1492,7 @@ var UI;
|
||||||
},
|
},
|
||||||
|
|
||||||
/* ------^-------
|
/* ------^-------
|
||||||
* /KEYBOARD
|
* /EXTRA KEYS
|
||||||
* ==============
|
* ==============
|
||||||
* MISC
|
* MISC
|
||||||
* ------v------*/
|
* ------v------*/
|
||||||
|
|
Loading…
Reference in New Issue