added element injection
Now it's possible to actually inject elements. Next up, let's destroy them.
This commit is contained in:
parent
40693dbc60
commit
951f0a520e
1 changed files with 29 additions and 16 deletions
|
@ -2,8 +2,8 @@
|
||||||
Control the interface!
|
Control the interface!
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export default class interface {
|
export default class UI {
|
||||||
static define(element_type, element_content, element_id = ``, element_class = ``) {
|
static init(element_type, element_content, element_id, element_class) {
|
||||||
/* Defines a new element.
|
/* Defines a new element.
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
|
@ -22,30 +22,43 @@ export default class interface {
|
||||||
element_new.id = element_id;
|
element_new.id = element_id;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (Array.isArray(element_class)) {
|
if (element_class) {
|
||||||
// for of loop
|
if (Array.isArray(element_class)) {
|
||||||
for (const element_class_one of element_class) {
|
// for of loop
|
||||||
element_new.classList.add(element_class_one);
|
for (const element_class_one of element_class) {
|
||||||
|
element_new.classList.add(element_class_one);
|
||||||
|
}
|
||||||
|
} else if ((typeof element_class).includes(`str`)) {
|
||||||
|
element_new.classList.add(element_class);
|
||||||
}
|
}
|
||||||
} else if ((typeof element_class).includes(`str`)) {
|
};
|
||||||
element_new.classList.add(element_class);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (element_new);
|
return (element_new);
|
||||||
};
|
};
|
||||||
|
|
||||||
static add(element_parent, element_type, element_content, element_id = ``, element_class = ``) {
|
static add(element_parent, element_new, element_placement = 1) {
|
||||||
/* Adds or injects an element.
|
/* Adds or injects an element.
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
element_parent: The parent element
|
element_parent: The parent element; may be ID or the element itself
|
||||||
element_type: the element type
|
element_placement: placement
|
||||||
element_content: the content of the element
|
element_new: the new element
|
||||||
element_id: the element id
|
|
||||||
element_class: the element class name
|
|
||||||
Returns: the inserted element
|
Returns: the inserted element
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* If it is the ID */
|
||||||
|
if ((typeof element_parent).includes(`str`)) {
|
||||||
|
element_parent = document.getElementById(element_parent);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Add the element
|
||||||
|
if (element_placement > 0) {
|
||||||
|
element_parent.appendChild(element_new);
|
||||||
|
} else if (element_placement < 0) {
|
||||||
|
element_parent.insertBefore(element_new);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Return the inserted element.
|
||||||
|
return(element_parent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue