Separate states of different sidebars

This commit is contained in:
Anna Dabrowska 2019-05-13 18:19:31 +02:00
commit e78ffc6c79
2 changed files with 16 additions and 8 deletions

View file

@ -115,10 +115,11 @@ class Template {
global $ID;
global $conf;
// id of the current sidebar, each sidebar must have its own state
$header = sprintf('<div id="sidebarId" class="%s"></div>', page_findnearest($conf['sidebar']));
// add tabs if multiple navigation types available
$header = '';
if ($this->plugins['sitemapnavi'] !== null) {
$header = '<ul class="sidebar-tabs">';
$header .= '<ul class="sidebar-tabs">';
$header .= '<li class="' . ($this->nav === 'sidebar' ? 'active' : '') . '">' .
'<a href="' . wl($ID, ['nav' => 'sidebar']) . '">'.tpl_getLang('nav_sidebar').'</a></li>';
$header .= '<li class="' . ($this->nav === 'sitemap' ? 'active' : '') . '">' .

View file

@ -9,6 +9,13 @@ jQuery(function () {
var $nav = jQuery('#dokuwiki__aside');
if (!$nav.length) return;
// id of the current sidebar, used to differentiate states
var sidebarId = '';
var divId = jQuery('#sidebarId');
if (typeof divId !== 'undefined') {
sidebarId = divId.attr('class').split(' ')[0];
}
/**
* closes sidebar
*/
@ -24,11 +31,11 @@ jQuery(function () {
*/
removeToggleStorage = function () {
for (var index=0; index <= window.sessionStorage.length; index += 1) {
var item = window.sessionStorage.getItem('sidebar-section-' + index + '-open');
var item = window.sessionStorage.getItem('sidebar-section-' + sidebarId + '-' + index + '-open');
if (!item) {
continue;
}
window.sessionStorage.setItem('sidebar-section-' + index + '-open', 'false');
window.sessionStorage.setItem('sidebar-section-' + sidebarId + '-' + index + '-open', 'false');
}
},
@ -72,7 +79,7 @@ jQuery(function () {
$toggler.removeClass('is-open');
}
});
window.sessionStorage.setItem('sidebar-section-' + $toggler.data('index') + '-open', !isOpen);
window.sessionStorage.setItem('sidebar-section-' + sidebarId + '-' + $toggler.data('index') + '-open', !isOpen);
},
/**
@ -138,7 +145,7 @@ jQuery(function () {
$toggler.parent('li').addClass('toggler');
}
if (window.sessionStorage.getItem('sidebar-section-' + index + '-open') === 'true') {
if (window.sessionStorage.getItem('sidebar-section-' + sidebarId + '-' + index + '-open') === 'true') {
$wrap.css('display', 'block');
setTogglerClass($toggler,'is-open');
}
@ -288,10 +295,10 @@ jQuery(function () {
tIndex = y + index;
$toggler.data('index', tIndex);
var item = window.sessionStorage.getItem('sidebar-section-' + tIndex + '-open');
var item = window.sessionStorage.getItem('sidebar-section-' + sidebarId + '-' + tIndex + '-open');
if (item) {
if(isWideContent) {
window.sessionStorage.setItem('sidebar-section-' + tIndex + '-open', 'false');
window.sessionStorage.setItem('sidebar-section-' + sidebarId + '-' + tIndex + '-open', 'false');
} else {
if (item === 'true') {
jQuery(this).find('.nav-panel').css('display', 'block');