Skip to content
This repository has been archived by the owner on Jul 1, 2024. It is now read-only.

Commit

Permalink
Simplify preference panel loading
Browse files Browse the repository at this point in the history
  • Loading branch information
thorio committed May 19, 2020
1 parent 4302e64 commit 1019704
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions src/js/ui/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,15 @@ let load = (preferences) => {
for (let j in preferences[i]) {
let html = "";
switch (typeof group[j]) {
case "string":
html = `<div><span>${j.replace(/_/g, " ")}:</span><input type="text" value="${group[j]}" class="KG-preferences-input-text right" id="KG-preference-${i}-${j}"></div>`;
break;
case "boolean":
html = `<div><span>${j.replace(/_/g, " ")}:</span><input type="checkbox" ${group[j] ? "checked" : ""} class="KG-preferences-input-checkbox right" id="KG-preference-${i}-${j}"></div>`;
break;
case "number":
html = `<div><span>${j.replace(/_/g, " ")}:</span><input type="number" value="${group[j]}" class="KG-preferences-input-text right" id="KG-preference-${i}-${j}"></div>`;
break;
default:
log.err(`unknown type "${typeof group[j]}" of preferences.${i}.${j}`);
case "string":
case "number":
html = `<div><span>${j.replace(/_/g, " ")}:</span><input type="${typeof group[j]}" value="${group[j]}" class="KG-preferences-input-text right" id="KG-preference-${i}-${j}"></div>`;
break;
case "boolean":
html = `<div><span>${j.replace(/_/g, " ")}:</span><input type="checkbox" ${group[j] ? "checked" : ""} class="KG-preferences-input-checkbox right" id="KG-preference-${i}-${j}"></div>`;
break;
default:
log.err(`unknown type "${typeof group[j]}" of preferences.${i}.${j}`);
}
$group.append(html);
}
Expand Down Expand Up @@ -70,12 +68,12 @@ function read() {
let ids = obj.id.slice(14).match(/[^-]+/g);
let value;
switch (obj.type) {
case "checkbox":
value = obj.checked;
break;
default:
value = obj.value;
break;
case "checkbox":
value = obj.checked;
break;
default:
value = obj.value;
break;
}
if (!preferences[ids[0]]) {
preferences[ids[0]] = {};
Expand Down

0 comments on commit 1019704

Please sign in to comment.