2020-12-29 18:42:26 +00:00
|
|
|
export class Tabs implements Tabs {
|
|
|
|
tabs: Array<Tab>;
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
this.tabs = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
addTab = (tabID: string, preFunc = () => void {}, postFunc = () => void {}) => {
|
|
|
|
let tab = {} as Tab;
|
|
|
|
tab.tabID = tabID;
|
|
|
|
tab.tabEl = document.getElementById(tabID) as HTMLDivElement;
|
|
|
|
tab.buttonEl = document.getElementById(tabID + "-button") as HTMLSpanElement;
|
|
|
|
tab.buttonEl.onclick = () => { this.switch(tabID); };
|
|
|
|
tab.preFunc = preFunc;
|
|
|
|
tab.postFunc = postFunc;
|
|
|
|
this.tabs.push(tab);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch = (tabID: string) => {
|
|
|
|
for (let t of this.tabs) {
|
|
|
|
if (t.tabID == tabID) {
|
|
|
|
t.buttonEl.classList.add("active", "~urge");
|
2021-01-01 23:31:32 +00:00
|
|
|
if (t.preFunc) { t.preFunc(); }
|
2020-12-29 18:42:26 +00:00
|
|
|
t.tabEl.classList.remove("unfocused");
|
2021-01-01 23:31:32 +00:00
|
|
|
if (t.postFunc) { t.postFunc(); }
|
2020-12-29 18:42:26 +00:00
|
|
|
} else {
|
|
|
|
t.buttonEl.classList.remove("active");
|
|
|
|
t.buttonEl.classList.remove("~urge");
|
|
|
|
t.tabEl.classList.add("unfocused");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|