From 2255fadf52bff17d183f48e0bc72a078568481f2 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 5 Oct 2019 21:38:13 -0400 Subject: Rename Popup.setVisible to setVisibleOverride --- ext/mixed/js/display.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'ext/mixed/js') diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index dc64dbea..b70fa4b8 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -445,7 +445,7 @@ class Display { async getScreenshot() { try { - await this.setPopupVisible(false); + await this.setPopupVisibleOverride(false); await Display.delay(1); // Wait for popup to be hidden. const {format, quality} = this.options.anki.screenshot; @@ -454,7 +454,7 @@ class Display { return {dataUrl, format}; } finally { - await this.setPopupVisible(true); + await this.setPopupVisibleOverride(true); } } @@ -462,8 +462,8 @@ class Display { return this.options.general.resultOutputMode === 'merge' ? 0 : -1; } - setPopupVisible(visible) { - return apiForward('popupSetVisible', {visible}); + setPopupVisibleOverride(visible) { + return apiForward('popupSetVisibleOverride', {visible}); } setSpinnerVisible(visible) { -- cgit v1.2.3 From cd6d4e7ee14b3bfde9efb76eb65d7ee91c740c77 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 5 Oct 2019 21:57:13 -0400 Subject: Update how popup visibility works --- ext/fg/js/popup.js | 49 ++++++++++++++++++++++++------------------------- ext/mixed/js/display.js | 2 +- 2 files changed, 25 insertions(+), 26 deletions(-) (limited to 'ext/mixed/js') diff --git a/ext/fg/js/popup.js b/ext/fg/js/popup.js index 5509c98c..9ca91afa 100644 --- a/ext/fg/js/popup.js +++ b/ext/fg/js/popup.js @@ -34,6 +34,9 @@ class Popup { this.container.style.height = '0px'; this.injectPromise = null; this.isInjected = false; + this.visible = false; + this.visibleOverride = null; + this.updateVisibility(); } inject(options) { @@ -105,9 +108,11 @@ class Popup { container.style.top = `${y}px`; container.style.width = `${width}px`; container.style.height = `${height}px`; - container.style.visibility = 'visible'; - this.hideChildren(true); + this.setVisible(true); + if (this.child !== null) { + this.child.hide(true); + } } static getPositionForHorizontalText(elementRect, width, height, maxWidth, maxHeight, optionsGeneral) { @@ -209,41 +214,35 @@ class Popup { } hide(changeFocus) { - if (this.isContainerHidden()) { - changeFocus = false; + if (!this.isVisible()) { + return; + } + + this.setVisible(false); + if (this.child !== null) { + this.child.hide(false); } - this.hideChildren(changeFocus); - this.hideContainer(); if (changeFocus) { this.focusParent(); } } - hideChildren(changeFocus) { - // Recursively hides all children. - if (this.child !== null && !this.child.isContainerHidden()) { - this.child.hide(changeFocus); - } - } - - hideContainer() { - this.container.style.visibility = 'hidden'; + isVisible() { + return this.isInjected && (this.visibleOverride !== null ? this.visibleOverride : this.visible); } - isContainerHidden() { - return (this.container.style.visibility === 'hidden'); + setVisible(visible) { + this.visible = visible; + this.updateVisibility(); } - isVisible() { - return this.isInjected && this.container.style.visibility !== 'hidden'; + setVisibleOverride(visible) { + this.visibleOverride = visible; + this.updateVisibility(); } - setVisibleOverride(visible) { - if (visible) { - this.container.style.setProperty('display', ''); - } else { - this.container.style.setProperty('display', 'none', 'important'); - } + updateVisibility() { + this.container.style.setProperty('visibility', this.isVisible() ? 'visible' : 'hidden', 'important'); } focusParent() { diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index b70fa4b8..575011fd 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -454,7 +454,7 @@ class Display { return {dataUrl, format}; } finally { - await this.setPopupVisibleOverride(true); + await this.setPopupVisibleOverride(null); } } -- cgit v1.2.3