From dd8eac8cb2d156513c49b5fb551ac492ee9eff23 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Fri, 4 May 2018 16:14:42 +1200 Subject: [PATCH 1/5] Remove superfluous keyboardControl.js file and references The raiseAndLowerKeyboard.js script is automatically injected into these pages, instead. --- scripts/system/html/entityList.html | 1 - scripts/system/html/entityProperties.html | 1 - scripts/system/html/gridControls.html | 1 - scripts/system/html/js/keyboardControl.js | 73 ----------------------- 4 files changed, 76 deletions(-) delete mode 100644 scripts/system/html/js/keyboardControl.js diff --git a/scripts/system/html/entityList.html b/scripts/system/html/entityList.html index d608ab63e5..7906a3c97f 100644 --- a/scripts/system/html/entityList.html +++ b/scripts/system/html/entityList.html @@ -14,7 +14,6 @@ - diff --git a/scripts/system/html/entityProperties.html b/scripts/system/html/entityProperties.html index 8647dca035..8d63261f4c 100644 --- a/scripts/system/html/entityProperties.html +++ b/scripts/system/html/entityProperties.html @@ -20,7 +20,6 @@ - diff --git a/scripts/system/html/gridControls.html b/scripts/system/html/gridControls.html index c0bd87988d..cd646fed51 100644 --- a/scripts/system/html/gridControls.html +++ b/scripts/system/html/gridControls.html @@ -16,7 +16,6 @@ - diff --git a/scripts/system/html/js/keyboardControl.js b/scripts/system/html/js/keyboardControl.js deleted file mode 100644 index 7a8a314c62..0000000000 --- a/scripts/system/html/js/keyboardControl.js +++ /dev/null @@ -1,73 +0,0 @@ -// -// keyboardControl.js -// -// Created by David Rowe on 28 Sep 2016. -// Copyright 2016 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -function setUpKeyboardControl() { - - var lowerTimer = null; - var isRaised = false; - var KEYBOARD_HEIGHT = 200; - - function raiseKeyboard() { - window.isKeyboardRaised = true; - window.isNumericKeyboard = this.type === "number"; - - if (lowerTimer !== null) { - clearTimeout(lowerTimer); - lowerTimer = null; - } - - EventBridge.emitWebEvent("_RAISE_KEYBOARD" + (this.type === "number" ? "_NUMERIC" : "")); - - if (!isRaised) { - var delta = this.getBoundingClientRect().bottom + 10 - (document.body.clientHeight - KEYBOARD_HEIGHT); - if (delta > 0) { - setTimeout(function () { - document.body.scrollTop += delta; - }, 500); // Allow time for keyboard to be raised in QML. - } - } - - isRaised = true; - } - - function doLowerKeyboard() { - window.isKeyboardRaised = false; - window.isNumericKeyboard = false; - - EventBridge.emitWebEvent("_LOWER_KEYBOARD"); - lowerTimer = null; - isRaised = false; - } - - function lowerKeyboard() { - // Delay lowering keyboard a little in case immediately raise it again. - if (lowerTimer === null) { - lowerTimer = setTimeout(doLowerKeyboard, 20); - } - } - - function documentBlur() { - // Action any pending Lower keyboard event immediately upon leaving document window so that they don't interfere with - // other Entities Editor tab. - if (lowerTimer !== null) { - clearTimeout(lowerTimer); - doLowerKeyboard(); - } - } - - var inputs = document.querySelectorAll("input[type=text], input[type=password], input[type=number], textarea"); - for (var i = 0, length = inputs.length; i < length; i++) { - inputs[i].addEventListener("focus", raiseKeyboard); - inputs[i].addEventListener("blur", lowerKeyboard); - } - - window.addEventListener("blur", documentBlur); -} - From 03da2f09461b54a2b7fc8b119d8454212f62c8f5 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Fri, 4 May 2018 20:32:53 +1200 Subject: [PATCH 2/5] Only scroll keyboard if necessary --- interface/resources/html/raiseAndLowerKeyboard.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/interface/resources/html/raiseAndLowerKeyboard.js b/interface/resources/html/raiseAndLowerKeyboard.js index a0aa1eb7fe..b2688e3db8 100644 --- a/interface/resources/html/raiseAndLowerKeyboard.js +++ b/interface/resources/html/raiseAndLowerKeyboard.js @@ -44,15 +44,14 @@ }; function scheduleBringToView(timeout) { - - var timer = setTimeout(function () { - clearTimeout(timer); - + setTimeout(function () { + // If the element is not visible because the keyboard has been raised over the top of it, scroll it into view. var elementRect = document.activeElement.getBoundingClientRect(); - var absoluteElementTop = elementRect.top + window.scrollY; - var middle = absoluteElementTop - (window.innerHeight / 2); - - window.scrollTo(0, middle); + var VISUAL_MARGIN = 3 + var delta = elementRect.y + elementRect.height + VISUAL_MARGIN - window.innerHeight; + if (delta > 0) { + window.scrollBy(0, delta); + } }, timeout); } From 1be948ee2846b02e98e974568798ff275cf40cf3 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Sat, 5 May 2018 12:03:18 +1200 Subject: [PATCH 3/5] Scroll element into view if it's been moved off the screen --- interface/resources/html/raiseAndLowerKeyboard.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/interface/resources/html/raiseAndLowerKeyboard.js b/interface/resources/html/raiseAndLowerKeyboard.js index b2688e3db8..15df94334c 100644 --- a/interface/resources/html/raiseAndLowerKeyboard.js +++ b/interface/resources/html/raiseAndLowerKeyboard.js @@ -45,12 +45,15 @@ function scheduleBringToView(timeout) { setTimeout(function () { - // If the element is not visible because the keyboard has been raised over the top of it, scroll it into view. + // 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 delta = elementRect.y + elementRect.height + VISUAL_MARGIN - window.innerHeight; if (delta > 0) { window.scrollBy(0, delta); + } else if (elementRect.y < VISUAL_MARGIN) { + window.scrollBy(0, elementRect.y - VISUAL_MARGIN); } }, timeout); } From 3c2bee757a521e918d195772a88dc8e3913f50a4 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Sat, 5 May 2018 12:14:40 +1200 Subject: [PATCH 4/5] Remove calls to function that's been removed --- scripts/system/html/js/entityList.js | 2 -- scripts/system/html/js/entityProperties.js | 4 +--- scripts/system/html/js/gridControls.js | 2 -- 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/scripts/system/html/js/entityList.js b/scripts/system/html/js/entityList.js index 625aa26b00..88b3ccbf7c 100644 --- a/scripts/system/html/js/entityList.js +++ b/scripts/system/html/js/entityList.js @@ -444,8 +444,6 @@ function loaded() { augmentSpinButtons(); - setUpKeyboardControl(); - // Disable right-click context menu which is not visible in the HMD and makes it seem like the app has locked document.addEventListener("contextmenu", function (event) { event.preventDefault(); diff --git a/scripts/system/html/js/entityProperties.js b/scripts/system/html/js/entityProperties.js index 4b6329db44..2194b539ef 100644 --- a/scripts/system/html/js/entityProperties.js +++ b/scripts/system/html/js/entityProperties.js @@ -7,7 +7,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html /* global alert, augmentSpinButtons, clearTimeout, console, document, Element, EventBridge, - HifiEntityUI, JSONEditor, openEventBridge, setUpKeyboardControl, setTimeout, window, _ $ */ + HifiEntityUI, JSONEditor, openEventBridge, setTimeout, window, _ $ */ var PI = 3.14159265358979; var DEGREES_TO_RADIANS = PI / 180.0; @@ -2157,8 +2157,6 @@ function loaded() { augmentSpinButtons(); - setUpKeyboardControl(); - // Disable right-click context menu which is not visible in the HMD and makes it seem like the app has locked document.addEventListener("contextmenu", function(event) { event.preventDefault(); diff --git a/scripts/system/html/js/gridControls.js b/scripts/system/html/js/gridControls.js index be4271788e..79a169400a 100644 --- a/scripts/system/html/js/gridControls.js +++ b/scripts/system/html/js/gridControls.js @@ -129,8 +129,6 @@ function loaded() { augmentSpinButtons(); - setUpKeyboardControl(); - EventBridge.emitWebEvent(JSON.stringify({ type: 'init' })); }); document.addEventListener("keydown", function (keyDown) { From 5e6b83a6346bde1d00fc148c073d0b7687a01692 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Sat, 5 May 2018 12:14:51 +1200 Subject: [PATCH 5/5] Lint --- .../resources/html/raiseAndLowerKeyboard.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/interface/resources/html/raiseAndLowerKeyboard.js b/interface/resources/html/raiseAndLowerKeyboard.js index 15df94334c..f40c0d7376 100644 --- a/interface/resources/html/raiseAndLowerKeyboard.js +++ b/interface/resources/html/raiseAndLowerKeyboard.js @@ -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;