mirror of
https://github.com/unraid/webgui.git
synced 2026-01-06 01:29:54 -06:00
fix: update cookie handling in tab management
- Removed unused cookie helper functions from MainContentTabbed.php to streamline the code. - Updated the tab management logic to ensure cookies are cleared when no cookie exists, aligning with the behavior of the initab function. - Corrected the filename reference in MainContent.php from 'MainContentNotab.php' to 'MainContentNoTab.php' for consistency.
This commit is contained in:
@@ -101,28 +101,12 @@ function refresh(top) {
|
||||
}
|
||||
}
|
||||
|
||||
function initab(page) {
|
||||
function initab(page) { // @todo remove in the future
|
||||
$.removeCookie('one');
|
||||
$.removeCookie('tab');
|
||||
if (page != null) location.replace(page);
|
||||
}
|
||||
|
||||
function settab(tab) {
|
||||
<?switch ($myPage['name']):?>
|
||||
<?case'Main':?>
|
||||
$.cookie('tab',tab);
|
||||
<?if (_var($var,'fsState')=='Started'):?>
|
||||
$.cookie('one','tab1');
|
||||
<?endif;?>
|
||||
<?break;?>
|
||||
<?case'Cache':case'Data':case'Device':case'Flash':case'Parity':?>
|
||||
$.cookie('one',tab);
|
||||
<?break;?>
|
||||
<?default:?>
|
||||
$.cookie('one',tab);
|
||||
<?endswitch;?>
|
||||
}
|
||||
|
||||
function done(key) {
|
||||
var url = location.pathname.split('/');
|
||||
var path = '/'+url[1];
|
||||
|
||||
@@ -10,7 +10,7 @@ $display['tabs'] = isset($myPage['Tabs'])
|
||||
? (strtolower($myPage['Tabs']) == 'true' ? 0 : 1)
|
||||
: $display['tabs'];
|
||||
$tabbed = $display['tabs'] == 0 && count($pages) > 1;
|
||||
$contentInclude = $tabbed ? 'MainContentTabbed.php' : 'MainContentNotab.php';
|
||||
$contentInclude = $tabbed ? 'MainContentTabbed.php' : 'MainContentNoTab.php';
|
||||
|
||||
$defaultIcon = "<i class=\"icon-app PanelIcon\"></i>";
|
||||
function process_icon($icon, $docroot, $root) {
|
||||
|
||||
@@ -53,15 +53,6 @@
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Cookie helpers
|
||||
function getCookie(name) {
|
||||
const v = document.cookie.match('(^|;) ?' + name + '=([^;]*)(;|$)');
|
||||
return v ? v[2] : null;
|
||||
}
|
||||
function setCookie(name, value) {
|
||||
document.cookie = name + '=' + value + '; path=/';
|
||||
}
|
||||
|
||||
const tabs = document.querySelectorAll('.tabs [role="tab"]');
|
||||
const panels = document.querySelectorAll('[role="tabpanel"]');
|
||||
|
||||
@@ -91,11 +82,16 @@ switch ($myPage['name']) {
|
||||
|
||||
// On load: select correct tab from cookie, or default to first
|
||||
let activeIdx = 0;
|
||||
const cookieVal = getCookie(cookieName);
|
||||
const cookieVal = $.cookie(cookieName);
|
||||
if (cookieVal) {
|
||||
const idx = Array.from(tabs).findIndex(tab => tab.id === cookieVal);
|
||||
if (idx !== -1) activeIdx = idx;
|
||||
} else {
|
||||
// If no cookie exists, clear both cookies to match the origial initab function behavior
|
||||
$.removeCookie('one');
|
||||
$.removeCookie('tab');
|
||||
}
|
||||
|
||||
tabs.forEach((tab, i) => {
|
||||
if (i === activeIdx) {
|
||||
tab.setAttribute('aria-selected', 'true');
|
||||
@@ -111,6 +107,7 @@ tabs.forEach((tab, i) => {
|
||||
// On tab click: update cookie and show correct panel
|
||||
// Also update ARIA
|
||||
// No content flash
|
||||
|
||||
tabs.forEach((tab, i) => {
|
||||
tab.addEventListener('click', () => {
|
||||
tabs.forEach((t, j) => {
|
||||
@@ -118,7 +115,7 @@ tabs.forEach((tab, i) => {
|
||||
t.setAttribute('tabindex', j === i ? '0' : '-1');
|
||||
panels[j].style.display = j === i ? 'block' : 'none';
|
||||
});
|
||||
setCookie(cookieName, tab.id);
|
||||
$.cookie(cookieName, tab.id);
|
||||
tab.focus();
|
||||
});
|
||||
tab.addEventListener('keydown', e => {
|
||||
|
||||
Reference in New Issue
Block a user