consider data-actions as interactives
This commit is contained in:
parent
fe2c59920d
commit
ddb455db28
3 changed files with 44 additions and 37 deletions
|
@ -283,7 +283,25 @@ export default class windowman {
|
|||
: false;
|
||||
}
|
||||
|
||||
const actions = () => {
|
||||
let TYPE = `action`;
|
||||
this.elements[`interactive`][TYPE] = (this.elements[`interactive`][TYPE]) ? this.elements[`interactive`][TYPE] : {};
|
||||
|
||||
document.querySelector(`[data-${TYPE}]`)
|
||||
? document.querySelectorAll(`[data-${TYPE}]`).forEach((ELEMENT) => {
|
||||
// Store the button.
|
||||
this.elements[`interactive`][TYPE][ELEMENT.getAttribute(`data-${TYPE}`)] = ((this.elements[`interactive`][TYPE][ELEMENT.getAttribute(`data-${TYPE}`)]))
|
||||
? this.elements[`interactive`][TYPE][ELEMENT.getAttribute(`data-${TYPE}`)]
|
||||
: document.querySelectorAll(`[data-${TYPE}="${ELEMENT.getAttribute(`data-${TYPE}`)}"]`);
|
||||
|
||||
// Remove the property.
|
||||
(!(TYPE.includes(`store`))) ? ELEMENT.removeAttribute(`data-${TYPE}`) : false;
|
||||
})
|
||||
: false;
|
||||
}
|
||||
|
||||
links();
|
||||
actions();
|
||||
}
|
||||
|
||||
this[`elements`] = appearance();
|
||||
|
@ -376,6 +394,9 @@ export default class windowman {
|
|||
(this[`elements`][`linked`][`enable`][SOURCE] ? this[`elements`][`linked`][`enable`][SOURCE].length : false)
|
||||
? this[`elements`][`linked`][`enable`][SOURCE].push(input_element)
|
||||
: this[`elements`][`linked`][`enable`][SOURCE] = [input_element];
|
||||
|
||||
// Remove the attribute.
|
||||
input_element.removeAttribute(`data-enable`);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
|
@ -116,21 +116,16 @@ class Page_Error extends Page {
|
|||
Add event listeners to the page.
|
||||
*/
|
||||
events () {
|
||||
this[`elements`] = (this[`elements`]) ? this[`elements`] : {};
|
||||
this[`elements`][`button`] = {};
|
||||
|
||||
document.querySelectorAll(`[data-action]`).forEach((ELEMENT) => {
|
||||
let ACTION = ELEMENT.getAttribute(`data-action`);
|
||||
this[`elements`][`button`][ACTION] = ELEMENT;
|
||||
|
||||
// Remove the data-action attribute.
|
||||
ELEMENT.removeAttribute(`data-action`);
|
||||
})
|
||||
|
||||
// Add an event listener to the refresh button.
|
||||
this[`elements`][`button`][`refresh`].addEventListener(`click`, () => {
|
||||
(this[`window`][`elements`][`interactive`][`action`] ? this[`window`][`elements`][`interactive`][`action`].length : false)
|
||||
? (this[`window`][`elements`][`interactive`][`action`][`refresh`] ? this[`window`][`elements`][`interactive`][`action`][`refresh`].length : false)
|
||||
? (this[`window`][`elements`][`interactive`][`action`][`refresh`]).forEach((ELEMENT) => {
|
||||
ELEMENT.addEventListener(`click`, () => {
|
||||
this.send();
|
||||
});
|
||||
})
|
||||
})
|
||||
: false
|
||||
: false;
|
||||
};
|
||||
|
||||
/*
|
||||
|
@ -140,7 +135,7 @@ class Page_Error extends Page {
|
|||
try {
|
||||
// Send a message to the content script.
|
||||
Tabs.query(null, 0).then((TAB) => {
|
||||
chrome.tabs.sendMessage(TAB.id, {"refresh": "automatic"});
|
||||
chrome.tabs.sendMessage(TAB.id, {"refresh": "manual"});
|
||||
});
|
||||
} catch(err) {
|
||||
logging.error(err.name, err.message, err.stack);
|
||||
|
|
|
@ -94,7 +94,7 @@ class Page_Popup extends Page {
|
|||
|
||||
// Check if the frame is available.
|
||||
if (this.elements[`frame`]) {
|
||||
await this.switch();
|
||||
this.switch();
|
||||
|
||||
// Call for scraping of data if global data does not indicate automatic scraping or if data doesn't exist.
|
||||
if (!await global.read([`settings`, `behavior`, `autoRun`]) && DATA[`status`] == null) {
|
||||
|
@ -123,28 +123,19 @@ class Page_Popup extends Page {
|
|||
};
|
||||
|
||||
events() {
|
||||
this[`elements`] = (this[`elements`]) ? this[`elements`] : {};
|
||||
this[`elements`][`button`] = {};
|
||||
let ACTIONS = {};
|
||||
ACTIONS[`open,settings`] = () => {chrome.runtime.openOptionsPage();}
|
||||
ACTIONS[`open,help`] = () => {new Window(`help.htm`);}
|
||||
ACTIONS[`analysis,reload`] = () => {this.send({"refresh": "manual"});}
|
||||
|
||||
document.querySelectorAll(`[data-action]`).forEach((ELEMENT) => {
|
||||
let ACTION = ELEMENT.getAttribute(`data-action`).trim();
|
||||
this[`elements`][`button`][ACTION] = ELEMENT;
|
||||
|
||||
// Remove the data-action attribute.
|
||||
ELEMENT.removeAttribute(`data-action`);
|
||||
});
|
||||
|
||||
(this[`elements`][`button`][`open,settings`]) ? this[`elements`][`button`][`open,settings`].addEventListener("click", () => {
|
||||
chrome.runtime.openOptionsPage();
|
||||
}) : false;
|
||||
|
||||
(this[`elements`][`button`][`open,help`]) ? this[`elements`][`button`][`open,help`].addEventListener(`click`, () => {
|
||||
new Window(`help.htm`);
|
||||
}) : false;
|
||||
|
||||
(this[`elements`][`button`][`analysis,reload`]) ? this[`elements`][`button`][`analysis,reload`].addEventListener(`click`, () => {
|
||||
this.send({"refresh": "manual"});
|
||||
}) : false;
|
||||
// Add the event listeners.
|
||||
(Object.keys(ACTIONS)).forEach((NAME) => {
|
||||
(this.window.elements[`interactive`][`action`][NAME] ? this.window.elements[`interactive`][`action`][NAME].length : false)
|
||||
? this.window.elements[`interactive`][`action`][NAME].forEach((ELEMENT) => {
|
||||
ELEMENT.addEventListener(`click`, ACTIONS[NAME]);
|
||||
})
|
||||
: false;
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue