refactor: Consolidate tab initialization logic using shared utility function

This commit is contained in:
Jokob @NetAlertX
2026-02-27 10:07:55 +00:00
parent 9d64665599
commit 4c0d5c7376
5 changed files with 116 additions and 87 deletions

View File

@@ -118,29 +118,10 @@ function loadTabContent(target) {
}
function initializeTabs() {
const key = "activeSysinfoTab";
let selectedTab = "tabServer"; // fallback default
const cached = getCache(key);
if (!emptyArr.includes(cached)) {
selectedTab = cached;
}
// Activate the correct tab
const $tabLink = $('.nav-tabs a[id="' + selectedTab + '"]');
$tabLink.tab('show');
// Get the pane's ID from the tab's href attribute
const targetSelector = $tabLink.attr("href");
loadTabContent(targetSelector);
// On tab change
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
const newTabId = $(e.target).attr('id');
setCache(key, newTabId);
const newTarget = $(e.target).attr("href");
loadTabContent(newTarget);
initializeTabsShared({
cacheKey: 'activeSysinfoTab',
defaultTab: 'tabServer',
onTabChange: loadTabContent
});
}