From fd7b4e1666ace98202bfd0ba9db6ac53f61e552d Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Thu, 18 Jan 2018 15:12:17 +0100 Subject: [PATCH] js/dom: fix little quirks --- src/browser/js/app/ui/utils.js | 6 ++++-- src/browser/js/app/widgets/inputs/input.js | 9 ++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/browser/js/app/ui/utils.js b/src/browser/js/app/ui/utils.js index 819838f9..a4d400d3 100644 --- a/src/browser/js/app/ui/utils.js +++ b/src/browser/js/app/ui/utils.js @@ -49,18 +49,20 @@ module.exports = { close() { if (!this.state) return + this.state = 0 + if (this.escKey) document.removeEventListener('keydown', this.escKeyHandler) if (this.enterKey) document.removeEventListener('keydown', this.enterKeyHandler) document.body.removeChild(this.html) - this.state = 0 } open() { if (this.state) return + this.state = 1 + if (this.escKey) document.addEventListener('keydown', this.escKeyHandler) if (this.enterKey) document.addEventListener('keydown', this.enterKeyHandler) document.body.appendChild(this.html) - this.state = 1 } }, diff --git a/src/browser/js/app/widgets/inputs/input.js b/src/browser/js/app/widgets/inputs/input.js index 13e33629..924bdf84 100644 --- a/src/browser/js/app/widgets/inputs/input.js +++ b/src/browser/js/app/widgets/inputs/input.js @@ -55,6 +55,7 @@ module.exports = class Input extends _canvas_base { this.value = '' this.stringValue = '' + this.focused = false if (this.getProp('vertical')) { this.widget.classList.add('vertical') @@ -83,6 +84,9 @@ module.exports = class Input extends _canvas_base { focus() { + if (this.focused) return + this.focused = true + this.canvas.setAttribute('tabindex','-1') this.input.value = this.stringValue this.widget.insertBefore(this.input, this.canvas) @@ -92,10 +96,13 @@ module.exports = class Input extends _canvas_base { blur(change=true) { + if (!this.focused) return + this.focused = false + if (change) this.inputChange() this.canvas.setAttribute('tabindex','0') - if (this.input.parentNode == this.widget) this.widget.removeChild(input) + this.widget.removeChild(this.input) }