Popup is fixed to the page it has opened
This commit is contained in:
parent
b98be445ae
commit
0a696ad54e
1 changed files with 42 additions and 21 deletions
|
@ -18,7 +18,27 @@ class Page_Popup extends Page {
|
|||
|
||||
async background() {
|
||||
// Wait until a change in the session storage.
|
||||
observe(async (changes) => {
|
||||
this.update();
|
||||
this.switch();
|
||||
// First, update site data but retain the URL.
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
Update the data used by the page.
|
||||
|
||||
@param {boolean} override override the current data.
|
||||
*/
|
||||
async update(override = false) {
|
||||
// Set the reference website when overriding or unset.
|
||||
(override || !this[`ref`]) ? this[`ref`] = await session.read([`last`, `URL`]) : false;
|
||||
|
||||
// Update all other data.
|
||||
(this[`ref`]) ? this[`data`] = await session.read([`last`]) : false;
|
||||
|
||||
// Merge objects
|
||||
(this[`data`] && this[`ref`]) ? this[`data`] = Object.assign(this[`data`], await session.read([`sites`, this[`ref`]])) : false;
|
||||
}
|
||||
|
||||
async loading() {
|
||||
|
@ -32,21 +52,20 @@ class Page_Popup extends Page {
|
|||
"error": "error.htm"
|
||||
}
|
||||
|
||||
// This will be rewritten to only get the active tab. It should not change whenever the user clicks another tab; it's assumed that he will open the pop-up seperately over there.
|
||||
// Get the last edited site.
|
||||
let SITE = {};
|
||||
SITE = await session.read([`last`], -1);
|
||||
SITE.details = (SITE.url) ? await session.read([`sites`, SITE.url]) : null;
|
||||
// Prepare all the necessary data.
|
||||
await this.update();
|
||||
|
||||
// Make sure that the website has been selected!
|
||||
if (this[`ref`]) {
|
||||
// Set the relative chrome URLs
|
||||
(Object.keys(PAGES)).forEach(PAGE => {
|
||||
PAGES[PAGE] = chrome.runtime.getURL(`pages/popup/${PAGES[PAGE]}`);
|
||||
});
|
||||
|
||||
// Check if the site is available.
|
||||
if (SITE.url ? (!SITE.done) : true) {
|
||||
if ((this[`ref`] && this[`data`]) ? (!this[`data`][`done`]) : true) {
|
||||
this.elements[`frame`].src = PAGES[`loading`];
|
||||
} else if (SITE.details.error) {
|
||||
} else if (this[`data`][`error`]) {
|
||||
// Set the iframe src to display the error.
|
||||
this.elements[`frame`].src = PAGES[`error`];
|
||||
} else {
|
||||
|
@ -54,11 +73,13 @@ class Page_Popup extends Page {
|
|||
this.elements[`frame`].src = PAGES[`results`];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async content() {
|
||||
this.elements = {};
|
||||
this.elements[`frame`] = document.querySelectorAll(`iframe.viewer`);
|
||||
|
||||
|
||||
// Check if the frame is available.
|
||||
if (this.elements[`frame`].length) {
|
||||
await this.switch();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue