diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2019-12-15 20:11:32 -0500 |
---|---|---|
committer | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2019-12-16 19:54:41 -0500 |
commit | 4014bbab427c9c9441ca778f3cda528e35f054f6 (patch) | |
tree | 5339eb63617c5b4d3f8cc87db765036a6af44c51 /ext/fg/js/popup.js | |
parent | 8164ccfbfc257b81b5c35a38b1629d6c1178498d (diff) |
Reorganize popup public functions to match popup proxy
Diffstat (limited to 'ext/fg/js/popup.js')
-rw-r--r-- | ext/fg/js/popup.js | 112 |
1 files changed, 57 insertions, 55 deletions
diff --git a/ext/fg/js/popup.js b/ext/fg/js/popup.js index 6aebc68e..8226a13a 100644 --- a/ext/fg/js/popup.js +++ b/ext/fg/js/popup.js @@ -48,6 +48,63 @@ class Popup { return window.location.href; } + // Public functions + + async setOptions(options) { + this.options = options; + this.updateTheme(); + } + + hide(changeFocus) { + if (!this.isVisible()) { + return; + } + + this.setVisible(false); + if (this.child !== null) { + this.child.hide(false); + } + if (changeFocus) { + this.focusParent(); + } + } + + async isVisibleAsync() { + return this.isVisible(); + } + + setVisibleOverride(visible) { + this.visibleOverride = visible; + this.updateVisibility(); + } + + async containsPoint(x, y) { + for (let popup = this; popup !== null && popup.isVisible(); popup = popup.child) { + const rect = popup.container.getBoundingClientRect(); + if (x >= rect.left && y >= rect.top && x < rect.right && y < rect.bottom) { + return true; + } + } + return false; + } + + async showContent(elementRect, writingMode, type=null, details=null) { + if (!this.isInitialized()) { return; } + await this.show(elementRect, writingMode); + if (type === null) { return; } + this.invokeApi('setContent', {type, details}); + } + + async setCustomCss(css) { + this.invokeApi('setCustomCss', {css}); + } + + clearAutoPlayTimer() { + if (this.isInjected) { + this.invokeApi('clearAutoPlayTimer'); + } + } + inject() { if (this.injectPromise === null) { this.injectPromise = this.createInjectPromise(); @@ -91,18 +148,6 @@ class Popup { return this.options !== null; } - async setOptions(options) { - this.options = options; - this.updateTheme(); - } - - async showContent(elementRect, writingMode, type=null, details=null) { - if (!this.isInitialized()) { return; } - await this.show(elementRect, writingMode); - if (type === null) { return; } - this.invokeApi('setContent', {type, details}); - } - async show(elementRect, writingMode) { await this.inject(); @@ -138,24 +183,6 @@ class Popup { } } - hide(changeFocus) { - if (!this.isVisible()) { - return; - } - - this.setVisible(false); - if (this.child !== null) { - this.child.hide(false); - } - if (changeFocus) { - this.focusParent(); - } - } - - async isVisibleAsync() { - return this.isVisible(); - } - isVisible() { return this.isInjected && (this.visibleOverride !== null ? this.visibleOverride : this.visible); } @@ -165,11 +192,6 @@ class Popup { this.updateVisibility(); } - setVisibleOverride(visible) { - this.visibleOverride = visible; - this.updateVisibility(); - } - updateVisibility() { this.container.style.setProperty('visibility', this.isVisible() ? 'visible' : 'hidden', 'important'); } @@ -203,20 +225,6 @@ class Popup { return dark ? 'dark' : 'light'; } - async containsPoint(x, y) { - for (let popup = this; popup !== null && popup.isVisible(); popup = popup.child) { - const rect = popup.container.getBoundingClientRect(); - if (x >= rect.left && y >= rect.top && x < rect.right && y < rect.bottom) { - return true; - } - } - return false; - } - - async setCustomCss(css) { - this.invokeApi('setCustomCss', {css}); - } - async setCustomOuterCss(css, injectDirectly) { // Cannot repeatedly inject stylesheets using web extension APIs since there is no way to remove them. if (this.stylesheetInjectedViaApi) { return; } @@ -234,12 +242,6 @@ class Popup { } } - clearAutoPlayTimer() { - if (this.isInjected) { - this.invokeApi('clearAutoPlayTimer'); - } - } - invokeApi(action, params={}) { this.container.contentWindow.postMessage({action, params}, '*'); } |