forked from lin-midas-pages/common_pages
Added tab label so we can search the tab by label
This commit is contained in:
1 parent
c4d2e3498a
commit
07abb9e885
1 file changed
+29
-56
+29
-56
@@ -215,71 +215,44 @@ function fillODBs() {
|
||||
}
|
||||
}
|
||||
|
||||
// This function fills the tabs according to the init file
|
||||
// The tabs should be defined in instrTabs ([INSTR]init.js)
|
||||
// This function fills the tabs according to the init file
|
||||
// The tabs should be defined in instrTabs ([INSTR]init.js)
|
||||
function fillTabs() {
|
||||
|
||||
// Convert the tab label into a suitable HTML ID
|
||||
function makeTabId(label) {
|
||||
return label.replace(/[^a-zA-Z0-9_-]/g, "");
|
||||
}
|
||||
|
||||
// Create two containers
|
||||
// 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++;
|
||||
|
||||
// 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;
|
||||
|
||||
// Create tab button
|
||||
let b = document.createElement("button");
|
||||
|
||||
if (instrTabs[key].style == "Menu") {
|
||||
b = document.createElement("a");
|
||||
}
|
||||
|
||||
// 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);
|
||||
iTab++;
|
||||
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 b = document.createElement("button");
|
||||
if (instrTabs[key].style == "Menu") {
|
||||
b = document.createElement("a");
|
||||
}
|
||||
b.id = iTab;
|
||||
b.dataset.tabLabel = instrTabs[key].label;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user