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