Add $utils object in libsui for enhanced utility functions
This commit is contained in:
parent
271b494c59
commit
0870332e8b
1 changed files with 41 additions and 20 deletions
|
|
@ -30,6 +30,47 @@ func libsui(minify bool) (string, error) {
|
||||||
|
|
||||||
const libsuisource = `
|
const libsuisource = `
|
||||||
|
|
||||||
|
function $$(selector) {
|
||||||
|
elm = null;
|
||||||
|
if (typeof selector === "string" ){
|
||||||
|
elm = document.querySelector(selector);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selector instanceof HTMLElement) {
|
||||||
|
elm = selector;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (elm) {
|
||||||
|
cn = elm.getAttribute("s:cn");
|
||||||
|
if (cn != "" && typeof window[cn] === "function") {
|
||||||
|
const component = new window[cn](elm);
|
||||||
|
return new __sui_component(elm, component);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const $utils = {
|
||||||
|
|
||||||
|
RemoveClass: (element, className) => {
|
||||||
|
const classes = Array.isArray(className) ? className : className.split(" ");
|
||||||
|
classes.forEach((c) => {
|
||||||
|
const v = c.replace(/[\n\r\s]/g, "");
|
||||||
|
if (v === "") return;
|
||||||
|
element.classList.remove(v);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
AddClass: (element, className) => {
|
||||||
|
const classes = Array.isArray(className) ? className : className.split(" ");
|
||||||
|
classes.forEach((c) => {
|
||||||
|
const v = c.replace(/[\n\r\s]/g, "");
|
||||||
|
if (v === "") return;
|
||||||
|
element.classList.add(v);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
function __sui_component_root(elm, name) {
|
function __sui_component_root(elm, name) {
|
||||||
while (elm && elm.getAttribute("s:cn") !== name) {
|
while (elm && elm.getAttribute("s:cn") !== name) {
|
||||||
elm = elm.parentElement;
|
elm = elm.parentElement;
|
||||||
|
|
@ -99,26 +140,6 @@ const libsuisource = `
|
||||||
this.state = component ? new __sui_state(component) : {};
|
this.state = component ? new __sui_state(component) : {};
|
||||||
}
|
}
|
||||||
|
|
||||||
function $$(selector) {
|
|
||||||
elm = null;
|
|
||||||
if (typeof selector === "string" ){
|
|
||||||
elm = document.querySelector(selector);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (selector instanceof HTMLElement) {
|
|
||||||
elm = selector;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (elm) {
|
|
||||||
cn = elm.getAttribute("s:cn");
|
|
||||||
if (cn != "" && typeof window[cn] === "function") {
|
|
||||||
const component = new window[cn](elm);
|
|
||||||
return new __sui_component(elm, component);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
function __sui_event_handler(event, dataKeys, jsonKeys, target, root, handler) {
|
function __sui_event_handler(event, dataKeys, jsonKeys, target, root, handler) {
|
||||||
const data = {};
|
const data = {};
|
||||||
target = target || null;
|
target = target || null;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue