js fixes courtesy drzed

This commit is contained in:
zzz
2025-04-09 11:48:24 -04:00
parent a4c8a0d183
commit f819590f3c

View File

@@ -1,40 +1,51 @@
var expandConfig = null; let config;
var collapseConfig = null; let debug = false;
var config = null;
function initToggleConfig() function initToggleConfig() {
{ const configurationElement = document.getElementById("configuration");
expandConfig = document.getElementById("expandConfig"); if (configurationElement) {
collapseConfig = document.getElementById("collapseConfig"); config = configurationElement;
config = document.getElementById("configuration");
hideConfig(); hideConfig();
} else if (debug) {
console.error("Configuration element not found.");
}
} }
function hideConfig() { function hideConfig() {
if (!collapseConfig) if (config) {
config.style.display = "none"; config.style.display = "none";
} else if (debug && !document.querySelector("#expandConfig")) {
console.error("ExpandConfig link element not found.");
}
} }
function showConfig() { function showConfig() {
if (collapseConfig) if (document.querySelector("#collapseConfig")) {
config.style.display = "block"; config.style.display = "block";
} else if (debug) {
console.error("CollapseConfig link element not found.");
}
} }
function clean() { function clean() {
if (expandConfig) { const expandConfigElement = document.getElementById("expandConfig");
expandConfig.remove(); const collapseConfigElement = document.getElementById("collapseConfig");
if (expandConfigElement) {
expandConfigElement.remove();
} }
if (collapseConfig) {
collapseConfig.remove(); if (collapseConfigElement) {
collapseConfigElement.remove();
} }
} }
function expand() { function expand() {
clean(); clean();
var x = document.createElement("link"); const x = document.createElement("link");
x.type="text/css"; x.type = "text/css";
x.rel="stylesheet"; x.rel = "stylesheet";
x.href="/prometheus/resources/expand.css"; x.href = "/prometheus/resources/expand.css";
x.setAttribute("id", "expandConfig"); x.setAttribute("id", "expandConfig");
document.head.appendChild(x); document.head.appendChild(x);
showConfig(); showConfig();
@@ -42,19 +53,22 @@ function expand() {
function collapse() { function collapse() {
clean(); clean();
var c = document.createElement("link"); const c = document.createElement("link");
c.type="text/css"; c.type = "text/css";
c.rel="stylesheet"; c.rel = "stylesheet";
c.href="/prometheus/resources/collapse.css"; c.href = "/prometheus/resources/collapse.css";
c.setAttribute("id", "collapseConfig"); c.setAttribute("id", "collapseConfig");
document.head.appendChild(c); document.head.appendChild(c);
hideConfig(); hideConfig();
} }
function copyText() { function copyText() {
document.execCommand("copy"); navigator.clipboard.writeText("Some text to copy").then(
() => console.log('Copy successful'),
err => console.error('Copy failed: ', err)
);
} }
document.addEventListener("DOMContentLoaded", function() { document.addEventListener("DOMContentLoaded", function () {
initToggleConfig(); initToggleConfig();
}, true); }, true);