mirror of
https://github.com/overte-org/overte.git
synced 2025-04-16 15:02:10 +02:00
Scroll HTML window if necessary when raise keyboard
This commit is contained in:
parent
a94d77ee12
commit
b60f649e0a
2 changed files with 25 additions and 0 deletions
|
@ -12,6 +12,7 @@
|
|||
var MAX_WARNINGS = 3;
|
||||
var numWarnings = 0;
|
||||
var isKeyboardRaised = false;
|
||||
var KEYBOARD_HEIGHT = 200;
|
||||
|
||||
function shouldRaiseKeyboard() {
|
||||
if (document.activeElement.nodeName == "INPUT" || document.activeElement.nodeName == "TEXTAREA") {
|
||||
|
@ -31,6 +32,15 @@
|
|||
setInterval(function () {
|
||||
if (isKeyboardRaised !== shouldRaiseKeyboard()) {
|
||||
isKeyboardRaised = !isKeyboardRaised;
|
||||
|
||||
if (isKeyboardRaised) {
|
||||
var delta = document.activeElement.getBoundingClientRect().bottom + 10
|
||||
- (document.body.clientHeight - KEYBOARD_HEIGHT);
|
||||
if (delta > 0) {
|
||||
document.body.scrollTop += delta;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof EventBridge != "undefined") {
|
||||
EventBridge.emitWebEvent(isKeyboardRaised ? "_RAISE_KEYBOARD" : "_LOWER_KEYBOARD");
|
||||
} else {
|
||||
|
|
|
@ -11,18 +11,33 @@
|
|||
function setUpKeyboardControl() {
|
||||
|
||||
var lowerTimer = null;
|
||||
var isRaised = false;
|
||||
var KEYBOARD_HEIGHT = 200;
|
||||
|
||||
function raiseKeyboard() {
|
||||
if (lowerTimer !== null) {
|
||||
clearTimeout(lowerTimer);
|
||||
lowerTimer = null;
|
||||
}
|
||||
|
||||
if (isRaised) {
|
||||
return;
|
||||
}
|
||||
|
||||
var delta = this.getBoundingClientRect().bottom + 10 - (document.body.clientHeight - KEYBOARD_HEIGHT);
|
||||
if (delta > 0) {
|
||||
document.body.scrollTop += delta;
|
||||
}
|
||||
|
||||
EventBridge.emitWebEvent("_RAISE_KEYBOARD");
|
||||
|
||||
isRaised = true;
|
||||
}
|
||||
|
||||
function doLowerKeyboard() {
|
||||
EventBridge.emitWebEvent("_LOWER_KEYBOARD");
|
||||
lowerTimer = null;
|
||||
isRaised = false;
|
||||
}
|
||||
|
||||
function lowerKeyboard() {
|
||||
|
|
Loading…
Reference in a new issue