Skip to content

Commit

Permalink
www/js- fix create_element callsites
Browse files Browse the repository at this point in the history
  • Loading branch information
nektro committed Apr 17, 2022
1 parent ebd289d commit 9664594
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 26 deletions.
8 changes: 4 additions & 4 deletions www/chat/js/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
* @param {Node[]} children
* @returns {HTMLElement}
*/
export function create_element(name, attrs, children, events) {
export function create_element(name, attrs = [], children = [], events = []) {
const ele = document.createElement(name);
(attrs || []).forEach((v) => { ele.setAttribute(v[0], v[1]); });
(children || []).forEach((v) => { ele.appendChild(v); });
(events || []).forEach((v) => { ele.addEventListener(v[0], v[1]); });
attrs.forEach((v) => { ele.setAttribute(v[0], v[1]); });
children.forEach((v) => { ele.appendChild(v); });
events.forEach((v) => { ele.addEventListener(v[0], v[1]); });
return ele;
}

Expand Down
4 changes: 2 additions & 2 deletions www/chat/js/x/x-2s-toggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ customElements.define("x-2s-toggle", class extends WSetting {
const ln = this.getAttribute("local-name");
const n = this.getAttribute("name");
const d = this.getAttribute("label") || "";
this.appendChild(create_element("div", null, [dcTN(d)]));
this.appendChild(create_element("label", null, [
this.appendChild(create_element("div", [], [dcTN(d)]));
this.appendChild(create_element("label", [], [
create_element("input", [["type", "checkbox"]]),
create_element("span")
]));
Expand Down
4 changes: 2 additions & 2 deletions www/chat/js/x/x-3s-toggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ customElements.define("x-3s-toggle", class extends WSetting {
Math.random().toString().replace(".", ""),
Math.random().toString().replace(".", ""),
];
this.appendChild(create_element("form", null, [
create_element("label", null, [dcTN(d)]),
this.appendChild(create_element("form", [], [
create_element("label", [], [dcTN(d)]),
create_element("div", [["clasS", "switch-toggle switch-candy"]], [
create_element("input", [["id", `deny_${t[0]}`], ["name", n], ["type", "radio"]]),
create_element("label", [["for", `deny_${t[0]}`]], [
Expand Down
4 changes: 2 additions & 2 deletions www/chat/js/x/x-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ customElements.define("x-button", class extends WSetting {
}

connectedCallback() {
this.appendChild(create_element("form", null, [
create_element("button", null, [dcTN(this.getAttribute("text"))]),
this.appendChild(create_element("form", [], [
create_element("button", [], [dcTN(this.getAttribute("text"))]),
]));
this.querySelector("form").addEventListener("submit", async (ev) => {
ev.preventDefault();
Expand Down
6 changes: 3 additions & 3 deletions www/chat/js/x/x-msg-pane.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async function _make_m_element(user, msg) {
return "";
});
}
safe_html_replace(mtx, /(`.+`)/gu, (match) => create_element("code", null, [dcTN(match.substring(1, match.length - 1))]));
safe_html_replace(mtx, /(`.+`)/gu, (match) => create_element("code", [], [dcTN(match.substring(1, match.length - 1))]));
safe_html_replace(mtx, /(\|\|[\w ]+\|\|)/gu, (match) => create_element("x-spoiler", [], [dcTN(match.substring(2, match.length - 2))]));
safe_html_replace(mtx, /([a-z]+:\/\/[^\s]+)/gu, (match) => create_element("a", [["href", match], ["target", "_blank"]], [dcTN(decodeURIComponent(match))]));
safe_html_replace(mtx, /(magnet:[^\s]+)/gu, (match) => create_element("a", [["href", match], ["target", "_blank"]], [dcTN(decodeURIComponent(match))]));
Expand All @@ -55,14 +55,14 @@ async function _make_m_element(user, msg) {
*/
function _make_m_divider(msg) {
return create_element("fieldset", [["class", "div date"]], [
create_element("legend", null, [dcTN(msg.time.toString().substring(0, 15))])
create_element("legend", [], [dcTN(msg.time.toString().substring(0, 15))])
]);
}

//
function _make_m_newdiv() {
return create_element("fieldset", [["class", "div new"]], [
create_element("legend", null, [dcTN("New")])
create_element("legend", [], [dcTN("New")])
]);
}

Expand Down
6 changes: 3 additions & 3 deletions www/chat/js/x/x-text-setting.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ customElements.define("x-text-setting", class extends WSetting {
const v = this.getAttribute("value") || "";
const d = this.getAttribute("label") || "";
const b = this.getAttribute("binding");
this.appendChild(create_element("form", null, [
this.appendChild(create_element("form", [], [
create_element("label", [["for", "input_" + t]], [dcTN(d)]),
create_element("div", null, [
create_element("div", [], [
create_element("input", [["type", "text"], ["name", n], ["id", "input_" + t], ["value", v]]),
create_element("button", null, [
create_element("button", [], [
create_element("i", [["class", "check icon"]])
]),
]),
Expand Down
4 changes: 2 additions & 2 deletions www/chat/js/x/x-uonline-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ customElements.define("x-uonline-user", class extends HTMLElement {
this.setAttribute("data-role", l[0].uuid);
}
}
this.appendChild(create_element("span", null, [dcTN(o.getName())]));
this.appendChild(create_element("span", null, [dcTN("#" + o.id)]));
this.appendChild(create_element("span", [], [dcTN(o.getName())]));
this.appendChild(create_element("span", [], [dcTN("#" + o.id)]));
//
el_xud.triggers.push("x-uonline-user");
this.addEventListener("click", async (e) => {
Expand Down
16 changes: 8 additions & 8 deletions www/chat/js/x/x-user-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ customElements.define("x-user-dialog", class extends HTMLElement {
async openWith(uid, e) {
const userN = await api.M.users.get(uid);
this.removeAllChildren();
this.appendChild(create_element("div", null, [
create_element("h2", null, [dcTN(userN.nickname)]),
create_element("h2", null, [
create_element("span", null, [dcTN(userN.name)]),
this.appendChild(create_element("div", [], [
create_element("h2", [], [dcTN(userN.nickname)]),
create_element("h2", [], [
create_element("span", [], [dcTN(userN.name)]),
dcTN("#"),
create_element("span", null, [dcTN(userN.id)]),
create_element("span", [], [dcTN(userN.id)]),
]),
create_element("div", [["id", "pp_uuid"]], [dcTN(userN.uuid)]),
create_element("div", null, [
create_element("div", [], [
dcTN("Provider: "),
create_element("span", null, [dcTN(userN.provider)]),
create_element("span", [], [dcTN(userN.provider)]),
]),
create_element("hr"),
create_element("div", null, [dcTN("Roles")]),
create_element("div", [], [dcTN("Roles")]),
create_element("ol"),
]));
for (const item of api.C.roles.values()) {
Expand Down

0 comments on commit 9664594

Please sign in to comment.