Remember sidebar section state when browsing the wiki

So we do not have to open the same section of the sidebar every time, we click
 a link to a new page.
It forgets the toggle-state if the content is manually or automatically
widened, for example by clicking on an edit-button.

SPR-883
This commit is contained in:
Michael Große 2017-04-12 17:13:56 +02:00
commit 2bd7f884e5
No known key found for this signature in database
GPG key ID: 7E31028FBFEACC79

View file

@ -11,6 +11,20 @@ jQuery(function () {
var setWideContent = function () { var setWideContent = function () {
$nav.find('div.nav-panel').hide(); // close all panels $nav.find('div.nav-panel').hide(); // close all panels
jQuery('body').addClass('wide-content'); jQuery('body').addClass('wide-content');
removeToggleStorage();
},
/**
* removes information about the toggle-state
*/
removeToggleStorage = function () {
for (var index=0; index <= sessionStorage.length; index += 1) {
var item = sessionStorage.getItem('sidebar-section-' + index + '-open');
if (!item) {
break;
}
sessionStorage.removeItem('sidebar-section-' + index + '-open');
}
}, },
/** /**
@ -46,6 +60,7 @@ jQuery(function () {
focusFirstSubLink($panel); focusFirstSubLink($panel);
} }
}); });
sessionStorage.setItem('sidebar-section-' + $toggler.data('index') + '-open', !isOpen);
}, },
/** /**
@ -57,9 +72,13 @@ jQuery(function () {
var $main = $nav.find('nav.nav-main'); var $main = $nav.find('nav.nav-main');
if (!$main.length) return; if (!$main.length) return;
if(jQuery('body').hasClass('wide-content')) {
removeToggleStorage();
}
var ELEMENT = JSINFO.template.sprintdoc.sidebar_toggle_elements; var ELEMENT = JSINFO.template.sprintdoc.sidebar_toggle_elements;
var $elements = $main.find(ELEMENT); var $elements = $main.find(ELEMENT);
$elements.each(function () { $elements.each(function (index) {
var $me = jQuery(this), var $me = jQuery(this),
// prepare text and the optional icon // prepare text and the optional icon
@ -83,6 +102,7 @@ jQuery(function () {
.text(text) .text(text)
.wrapInner('<span class="lbl">') .wrapInner('<span class="lbl">')
.prepend($icon) .prepend($icon)
.data('index', index)
; ;
// wrap all following siblings til the next element in a wrapper // wrap all following siblings til the next element in a wrapper
@ -102,6 +122,11 @@ jQuery(function () {
if ($toggler.parent('li').length) { if ($toggler.parent('li').length) {
$toggler.parent('li').addClass('toggler'); $toggler.parent('li').addClass('toggler');
} }
if (sessionStorage.getItem('sidebar-section-' + index + '-open') === 'true') {
$wrap.css('display', 'block');
}
}); });
}, },