Want to know how the pretty collapsible effect is done on my sidebar widgets? It’s pretty simple, generic, and entirely jQuery.
This is the most simple plugin I have ever written, and it does all that you see in my sidebar with the jQuery library that comes pre-installed with WordPress. It also comes with two jQuery plugins for parsing JSON and dealing with cookies.
This plugin can of course can be extended to be so much better, but this is the basics. In order for it to work, your WordPress theme must use the CSS class “.widget” for this plugin to identify them. Like I said, there’s much that can be done. So if you want to make this thing better, I encourage it, and would love to see it if you do. I’d just like to think I laid the groundwork…
Collapsible Widgets Plugin
Be kind, don’t do anything your mom wouldn’t do.
A little note on jQuery and the slideToggle method I am using to slide the content of the widgets. jQuery has a problem with reading the correct height on an element containing wrapped text, using padding, or using margins. It still does the slideToggle, but you will see a jump in the animation. The amount of jump depends on the amount of those things in use or happening inside the element being toggled.
As a workaround, I suggest this:
Don’t use margins or padding directly on the element being toggled. Instead create an inner element and apply your margins or padding to that, also within this inner element, don’t worry about text wrapping either. Now with this inner element in place, put another element like a div or whatever also within the element being toggled below the inner element. Give this new element a style of “clear: both” pushing it to the bottom below the inner element, and making sure that the parent element”s height is correct for jQuery.
This can all be done within WordPress’ register_sidebar
function, with the “before” and “after” arguments.
I may do more with this plugin myself, but it’s not in the cards for now.
Toodles.
Leave a Reply