N°3564 Alert and CollapsibleSectionState can now be saved

This commit is contained in:
Pierre Goiffon
2020-12-24 11:36:51 +01:00
parent d3efd3ea0e
commit 2c0d001721
7 changed files with 128 additions and 5 deletions

View File

@@ -24,7 +24,10 @@ $(function () {
{
// default options
options:
{},
{
hasCollapsibleStateSavingEnabled: false,
collapsibleStateStorageKey: null,
},
css_classes:
{
opened: 'ibo-is-opened',
@@ -51,6 +54,26 @@ $(function () {
},
_onCollapseTogglerClick: function (oEvent) {
this.element.toggleClass(this.css_classes.opened);
if (this.options.hasCollapsibleStateSavingEnabled) {
localStorage.setItem(
this.options.collapsibleStateStorageKey,
this.element.hasClass(this.css_classes.opened)
);
}
},
enableSaveCollapsibleState: function (bOpenedByDefault, sSectionStateStorageKey) {
this.options.hasCollapsibleStateSavingEnabled = true;
this.options.collapsibleStateStorageKey = sSectionStateStorageKey;
let bStoredSectionState = JSON.parse(localStorage.getItem(sSectionStateStorageKey));
let bIsSectionOpenedInitially = (bStoredSectionState == null) ? bOpenedByDefault : bStoredSectionState;
if (bIsSectionOpenedInitially) {
this.element.addClass(this.css_classes.opened);
} else {
this.element.removeClass(this.css_classes.opened);
}
}
})
});