YUI powered javascript Accordion widget

Sunday Jul 20 2008

First of all, you may wonder what the hell is going on with this blogger's obsession with Accordion widgets, probably because I already wrote about this and then another time with several improvements to what I did in the first article. I'll explain why at the end of this entry. First let's get to the stuff that really matters!

try it out here!

YUI Accordion widget in action

July 30 update: MASSIVE improvements galore! The highlights of this new version are:

  • Added custom events
  • Added more interesting examples
  • Added new methods: AccordionView:openPanel and AccordionView:closePanel to manipulate panels from elsewhere in your code.
  • Added a configurable timeout for hover-activated accordions
  • Various small bugfixes

The demo / download page has been updated.

Many thanks fo out to Satyam, the author of this awesome article on building YUI widgets for all his valuable advice over the past few days. Without his excellent knowledge this widget wouldn't be half as good as it is now. Thanks a lot Satyam!

If you're interested in modifying or creating YUI widgets, his article "Building Your Own Widget Library with YUI" is an absolute MUST read!

Dark Matter Pro: a premium photoblog template.

Affiliate program available

Features of YAHOO.widget.AccordionView

At the moment of writing, my widget has the following features:

  • built as a real YUI widget
  • configurable through a handy dandy configuration object passed to the widget at instantiation
  • completely encapsulated, no 'side effects' on any events within the widget
  • panels can hold anything, it's not just a 'menu system'
  • Ability to add or remove panels on the fly after instantiation
  • Can create itself from scratch based on JS based configuration data
  • single event handler per instance
  • Built from ordinary unordered list markup with extreme freedom in choice of elements to use
  • load of configuration options:
    • configurable item to be opened at initialization
    • configurable animation speed and effect type
    • option to disable animation altogether
    • option to make the menu fully collapsible or force one panel to be open at all times
    • option to make every panel to be expanded individually
    • option to open panels on mouseover
    • parameter configurable width
    • Working in many browsers! Tested in IE6, IE7, Firefox 2, Firefox 3, Safari 3 and Opera 9.5
  • All configuration parameters can be changed at will after instantiation
  • ARIA roles and states for excellent accessibility
  • Skinned in 'Sam' style as a sensible and good looking default
  • Light-weight. All this in well under 7kb when using the YUI Compressor

While I'm thinking of adding a few more features, it's already pretty complete and very usable. As usual, I set up a proper demo page where you can check out various instances of the accordion, learn how to use it and of course download it.

So, why yet another accordion then mate?

I was recently presented with a task that required an accordion view. Also, the preferred thing to use was of course . I looked around for a proper solution but I didn't really find one. Then, on a few hours in the afternoon I wrote some code that pretty much did what I needed. Then however I got the irresistible urge to take this a few steps further. There's an accordion here but it doesn't really have all the features I wanted, and it's not really built like a true widget. Also, it can't be nested which is something people have been asking me about in the comments below my previous accordion efforts. Note that I'm not trying to say it's a bad effort. I just wanted a bit more! While I don't think accordions should be nested from an UI perspective, the request for accordions that can be nested posed a special challenge. For that to work properly I needed to take special care that the widget is 100% autonomous and that events inside any single instance do not have any side effects. this one fails in that department. Additionally I thought it would be very nice to create one styled with YUI's default 'Sam' skin.

And finally, I wrote earlier about YUI being my favourite javascript framework. This of course means I felt like I had to put my money where my mouth is and... use it! The result is a lightweight, pretty looking by default and very flexible widget which I hope will be useful for anyone who wants to use it. In true YUI spirit it's licensed under the liberal BSD license so feel free to use it anywhere!

Even though the widget is in a pretty robust state already, I very much consider it a 'work in progress'. I will update this post when I make changes to the widget and I'll probably add a few more features.

I welcome your feedback and suggestions for improvements!

As mentioned before, but in case you missed it, here is the demo page.

About bug reports (added later)

I just wanted to let you all know that I really appreciate the feedback and useful bug reports I've received so far. It's already resulted in some great improvements and fixes. Please keep them coming so this component will be 'perfect' as soon as possible!

Tags: , ,

bookmarking

Commentary

Join the discussion! Leave a comment through the comment form below!

Got something to add to this?

Feel free to leave a comment on this site. You can use Textile and Emoticons. Your email address is only used to show a gravatar. Please stay on-topic and use common decency. Spammers will be shot in front of a live studio audience.

If you plan on posting code, use pastebin please and post a URL to the code. The comment processing doesn't deal very well with code. Sorry for the inconvenience.

Human comment spammers: don't bother posting your crap here. Comments are moderated and I won't let any of your shit through.

Remember personal info?
Yes
No

Trackbacks

If you have an interesting related post on your own site you can leave a trackback. As they say: 'a little AJAX a day keeps the spammers away' which is why you'll have to click below to generate a trackback key. The key will be valid for 15 minutes and can be used only once.

 

  • Featured Links
RockySomewhere near the Orion NebulaBookalicio.usGolden Gate BridgeThames River BankJackie and mePimpin' it