3
0
Fork 0
mirror of https://github.com/lubosz/overte.git synced 2025-04-17 21:58:18 +02:00
This commit is contained in:
David Rowe 2018-05-05 12:14:51 +12:00
parent 3c2bee757a
commit 5e6b83a634

View file

@ -7,6 +7,9 @@
//
// Sends messages over the EventBridge when text input is required.
//
/* global document, window, console, setTimeout, setInterval, EventBridge */
(function () {
var POLL_FREQUENCY = 500; // ms
var MAX_WARNINGS = 3;
@ -37,18 +40,18 @@
}
return false;
}
};
}
function shouldSetNumeric() {
return document.activeElement.type === "number";
};
}
function scheduleBringToView(timeout) {
setTimeout(function () {
// If the element is not visible because the keyboard has been raised over the top of it, scroll it up into view.
// If the element is not visible because the keyboard raising has moved it off screen, scroll it down into view.
var elementRect = document.activeElement.getBoundingClientRect();
var VISUAL_MARGIN = 3
var VISUAL_MARGIN = 3;
var delta = elementRect.y + elementRect.height + VISUAL_MARGIN - window.innerHeight;
if (delta > 0) {
window.scrollBy(0, delta);
@ -64,11 +67,13 @@
var passwordField = shouldSetPasswordField();
if (isWindowFocused &&
(keyboardRaised !== window.isKeyboardRaised || numericKeyboard !== window.isNumericKeyboard || passwordField !== window.isPasswordField)) {
(keyboardRaised !== window.isKeyboardRaised || numericKeyboard !== window.isNumericKeyboard
|| passwordField !== window.isPasswordField)) {
if (typeof EventBridge !== "undefined" && EventBridge !== null) {
EventBridge.emitWebEvent(
keyboardRaised ? ("_RAISE_KEYBOARD" + (numericKeyboard ? "_NUMERIC" : "") + (passwordField ? "_PASSWORD" : "")) : "_LOWER_KEYBOARD"
keyboardRaised ? ("_RAISE_KEYBOARD" + (numericKeyboard ? "_NUMERIC" : "")
+ (passwordField ? "_PASSWORD" : "")) : "_LOWER_KEYBOARD"
);
} else {
if (numWarnings < MAX_WARNINGS) {
@ -79,7 +84,7 @@
if (!window.isKeyboardRaised) {
scheduleBringToView(250); // Allow time for keyboard to be raised in QML.
// 2DO: should it be rather done from 'client area height changed' event?
// 2DO: should it be rather done from 'client area height changed' event?
}
window.isKeyboardRaised = keyboardRaised;