Merge pull request #3833 from Icinga/feature/restore-collapsed-sidebar-on-page-load-3628

navigation.js: Store and load sidebar collapse state from localStorage
This commit is contained in:
Johannes Meyer 2019-07-18 10:00:20 +02:00 committed by GitHub
commit 853864aee1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 28 additions and 1 deletions

View File

@ -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');
};