Karl Swedberg schrieb:
Sorry for the repeat posts, but this is the first time I've looked at
this sort of thing. I just realized that we can get up to 100 items by
changing that bigIndex function -- just pad values less than 10 and
append a delimiter to each one: [...]
The serialization I've used for the treeview plugin works a bit
different, but may be applied here, too. The relevant code is this:
function serialize() {
function binary(arg) {
return arg ? 1 : 0;
}
var data = [];
branches.each(function(i, e) {
data[i] = $(e).is(":has(>ul:visible)") ? 1 : 0;
});
$.cookie(settings.cookieId, data.join("") );
}
function deserialize() {
var stored = $.cookie(settings.cookieId);
if ( stored ) {
var data = stored.split("");
branches.each(function(i, e) {
$(e).find(">ul")[ parseInt(data[i]) ? "show" : "hide"
]();
});
}
}
Branches is the jQuery object containing all list items that contain
nested lists in the tree. For each I add 1 or 0 to an array, depending
on the visibility (":visible") of the nested list
(is(":has(>ul:visible)")). That array is joined with no seperator and
stored into the cookie. settings.cookieId is "treeview" by default and
can be customized to enable storage of more then one tree on a single page.
The deserialization works the other way round, splititing the ones/zeros
and showing and hiding the branches accordingly.
This scales pretty well, the size of the tree doesn't matter, and the
cookie is quite small, keeping the bandwith overhead rather low.
Jörn