Skip to content

Commit b29ce30

Browse files
committed
fix some JS code issues
1 parent b5e0dc1 commit b29ce30

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

html/dubeditor.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ function getPathImpl(content, /** @type {string[]} */ path) {
207207
if (part[0] == ":") {
208208
let eqIdx = part.indexOf("=");
209209
let key = part.substring(1, eqIdx);
210-
let val = part.substr(eqIdx + 1);
210+
let val = part.substring(eqIdx + 1);
211211
for (let j = 0; j < scope.length; j++) {
212212
if (scope[j][key] == val) {
213213
scope = scope[j];
@@ -229,7 +229,7 @@ function setPathImpl(content, /** @type {string[]} */ path, /** @type {any} */ v
229229
return;
230230
let eqIdx = part.indexOf("=");
231231
let key = part.substring(1, eqIdx);
232-
let val = part.substr(eqIdx + 1);
232+
let val = part.substring(eqIdx + 1);
233233
for (let j = 0; j < scope.length; j++)
234234
if (scope[j][key] == val) {
235235
scope = scope[j];
@@ -438,11 +438,12 @@ function getLabelElement(setting) {
438438
* @param {HTMLElement} setting
439439
*/
440440
function makeResetButton(setting, configPath) {
441+
if (!setting || !setting.parentElement)
442+
throw new Error("invalid setting element passed in");
443+
441444
let label = getLabelElement(setting);
442445
let modifiedHint = label?.querySelector(".modified-hint a");
443-
if (modifiedHint) {
444-
modifiedHint.parentElement.parentElement.removeChild(modifiedHint.parentElement);
445-
}
446+
modifiedHint?.parentElement?.parentElement?.removeChild(modifiedHint.parentElement);
446447

447448
let next = /** @type {HTMLElement} */(setting.nextElementSibling);
448449
if (next && next.classList.contains("reset-btn")) {
@@ -534,9 +535,7 @@ function makeSetInLabel(setting, usedAccess) {
534535
modifiedHint.setAttribute("data-prefix", usedAccess[1] ? "true" : "false");
535536
modifiedHint.setAttribute("data-suffix", usedAccess[0] ? "true" : "false");
536537
} else {
537-
if (modifiedHint) {
538-
modifiedHint.parentElement.parentElement.removeChild(modifiedHint.parentElement);
539-
}
538+
modifiedHint?.parentElement?.parentElement?.removeChild(modifiedHint.parentElement);
540539
}
541540
}
542541

@@ -569,12 +568,12 @@ function ready() {
569568
if (activeTab === element.id || element.id === undefined)
570569
return;
571570
if (activeTab !== undefined) {
572-
var page = "page" + activeTab.substr(3);
571+
var page = "page" + activeTab.substring(3);
573572
document.getElementById(page).setAttribute("class", "child");
574573
document.getElementById(activeTab).setAttribute("class", "");
575574
}
576575
activeTab = element.id;
577-
page = "page" + activeTab.substr(3);
576+
page = "page" + activeTab.substring(3);
578577
document.getElementById(page).setAttribute("class", "child visible");
579578
element.setAttribute("class", "active");
580579
setState("dub.activeTab", activeTab);
@@ -664,11 +663,11 @@ function loadJsonIntoUI() {
664663
// json-value="name" in string[] for checkboxes
665664
// json-type="string[]"
666665
let label = setting.parentElement;
667-
if (label.tagName != "LABEL")
668-
label = undefined;
666+
if (!label || label.tagName != "LABEL")
667+
label = null;
669668

670669
let inputType = setting.getAttribute("type");
671-
let path = setting.getAttribute("json-path").split(/\./g);
670+
const path = setting.getAttribute("json-path")?.split(/\./g);
672671
if (!path)
673672
continue;
674673
let type = setting.getAttribute("json-type");

0 commit comments

Comments
 (0)