48 lines
1.6 KiB
JavaScript
48 lines
1.6 KiB
JavaScript
export default class AButton extends window.AObject {
|
|
constructor(btn = null) {
|
|
super();
|
|
if (btn != null) {
|
|
if (btn instanceof NodeList) {
|
|
Array.from(btn).forEach(e => {
|
|
this.AddEventBtn(el);
|
|
})
|
|
} else {
|
|
this.AddEventBtn(btn);
|
|
}
|
|
}
|
|
}
|
|
AddEventBtn(e) {
|
|
var f = function (ev) {
|
|
if (ev.currentTarget.classList.contains("disabled")) {
|
|
return;
|
|
} else {
|
|
this.AddLoading(ev.currentTarget);
|
|
if (ev.currentTarget.hasAttribute("group-name")) {
|
|
this.trigger("click_" + ev.currentTarget.getAttribute("group-name"), ev.currentTarget);
|
|
} else if (ev.currentTarget.hasAttribute("id")) {
|
|
this.trigger("click_" + ev.currentTarget.getAttribute("id"), ev.currentTarget);
|
|
}
|
|
|
|
|
|
}
|
|
}.bind(this);
|
|
e.addEventListener("click", f, false);
|
|
this.stackEvent.push({ "event": "click", "callback": f, "element": e, "parent": null });
|
|
}
|
|
AddLoading(e) {
|
|
e.classList.add("disabled", "d-f", "a-i-center");
|
|
var a = document.createElement("div");
|
|
a.classList.add("loader");
|
|
var b = document.createElement("span");
|
|
b.textContent = e.textContent;
|
|
e.innerHTML = "";
|
|
e.appendChild(a);
|
|
e.appendChild(b);
|
|
|
|
}
|
|
RemoveLoading(e) {
|
|
e.classList.remove("disabled", "d-f", "a-i-center");
|
|
var c = e.querySelector("span");
|
|
e.textContent = c.textContent;
|
|
}
|
|
} |