Changed the tab IDs to a sanitized version of the tab labels

This commit is contained in:
mathis_s committed 2026-09-02 11:20:05 +02:00
1 parent 44be087e99
commit c4d2e3498a
1 file changed
+51 -20
+51 -20
View File
@@ -218,41 +218,72 @@ function fillODBs() {
// This function fills the tabs according to the init file
// The tabs should be defined in instrTabs ([INSTR]init.js)
function fillTabs() {
// create two containers
// Convert the tab label into a suitable HTML ID
function makeTabId(label) {
return label.replace(/[^a-zA-Z0-9_-]/g, "");
}
// Create two containers
let tabBtns = document.getElementById("tabBtns");
let tabMenu = document.getElementById("tabMenu");
let tabFrames = document.getElementById("tabFrames");
let beforeMenu = document.getElementById("beforeMenu");
let HIPA = document.getElementById("100");
// tab counter
let iTab=0;
// Tab counter
let iTab = 0;
for (let key in instrTabs) {
iTab++;
iTab++;
// Create tab content container
let d = document.createElement("div");
d.id = "Tab" + iTab;
d.className = "tabcontent";
let f = "<iframe src='/tabs/" + instrTabs[key].htmlFile + "'style='height:500px;width:100%;' onload='this.before((this.contentDocument.body||this.contentDocument).children[0]);this.remove();'></iframe>";
d.innerHTML= f;
let f =
"<iframe src='/tabs/" + instrTabs[key].htmlFile +
"' style='height:500px;width:100%;' " +
"onload='this.before((this.contentDocument.body||this.contentDocument).children[0]);this.remove();'></iframe>";
d.innerHTML = f;
// Create tab button
let b = document.createElement("button");
if (instrTabs[key].style == "Menu") {
b = document.createElement("a");
}
b.id = iTab;
b.className = "w3-bar-item w3-button w3-round";
b.setAttribute("onclick","openTab(event,this.id);" + instrTabs[key].addFunc);
b.innerHTML = "<b>" + instrTabs[key].label + "</b>";
//b.onload = "openTab(event,this.id);" + instrTabs[key].addFunc;
// Append elements
if (instrTabs[key].style == "Tab") {
tabBtns.insertBefore(b,beforeMenu);
} else {
tabMenu.insertBefore(b,HIPA);
}
tabFrames.appendChild(d);
}
// Use a readable ID based on the label
b.id = makeTabId(instrTabs[key].label);
// Keep the original numeric tab number for openTab()
b.dataset.tab = iTab;
b.className = "w3-bar-item w3-button w3-round";
b.setAttribute(
"onclick",
"openTab(event,this.dataset.tab);" + instrTabs[key].addFunc
);
b.innerHTML = "<b>" + instrTabs[key].label + "</b>";
// Append elements
if (instrTabs[key].style == "Tab") {
tabBtns.insertBefore(b, beforeMenu);
} else {
tabMenu.insertBefore(b, HIPA);
}
tabFrames.appendChild(d);
}
}
// This function checks for triggered alarms and add them to Mudas
function triggerAlarms() {
mjsonrpc_db_get_values(["/Alarms"]).then(function(rpc) {