Reviewed Highlighter and Options waiters

This commit is contained in:
n1474335 2023-01-19 17:14:24 +00:00
parent 934efcc5a0
commit fa21768931
3 changed files with 16 additions and 27 deletions

View file

@ -26,33 +26,27 @@ class OptionsWaiter {
* @param {Object} options
*/
load(options) {
for (const option in options) {
this.app.options[option] = options[option];
}
Object.assign(this.app.options, options);
// Set options to match object
const cboxes = document.querySelectorAll("#options-body input[type=checkbox]");
let i;
for (i = 0; i < cboxes.length; i++) {
cboxes[i].checked = this.app.options[cboxes[i].getAttribute("option")];
}
document.querySelectorAll("#options-body input[type=checkbox]").forEach(cbox => {
cbox.checked = this.app.options[cbox.getAttribute("option")];
});
const nboxes = document.querySelectorAll("#options-body input[type=number]");
for (i = 0; i < nboxes.length; i++) {
nboxes[i].value = this.app.options[nboxes[i].getAttribute("option")];
nboxes[i].dispatchEvent(new CustomEvent("change", {bubbles: true}));
}
document.querySelectorAll("#options-body input[type=number]").forEach(nbox => {
nbox.value = this.app.options[nbox.getAttribute("option")];
nbox.dispatchEvent(new CustomEvent("change", {bubbles: true}));
});
const selects = document.querySelectorAll("#options-body select");
for (i = 0; i < selects.length; i++) {
const val = this.app.options[selects[i].getAttribute("option")];
document.querySelectorAll("#options-body select").forEach(select => {
const val = this.app.options[select.getAttribute("option")];
if (val) {
selects[i].value = val;
selects[i].dispatchEvent(new CustomEvent("change", {bubbles: true}));
select.value = val;
select.dispatchEvent(new CustomEvent("change", {bubbles: true}));
} else {
selects[i].selectedIndex = 0;
select.selectedIndex = 0;
}
}
});
// Initialise options
this.setWordWrap();
@ -151,7 +145,6 @@ class OptionsWaiter {
*/
themeChange(e) {
const themeClass = e.target.value;
this.changeTheme(themeClass);
}