mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
N°3617 collapsible components state saving : use JQuery widget options instead of a method
This is the way JQuery widget are intended to work ! Thanks @Molkobain for the review !
This commit is contained in:
@@ -25,8 +25,8 @@ $(function () {
|
||||
// default options
|
||||
options:
|
||||
{
|
||||
hasCollapsibleStateSavingEnabled: false,
|
||||
collapsibleStateStorageKey: null,
|
||||
bOpenedByDefault: true,
|
||||
collapsibleStateStorageKey: null, // if non null will save collapsible state
|
||||
},
|
||||
css_classes:
|
||||
{
|
||||
@@ -40,6 +40,15 @@ $(function () {
|
||||
// the constructor
|
||||
_create: function () {
|
||||
this._bindEvents();
|
||||
|
||||
let bStoredSectionState = JSON.parse(localStorage.getItem(this.options.collapsibleStateStorageKey));
|
||||
let bIsSectionOpenedInitially = (bStoredSectionState == null) ? this.options.bOpenedByDefault : bStoredSectionState;
|
||||
|
||||
if (bIsSectionOpenedInitially) {
|
||||
this.element.addClass(this.css_classes.opened);
|
||||
} else {
|
||||
this.element.removeClass(this.css_classes.opened);
|
||||
}
|
||||
},
|
||||
// events bound via _bind are removed automatically
|
||||
// revert other modifications here
|
||||
@@ -55,25 +64,12 @@ $(function () {
|
||||
_onCollapseTogglerClick: function (oEvent) {
|
||||
this.element.toggleClass(this.css_classes.opened);
|
||||
|
||||
if (this.options.hasCollapsibleStateSavingEnabled) {
|
||||
if (this.options.collapsibleStateStorageKey) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user