interface.js: improve hiding elements
This commit is contained in:
parent
5c4f5c0a90
commit
45910aedfb
@ -1,4 +1,6 @@
|
||||
class InterfaceElement {
|
||||
rootNodes = [];
|
||||
|
||||
constructor({fragment}) {
|
||||
if (fragment === undefined) {
|
||||
this.fragment = new DocumentFragment();
|
||||
@ -7,6 +9,18 @@ class InterfaceElement {
|
||||
}
|
||||
}
|
||||
|
||||
scanNodes() {
|
||||
this.rootNodes = [];
|
||||
for (const node of this.fragment.children) {
|
||||
this.rootNodes.push(node);
|
||||
}
|
||||
}
|
||||
|
||||
mount(par) {
|
||||
this.scanNodes();
|
||||
par.append(this.fragment);
|
||||
}
|
||||
|
||||
#hidden = false;
|
||||
get hidden() {
|
||||
return this.#hidden;
|
||||
@ -14,14 +28,12 @@ class InterfaceElement {
|
||||
set hidden(x) {
|
||||
this.#hidden = x;
|
||||
|
||||
this.handle.hidden = this.hidden;
|
||||
if (this.labelTag !== undefined) {
|
||||
this.labelTag.hidden = this.hidden;
|
||||
for (const node of this.rootNodes) {
|
||||
node.hidden = this.hidden;
|
||||
}
|
||||
|
||||
if (this.hidden === true) this.clearAlerts();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function dataTypeSupports(params, validTypes) {
|
||||
@ -86,7 +98,7 @@ class Form extends InterfaceElement {
|
||||
}
|
||||
|
||||
appendElement(elem) {
|
||||
this.handle.append(elem.fragment);
|
||||
elem.mount(this.handle);
|
||||
this.elements.push(elem);
|
||||
if (elem.advanced) {
|
||||
elem.hidden = !this.advanced;
|
||||
@ -195,7 +207,6 @@ class FormElement extends InterfaceElement {
|
||||
this.labelTag = labelTag;
|
||||
}
|
||||
|
||||
|
||||
this.clearAlerts = this.clearAlerts.bind(this);
|
||||
|
||||
this.handle = tag;
|
||||
|
Loading…
Reference in New Issue
Block a user