I've made my own solution which works great for me and does exactly what you want:
First off, I instantiate my accordion just like it is done in examples:
$("#accordion").tabs("#accordion div.pane",
{
tabs: 'h2', effect: 'slide', initialIndex: null
}
);
Than I want my currently active header to close the accordion, so I made this adding two additional classes and standard JQuery functions slideUp() and slideDown()
$("#accordion h2.current").click(function ()
{
if($(this).attr("class") != "opened current")
{
$(this).addClass("opened");
if($(this).hasClass("closed"))
{
$(this).removeClass("closed opened current") ;
$(this).addClass("opened current");
var api = $("#accordion").data("tabs");
api.getCurrentPane().slideDown();
}
}
else
{
var api = $("#accordion").data("tabs");
api.getCurrentTab().removeClass("current");
if(api.getCurrentTab().hasClass("opened")) api.getCurrentTab().removeClass("opened") ;
$(this).addClass("closed");
api.getCurrentPane().slideUp();
}
});
I'm not sure that this is the easiest way to accomplish the goal, but I'm very newbie in jQuery and JS and did my best. Maybe someone will clean up my code a bit.
Of course don't forget about selectors which may be different from mine. My accordion HTML layout looks like this
<div id="accordion">
<h2>Header 1</h2>
<div class="pane">
Content 1
</div>
<h2>Header 2</h2>
<div class="pane">
Content 2
</div>
...
</div>
Sorry for my poor English.