Skip to content

Commit

Permalink
DOM.js update
Browse files Browse the repository at this point in the history
  • Loading branch information
lenincompres committed Oct 26, 2024
1 parent 65af3cd commit 18e0570
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions DOM.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
* Creates DOM structures from a JS object (structure)
* @author Lenin Compres <lenincompres@gmail.com>
* @version 1.2.0
* @version 1.2.1
* @repository https://github.com/lenincompres/DOM.js
*/

Element.prototype.get = function (station) {
Element.prototype.get = function (station) {
let output;
if (!station && this.tagName.toLocaleLowerCase() === "input") output = this.value;
else if (!station || ["content", "inner", "innerhtml", "html"].includes(station)) output = this.innerHTML;
Expand Down Expand Up @@ -570,19 +570,21 @@ class DOM {
});
document.head.set(headModel);
if (Array.isArray(model)) return model.map(m => DOM.set(m, ...args));
// checks if the model requires a new element
if (model.tag) args.push(model.tag);
else if (DOM.typify(model).isPrimitive) args.push("section");
// checks if the model should replace the DOM
if (argsType.boolean) document.body.innerHTML = "";
// checks if the body is loaded
if (document.body) return document.body.set(model, ...args);
// waits for the body to load
window.addEventListener("load", _ => document.body.set(model, ...args));
if (document.body) setTimeout(() => document.body.set(model, ...args), 0);
else window.addEventListener("load", _ => document.body.set(model, ...args));
}
static create = (...args) => DOM.set(...args);
// returns a new element without appending it to the DOM
static element = (model, tag = "section") => DOM.set(model, tag, false);
static element = (model, tag = "section") => {
if (model && model.tag) {
tag = model.tag;
delete model.tag;
}
return document.createElement(tag).set(model);
}
// returns a new binder
static binder(value, ...args) {
let binder = new Binder(value);
Expand Down

0 comments on commit 18e0570

Please sign in to comment.