collapsible.js: Store and load states form localStorage

This commit is contained in:
Johannes Meyer 2019-06-06 15:53:20 +02:00
parent 3122af2838
commit ba44240b68
1 changed files with 23 additions and 1 deletions

View File

@ -18,9 +18,10 @@
this.on('click', '.collapsible + .collapsible-control', this.onControlClicked, this);
this.icinga = icinga;
this.collapsibleStates = {};
this.defaultNumOfRows = 2;
this.defaultHeight = 36;
this.collapsibleStates = this.getStateFromStorage();
};
Collapsible.prototype = new Icinga.EventListener();
@ -144,6 +145,27 @@
$collapsible.css({display: '', height: ''});
};
/**
* Load the collapsible states from storage
*
* @returns {{}}
*/
Collapsible.prototype.getStateFromStorage = function () {
var state = localStorage.getItem('collapsible.state');
if (!! state) {
return JSON.parse(state);
}
return {};
};
/**
* Save the collapsible states to storage
*/
Collapsible.prototype.destroy = function () {
localStorage.setItem('collapsible.state', JSON.stringify(this.collapsibleStates));
};
Icinga.Behaviors.Collapsible = Collapsible;
})(Icinga, jQuery);