views:

438

answers:

3

We are using a jquery accordion on our site : http://www.racedayworld.com

It basically lists events under each month...

Apparently people are finding difficulties knowing how it really works and they don't see at first glance that there are more events under each month (that you click to expand)

So I was thinking about opening two at a time (the current month and the next) .. but I'm not sure how to enable both to be open at once ... any ideas?

This is how the accordion panes are getting intialized:

$(function() { 
$("#accordion").tabs("#accordion div.pane", {tabs: 'h2', effect: 'slide', initialIndex: 0});
}); 
A: 

If you just want to show the second div in the accordion you can show it after applying the accordion component.

$("#myAccordion").accordion();
$("#secondDivInTheAccordion").show();

This will show the first and second tabs open, until the user clicks one of the tabs. Then it will function as it normally would.

DangerMouse
How is that going to work if the panes are both <h2>?This is how they get initialized$(function() { $("#accordion").tabs("#accordion div.pane", {tabs: 'h2', effect: 'slide', initialIndex: 0});});
Kevin
The accordion component turns the h2 tags into the things you click and the div tags into the things that show and hide. So you want to target the second div inside the accordion div and show it. Something like $("#accordion").children("div").eq(1).show(); might work. You are using the jquery UI accordion component right? The code in the above comment looks like its using the tabs component.
DangerMouse
A: 

Or you can try this also:

$("div#accordion div.pane").last().css("display", "block");

Same as DangerMouse's answer, just add it after you accordion call, and it would open both tabs at the same time, assuming that you would display only the current and last month in the home page.

Hope it helps.

jnkrois
check out the latest edit I put in - it talks about how the accordions are being intialized
Kevin
Based on the way the accordion is initialized when the page loads, the first tab (a div with a class of "pane") is set to display "block", right after the accordion is initialized you can specify with my suggestion that the second tab (which is currently set to display "none") is shown by changing the display value.
jnkrois
A: 

Try changing your function to this:

$(function() {
 $("#accordion").tabs("#accordion div.pane", {tabs: 'h2', effect: 'slide', initialIndex: 0});

 $("#accordion h2").click(function(){
  index =  $("h2").index($(this)) + 1;
  // open next tab pane
  $("#accordion .pane:eq(" + index + ")").slideDown(500);
 })
 // open 2nd pane initially
 $("#accordion .pane:eq(1)").slideDown(500);
});

Update: If you only want to open two panes initially, then remove the click function in the middle, so you'll end up with this:

$(function() {
 $("#accordion").tabs("#accordion div.pane", {tabs: 'h2', effect: 'slide', initialIndex: 0});
 // open 2nd pane initially
 $("#accordion .pane:eq(1)").slideDown(500);
});

Edit: if the second pane doesn't appear to open up it may be because the tab script is still setting up, so if you need to, replace the second line with this:

 setTimeout ( function(){ $("#accordion .pane:eq(1)").slideDown(500); }, 500 );
fudgey
That works pretty good - but how about initially opening 2, then reverting back to the way it's supposed to work (opening 1 at a time)
Kevin
I've updated my code... you might have to put the second line inside a setTimeout because initially when I tried it, the tab panes weren't set up and code didn't appear to work.
fudgey
In a practical setting, the pane contents should have enough content in them to allow the rest to load, so I think that will work..I dunno, the whole thing is kind of annoying as I don't want to change the initial function of the accordion .. I mean if you don't know that you can click on the header to expand, then we open two at once, then how does a user even know that another one can be opened?
Kevin
Maybe change the + sign on the right to some text like "click to expand" or "see this month"
fudgey
You're probably right, I think that's the right step .... but I do like the 2 months at a time for now as well... thanks for the code help
Kevin