Blog Customizations, Part 2



As mentioned earlier, I wanted to persist your preferences for whether certain collapsible panels were in the collapsed or expanded state. With a simple ECMA-compliant wrapper class around document.cookie and a few minor changes to the CollapsiblePanel class, state for unique panels can be remembered. The cookie wrapper class is pretty straight forward:

To initialize the CollapsiblePanel, an init() function is defined for the class that does pretty much the oppose of the toggle() function. init() is also defined to read from the cookie while toggle() is changed to write the cookie:

All bold lines above show the changes to the CollapsiblePanel class.

Now when you expand or collapse a panel, its sibling’s display state is persisted and used to initial the class when the page is refreshed or you navigate to another page under the given path for the cookie, which can be easily changed to suit your needs.

Heath Stewart

Senior Software Engineer

Follow Heath   


    Leave a comment