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

@@ -778,50 +778,14 @@ function scrollDown() {
// General initialization
// --------------------------------------------------------
function initializeTabs() {
setTimeout(() => {
const key = "activeMaintenanceTab";
// default selection
let selectedTab = "tab_DBTools_id";
// the #target from the URL
let target = window.location.hash.substr(1);
console.log(selectedTab);
// get only the part between #...?
if (target.includes('?')) {
target = target.split('?')[0];
}
// update cookie if target specified
if (target) {
selectedTab = target.endsWith("_id") ? target : `${target}_id`;
setCache(key, selectedTab); // _id is added so it doesn't conflict with AdminLTE tab behavior
}
// get the tab id from the cookie (already overridden by the target)
const cachedTab = getCache(key);
if (cachedTab && !emptyArr.includes(cachedTab)) {
selectedTab = cachedTab;
}
// Activate panel
$('.nav-tabs a[id='+ selectedTab +']').tab('show');
// When changed save new current tab
$('a[data-toggle="tab"]').on('shown.bs.tab', (e) => {
const newTabId = $(e.target).attr('id');
setCache(key, newTabId);
});
// events on tab change
$('a[data-toggle="tab"]').on('shown.bs.tab', (e) => {
const newTarget = $(e.target).attr("href"); // activated tab
});
hideSpinner();
}, 50);
initializeTabsShared({
cacheKey: 'activeMaintenanceTab',
defaultTab: 'tab_DBTools_id',
useHash: true,
idSuffix: '_id',
delay: 50
});
setTimeout(() => hideSpinner(), 50);
}
//------------------------------------------------------------------------------