From 2bd7f884e5ee5bd5b1549e54dc052d1eb00437cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Gro=C3=9Fe?= Date: Wed, 12 Apr 2017 17:13:56 +0200 Subject: [PATCH] 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 --- js/sidebar.js | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/js/sidebar.js b/js/sidebar.js index 66f1015..56bd928 100644 --- a/js/sidebar.js +++ b/js/sidebar.js @@ -11,6 +11,20 @@ jQuery(function () { var setWideContent = function () { $nav.find('div.nav-panel').hide(); // close all panels 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); } }); + sessionStorage.setItem('sidebar-section-' + $toggler.data('index') + '-open', !isOpen); }, /** @@ -57,9 +72,13 @@ jQuery(function () { var $main = $nav.find('nav.nav-main'); if (!$main.length) return; + if(jQuery('body').hasClass('wide-content')) { + removeToggleStorage(); + } + var ELEMENT = JSINFO.template.sprintdoc.sidebar_toggle_elements; var $elements = $main.find(ELEMENT); - $elements.each(function () { + $elements.each(function (index) { var $me = jQuery(this), // prepare text and the optional icon @@ -83,6 +102,7 @@ jQuery(function () { .text(text) .wrapInner('') .prepend($icon) + .data('index', index) ; // wrap all following siblings til the next element in a wrapper @@ -102,6 +122,11 @@ jQuery(function () { if ($toggler.parent('li').length) { $toggler.parent('li').addClass('toggler'); } + + if (sessionStorage.getItem('sidebar-section-' + index + '-open') === 'true') { + $wrap.css('display', 'block'); + } + }); },