From dd4cfaba504123a0e144217989c296470d3b9295 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 18 Jul 2019 09:43:22 +0200 Subject: [PATCH] navigation.js: Store and load sidebar collapse state from localStorage resolves #3628 --- public/js/icinga/behavior/navigation.js | 29 ++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/public/js/icinga/behavior/navigation.js b/public/js/icinga/behavior/navigation.js index dbdbe16b1..d3d1dfe06 100644 --- a/public/js/icinga/behavior/navigation.js +++ b/public/js/icinga/behavior/navigation.js @@ -30,6 +30,30 @@ * @type {jQuery} */ this.$menu = null; + + /** + * Local storage + * + * @type {Icinga.Storage} + */ + this.storage = Icinga.Storage.BehaviorStorage('navigation'); + + // Restore collapsed sidebar if necessary + if (this.storage.get('sidebar-collapsed')) { + $('#layout').addClass('sidebar-collapsed'); + } + + // Ensure we'll get notified if the sidebar is toggled in another window + this.storage.onChange('sidebar-collapsed', function (collapsed) { + // Not using toggleClass here to avoid inconsistencies + if (collapsed) { + $('#layout').addClass('sidebar-collapsed'); + } else { + $('#layout').removeClass('sidebar-collapsed'); + } + + $(window).trigger('resize'); + }, this); }; Navigation.prototype = new Icinga.EventListener(); @@ -333,7 +357,10 @@ * @param {Object} e Event */ Navigation.prototype.toggleSidebar = function(e) { - $('#layout').toggleClass('sidebar-collapsed'); + var _this = e.data.self; + var $layout = $('#layout'); + $layout.toggleClass('sidebar-collapsed'); + _this.storage.set('sidebar-collapsed', $layout.is('.sidebar-collapsed')); $(window).trigger('resize'); };