I am trying to remember open accordions in a custom plugin. The first accordion is open by default, so:
var active = [0];
I click on accordions and then read from localStorage
to get the values. Inside my click event:
var active = JSON.parse(localStorage.getItem(outerName)),
tab = $(this).find('h3').index(ui.tab[0]);
if (tab in active) {
delete active[tab];
} else {
active[tab] = tab;
}
for (var i = 0; i < this.length; i++) {
if (active[i] == null) {
active.splice(i, 1);
i--;
}
}
localStorage.setItem(outerName, JSON.stringify(active));
This works, except where I remove the first accordion and then click the second and I'll get duplicated values [1,1]
. I have already removed the null values each time so this is the cause but I don't know how to get the values properly so that if I toggle an accordion it will get removed from the object.
[0,3]
= Accordion 1 and 4 is open
[0,1]
= Accordion 1 and 2 is open