mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-29 08:44:10 +02:00
navigation.js: Store and load sidebar collapse state from localStorage
resolves #3628
This commit is contained in:
parent
8d09279e15
commit
dd4cfaba50
@ -30,6 +30,30 @@
|
|||||||
* @type {jQuery}
|
* @type {jQuery}
|
||||||
*/
|
*/
|
||||||
this.$menu = null;
|
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();
|
Navigation.prototype = new Icinga.EventListener();
|
||||||
@ -333,7 +357,10 @@
|
|||||||
* @param {Object} e Event
|
* @param {Object} e Event
|
||||||
*/
|
*/
|
||||||
Navigation.prototype.toggleSidebar = function(e) {
|
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');
|
$(window).trigger('resize');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user