Fix: numbers are not compared correctly
This commit is contained in:
parent
e4135ce35d
commit
282bdf7706
27
js/prefs.js
27
js/prefs.js
|
@ -392,17 +392,15 @@ function setupLivePrefs(
|
||||||
IDs = Object.getOwnPropertyNames(prefs.defaults)
|
IDs = Object.getOwnPropertyNames(prefs.defaults)
|
||||||
.filter(id => $('#' + id))
|
.filter(id => $('#' + id))
|
||||||
) {
|
) {
|
||||||
const checkedProps = {};
|
|
||||||
for (const id of IDs) {
|
for (const id of IDs) {
|
||||||
const element = $('#' + id);
|
const element = $('#' + id);
|
||||||
checkedProps[id] = element.type === 'checkbox' ? 'checked' : 'value';
|
|
||||||
updateElement({id, element, force: true});
|
updateElement({id, element, force: true});
|
||||||
element.addEventListener('change', onChange);
|
element.addEventListener('change', onChange);
|
||||||
}
|
}
|
||||||
prefs.subscribe(IDs, (id, value) => updateElement({id, value}));
|
prefs.subscribe(IDs, (id, value) => updateElement({id, value}));
|
||||||
|
|
||||||
function onChange() {
|
function onChange() {
|
||||||
const value = this[checkedProps[this.id]];
|
const value = getInputValue(this);
|
||||||
if (prefs.get(this.id) !== value) {
|
if (prefs.get(this.id) !== value) {
|
||||||
prefs.set(this.id, value);
|
prefs.set(this.id, value);
|
||||||
}
|
}
|
||||||
|
@ -417,10 +415,25 @@ function setupLivePrefs(
|
||||||
prefs.unsubscribe(IDs, updateElement);
|
prefs.unsubscribe(IDs, updateElement);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const prop = checkedProps[id];
|
setInputValue(element, value, force);
|
||||||
if (force || element[prop] !== value) {
|
}
|
||||||
element[prop] = value;
|
function getInputValue(input) {
|
||||||
element.dispatchEvent(new Event('change', {bubbles: true, cancelable: true}));
|
if (input.type === 'checkbox') {
|
||||||
|
return input.checked;
|
||||||
|
}
|
||||||
|
if (input.type === 'number') {
|
||||||
|
return Number(input.value);
|
||||||
|
}
|
||||||
|
return input.value;
|
||||||
|
}
|
||||||
|
function setInputValue(input, value, force = false) {
|
||||||
|
if (force || getInputValue(input) !== value) {
|
||||||
|
if (input.type === 'checkbox') {
|
||||||
|
input.checked = value;
|
||||||
|
} else {
|
||||||
|
input.value = value;
|
||||||
|
}
|
||||||
|
input.dispatchEvent(new Event('change', {bubbles: true, cancelable: true}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user