From aa0771877ff9010a05a642b6b0ce115dfe00ab84 Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Sat, 14 Jul 2018 11:25:19 +0200 Subject: [PATCH] Remember sidebar collapsed state --- public/js/grocy.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/public/js/grocy.js b/public/js/grocy.js index 3bad7f03..d8e3e410 100644 --- a/public/js/grocy.js +++ b/public/js/grocy.js @@ -32,6 +32,32 @@ if (!Grocy.ActiveNav.isEmpty()) } } +var observer = new MutationObserver(function(mutations) +{ + mutations.forEach(function(mutation) + { + if (mutation.attributeName === "class") + { + var attributeValue = $(mutation.target).prop(mutation.attributeName); + if (attributeValue.contains("sidenav-toggled")) + { + window.localStorage.setItem("sidebar_state", "collapsed"); + } + else + { + window.localStorage.setItem("sidebar_state", "expanded"); + } + } + }); +}); +observer.observe(document.body, { + attributes: true +}); +if (window.localStorage.getItem("sidebar_state") === "collapsed") +{ + $("#sidenavToggler").click(); +} + $.timeago.settings.allowFuture = true; RefreshContextualTimeago = function() {