summaryrefslogtreecommitdiff
path: root/scripts/gui/input.js
diff options
context:
space:
mode:
authorKyle Gunger <kgunger12@gmail.com>2021-10-15 21:01:22 -0400
committerKyle Gunger <kgunger12@gmail.com>2021-10-15 21:01:22 -0400
commit6c4896d3aa9d618f024b54c8d51f25ca3f625744 (patch)
treea70ceb0b6d477141e7791b21cb6eaa79316529df /scripts/gui/input.js
parentfcf01353f94b11b8ca6db8ead14d2ec89a0275f4 (diff)
[Themes] Theme selection and small fixes
Diffstat (limited to 'scripts/gui/input.js')
-rw-r--r--scripts/gui/input.js37
1 files changed, 35 insertions, 2 deletions
diff --git a/scripts/gui/input.js b/scripts/gui/input.js
index f72dd91..a44784b 100644
--- a/scripts/gui/input.js
+++ b/scripts/gui/input.js
@@ -199,6 +199,10 @@ class MakeInput {
var wrapper = MakeInput.wrapInputs("select", se);
wrapper.getValue = MakeInput.selValue.bind(null, se);
+ wrapper.getIndex = MakeInput.selIndex.bind(null, se);
+ wrapper.addOption = MakeInput.selAdd.bind(se);
+ wrapper.removeOption = MakeInput.selRem.bind(se);
+ wrapper.setIndex = MakeInput.selSet.bind(se);
wrapper.setAttribute("tabindex", 0);
return wrapper;
@@ -213,18 +217,47 @@ class MakeInput {
return "";
}
+
+ static selIndex (el) {
+ return parseInt(el.getAttribute("selected"));
+ }
- static selOption (el) {
+ static selOption (el, dispatch = true) {
let sn = el.selectIndex;
let psn = parseInt(el.parentElement.getAttribute("selected"));
- if(Number.isInteger(psn))
+ if(Number.isInteger(psn) && psn < el.parentElement.childElementCount)
el.parentElement.children[psn].setAttribute("selected", false);
el.parentElement.setAttribute("selected", sn);
el.setAttribute("selected", true);
+
+ if(dispatch)
+ el.parentElement.parentElement.dispatchEvent(new InputEvent("change"));
}
+ static selSet (index) {
+ MakeInput.selOption(this.children[index], false);
+ }
+
+ static selAdd (name, value) {
+ this.appendChild(MakeInput.selectOption(value, name, this.childElementCount, false));
+ return this.childElementCount - 1;
+ }
+
+ static selRem (index) {
+ if(index >= this.childElementCount)
+ return false;
+
+ this.children[index].remove();
+
+ for(let i = index; i < this.childElementCount; i++) {
+ this.children[index].selectIndex = "" + i;
+ }
+
+ return true;
+ }
+
static titleWrap(el, title) {
var wrapper = document.createElement("div");
wrapper.className = "input-title-wrapper";