aboutsummaryrefslogtreecommitdiff
path: root/ext/fg/js/popup.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-08-23 15:18:41 -0400
committerGitHub <noreply@github.com>2020-08-23 15:18:41 -0400
commit773e28aa3c23c1cb93d5b19b10c49fcec19487a9 (patch)
treefcf3c775c3f97d1852848253149a47b55fa0a753 /ext/fg/js/popup.js
parent934355dd09aa8b7e8993759b678af063b56b9fc6 (diff)
Fix screenshot popup hide (#753)
* Refactor Popup.setVisibleOverride * Use event to observe visibility changes * Add setAllVisibleOverride/clearAllVisibleOverride * Add setAllVisibleOverride/clearAllVisibleOverride cross frame handlers * Update how visibility is changed * Wait for next frame to ensure visibility has been updated
Diffstat (limited to 'ext/fg/js/popup.js')
-rw-r--r--ext/fg/js/popup.js24
1 files changed, 13 insertions, 11 deletions
diff --git a/ext/fg/js/popup.js b/ext/fg/js/popup.js
index bbf39c4e..f644ee98 100644
--- a/ext/fg/js/popup.js
+++ b/ext/fg/js/popup.js
@@ -34,8 +34,7 @@ class Popup extends EventDispatcher {
this._childrenSupported = true;
this._injectPromise = null;
this._injectPromiseComplete = false;
- this._visible = false;
- this._visibleOverride = null;
+ this._visible = new DynamicProperty(false);
this._options = null;
this._optionsContext = null;
this._contentScale = 1.0;
@@ -96,11 +95,12 @@ class Popup extends EventDispatcher {
// Public functions
prepare() {
- this._updateVisibility();
this._frame.addEventListener('mousedown', (e) => e.stopPropagation());
this._frame.addEventListener('scroll', (e) => e.stopPropagation());
this._frame.addEventListener('load', this._onFrameLoad.bind(this));
+ this._visible.on('change', this._onVisibleChange.bind(this));
yomichan.on('extensionUnloaded', this._onExtensionUnloaded.bind(this));
+ this._onVisibleChange({value: this.isVisibleSync()});
}
async setOptionsContext(optionsContext, source) {
@@ -131,9 +131,12 @@ class Popup extends EventDispatcher {
return this.isVisibleSync();
}
- setVisibleOverride(visible) {
- this._visibleOverride = visible;
- this._updateVisibility();
+ async setVisibleOverride(value, priority) {
+ return this._visible.setOverride(value, priority);
+ }
+
+ async clearVisibleOverride(token) {
+ return this._visible.clearOverride(token);
}
async containsPoint(x, y) {
@@ -177,7 +180,7 @@ class Popup extends EventDispatcher {
}
isVisibleSync() {
- return (this._visibleOverride !== null ? this._visibleOverride : this._visible);
+ return this._visible.value;
}
updateTheme() {
@@ -392,12 +395,11 @@ class Popup extends EventDispatcher {
}
_setVisible(visible) {
- this._visible = visible;
- this._updateVisibility();
+ this._visible.defaultValue = visible;
}
- _updateVisibility() {
- this._frame.style.setProperty('visibility', this.isVisibleSync() ? 'visible' : 'hidden', 'important');
+ _onVisibleChange({value}) {
+ this._frame.style.setProperty('visibility', value ? 'visible' : 'hidden', 'important');
}
_focusParent() {