I used jquery accorion effect on Drupal 6. But if I clicked a sublink of a menu, the page would be reloaded and the visited menu would be closed again. I want to keep the clicked menu openned. How can I realize it?

Any ideas?

Regards

Comments

pflame’s picture

Oh you want to enable the currently active menu block automatically?
You can do this by specifying activate index for accordion blocks widget. The following code might help you.

// Activating the block having index 2 means it is 3rd block
$('.accordion_blocks_container').accordion('activate', 2);

The above code will activate the 3rd block in both left side and right side. Need to find the index of the block which is showing the active menu.

hgltao’s picture

Thank you for your reply. But I am just a new juy on Jquery. I don't know how can I get the index of the block I clicked.
Should I add this code to accordion_init.js in accordion blocks modules or some other places?
Can you give me more tipps?

Best Regars!

hgltao’s picture

Another problem is that I used the code you wrote, but it still didn't work. Because my whole page would be reloaded after I clicked a link. Then the navigation will be rebuilt. The previous status of the navigation would be lost. How can I solve the problem? Should I only use jquery cookie?

2noame’s picture

Thank you! This is exactly what I was looking for.

linneawilliams’s picture

StatusFileSize
new33.45 KB

Hello, I'm having a similar issue.

I'm using accordion blocks on 5 small menus stacked in the same column (photo attached--the titles are block titles). When I click a link in the menu, the page reloads and the first block (chunk of the menu) opens again, even if the link was in subsequent block.

Does the above code only allow you to specify one block as always being open, or can it recognize what page it's currently on?

Help would be much appreciated!

-Linnea

pflame’s picture

Hi linneaann,

The above mentioned code just activates the 3rd block. Accordion blocks module don't know any thing about current menu system. You have to check the current menu and activate the respective block using below code.

$('.accordion_blocks_container').accordion( "activate" , index);

The index is the index of block, it starts with zero.

zorax’s picture

Hello pfame,
I need to use this function too,
You said "You have to check the current menu and activate the respective block using below code."
where is the link between php and java?
Is it possible on a tpl.php file to launch a js function, if yes how to do that?
the function will be :
drupal.behaviors.accordion_blocks = function(){
$('.accordion_blocks_container').accordion('activate', $number);
}
$number will depend of the page visited.
Regards,

pflame’s picture

You can launch js function in the tpl file by just writing script tag like this. But this is not the suggested way, but will work.

<script type="text/javascript">
drupal.behaviors.accordion_blocks = function(){
  $('.accordion_blocks_container').accordion('activate', $number);
}
</script>
zorax’s picture

I try to place you code in page.tpl.php, in block.tpl.php in your module, but it doesn't worked..

But this is not the suggested way

Can you explain what is the suggested way to say to drupal :
on this page : accordion('activate', 2);
on this page : accordion('activate', 3);

Best Regards,

zorax’s picture

Please can you tell us how we can choose to let opened the menu depending of the content type
for example :
content type 1 :
$('.accordion_blocks_container').accordion('activate', 3);
content type 2 :
$('.accordion_blocks_container').accordion('activate', 2);

the function is under the file : accordion_init.js
Where do we need to put the code (page.tpl, node.tpl??), we talked about a function, I imagine we need to launch this function but where and how ?
can you just give an example,
Best Regards,

dargente’s picture

Version: 6.x-1.0-beta1 » 7.x-3.2
Component: User interface » Code

//Activating the block having index 2 means it is 3rd block
$('.accordion_blocks_container').accordion('activate', 2);

where do we put this code?
like to have each main category page with a different accordion open.

Thanks!

pflame’s picture

Assigned: Unassigned » pflame
Category: support » feature

I think, it is better to have this as an option for every accordion block. I will work on this in this week and post the updates.

Salbalea’s picture

Issue summary: View changes

I´m still searching for a solution for this issue.
Do you have some news?

As zorax wrote, an example like this would be great:

content type 1 :
$('.accordion_blocks_container').accordion('activate', 3);
content type 2 :
$('.accordion_blocks_container').accordion('activate', 2);