You could take it a step further and encode that binary (string of 1s and
0s) as a decimal, and store that. Cool.

function b2d(b) {
  return parseInt(b, 2);
}

function d2b(d) {
  return d.toString(2);
}

- Richard

On Jan 29, 2008 6:49 PM, Jörn Zaefferer <[EMAIL PROTECTED]> wrote:

>
> 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
>

Reply via email to