Options: minimum dimension is 45px + UI is updated after save
This commit is contained in:
parent
af99a34045
commit
d8282bdcc4
|
@ -1,17 +1,16 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store options UI using browser.storage.local.
|
* ParseInt with minimum dimension of 45px
|
||||||
* @return {void} -
|
* @param {string} dimension -
|
||||||
|
* @return {int} -
|
||||||
*/
|
*/
|
||||||
function storeSettings() {
|
function parseIntDimension(dimension){
|
||||||
const settings = {
|
const minDimension = 45;
|
||||||
url: document.querySelector("#url").value,
|
let parsedDimension = parseInt(dimension);
|
||||||
popupWidth: parseInt(document.querySelector("#popupWidth").value),
|
if(isNaN(parsedDimension) || parsedDimension < minDimension){
|
||||||
popupHeight: parseInt(document.querySelector("#popupHeight").value),
|
parsedDimension = minDimension;
|
||||||
pageAction: document.querySelector("#pageAction").checked,
|
}
|
||||||
};
|
return parsedDimension;
|
||||||
// console.log('storeSettings settings');
|
|
||||||
// console.log(settings);
|
|
||||||
browser.storage.local.set(settings);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -24,18 +23,45 @@ function updateUI(restoredSettings) {
|
||||||
// console.log('restoredSettings');
|
// console.log('restoredSettings');
|
||||||
// console.dir(restoredSettings, { depth: 10, colors: true }); // DEBUG
|
// console.dir(restoredSettings, { depth: 10, colors: true }); // DEBUG
|
||||||
|
|
||||||
|
// Get HTML input
|
||||||
const url = document.querySelector("#url");
|
const url = document.querySelector("#url");
|
||||||
url.value = restoredSettings.url;
|
|
||||||
|
|
||||||
const popupWidth = document.querySelector("#popupWidth");
|
const popupWidth = document.querySelector("#popupWidth");
|
||||||
popupWidth.value = restoredSettings.popupWidth;
|
|
||||||
const popupHeight = document.querySelector("#popupHeight");
|
const popupHeight = document.querySelector("#popupHeight");
|
||||||
popupHeight.value = restoredSettings.popupHeight;
|
|
||||||
|
|
||||||
const pageAction = document.querySelector("#pageAction");
|
const pageAction = document.querySelector("#pageAction");
|
||||||
|
|
||||||
|
// Set HTML input with stored values
|
||||||
|
url.value = restoredSettings.url;
|
||||||
|
popupWidth.value = restoredSettings.popupWidth;
|
||||||
|
popupHeight.value = restoredSettings.popupHeight;
|
||||||
pageAction.checked = restoredSettings.pageAction;
|
pageAction.checked = restoredSettings.pageAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store options UI using browser.storage.local.
|
||||||
|
* @return {void} -
|
||||||
|
*/
|
||||||
|
function storeSettings() {
|
||||||
|
const url = document.querySelector("#url");
|
||||||
|
const popupWidth = document.querySelector("#popupWidth");
|
||||||
|
const popupHeight = document.querySelector("#popupHeight");
|
||||||
|
const pageAction = document.querySelector("#pageAction");
|
||||||
|
|
||||||
|
const settings = {
|
||||||
|
url: url.value,
|
||||||
|
popupWidth: parseIntDimension(popupWidth.value),
|
||||||
|
popupHeight: parseIntDimension(popupHeight.value),
|
||||||
|
pageAction: pageAction.checked,
|
||||||
|
};
|
||||||
|
// console.log('storeSettings settings');
|
||||||
|
// console.log(settings);
|
||||||
|
|
||||||
|
// Store in storage
|
||||||
|
browser.storage.local.set(settings);
|
||||||
|
|
||||||
|
// Update UI
|
||||||
|
updateUI(settings);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display on error
|
* Display on error
|
||||||
* @param {object} error -
|
* @param {object} error -
|
||||||
|
|
Loading…
Reference in a new issue