refactor
This commit is contained in:
parent
0a6148c73f
commit
e8f1d1db1e
60 changed files with 2417 additions and 612 deletions
33
js/ui_helpers.js
Normal file
33
js/ui_helpers.js
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
"use strict";
|
||||
|
||||
(function (global) {
|
||||
function htmlEscape(value = "") {
|
||||
return String(value ?? "").replace(/[&<>"']/g, ch => ({ "&": "&", "<": "<", ">": ">", "\"": """, "'": "'" }[ch] || ch));
|
||||
}
|
||||
|
||||
function ensureStyle(id, cssText = "") {
|
||||
if (!id) return null;
|
||||
let style = document.getElementById(id);
|
||||
if (style) return style;
|
||||
style = document.createElement("style");
|
||||
style.id = id;
|
||||
style.textContent = cssText;
|
||||
document.head.appendChild(style);
|
||||
return style;
|
||||
}
|
||||
|
||||
function createPanel({ id, className = "", html = "", after = null, parent = document.body } = {}) {
|
||||
if (!id) return null;
|
||||
let panel = document.getElementById(id);
|
||||
if (panel) return panel;
|
||||
panel = document.createElement("section");
|
||||
panel.id = id;
|
||||
if (className) panel.className = className;
|
||||
panel.innerHTML = html;
|
||||
if (after?.parentNode) after.parentNode.insertBefore(panel, after.nextSibling);
|
||||
else parent.appendChild(panel);
|
||||
return panel;
|
||||
}
|
||||
|
||||
global.TarinaiUIHelpers = { htmlEscape, ensureStyle, createPanel };
|
||||
})(typeof window !== "undefined" ? window : globalThis);
|
||||
Loading…
Add table
Add a link
Reference in a new issue