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!
|
||||
*/
|
||||
|
||||
export default class interface {
|
||||
static define(element_type, element_content, element_id = ``, element_class = ``) {
|
||||
export default class UI {
|
||||
static init(element_type, element_content, element_id, element_class) {
|
||||
/* Defines a new element.
|
||||
|
||||
Parameters:
|
||||
|
@ -22,6 +22,7 @@ export default class interface {
|
|||
element_new.id = element_id;
|
||||
};
|
||||
|
||||
if (element_class) {
|
||||
if (Array.isArray(element_class)) {
|
||||
// for of loop
|
||||
for (const element_class_one of element_class) {
|
||||
|
@ -30,22 +31,34 @@ export default class interface {
|
|||
} else if ((typeof element_class).includes(`str`)) {
|
||||
element_new.classList.add(element_class);
|
||||
}
|
||||
};
|
||||
|
||||
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.
|
||||
|
||||
Parameters:
|
||||
element_parent: The parent element
|
||||
element_type: the element type
|
||||
element_content: the content of the element
|
||||
element_id: the element id
|
||||
element_class: the element class name
|
||||
element_parent: The parent element; may be ID or the element itself
|
||||
element_placement: placement
|
||||
element_new: the new 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