Official Documentation for the JQuery Menu API

This document is intended for module developers who wish to make use of JQuery to process an array of hierarchical data into a click and expand menu. It is written with the assumption that you are a programmer and that you know how to create multidimensional arrays through recursive functions.
The only function that third party modules need to call from JQuery menu in order to create a click and expand menu is as follows:

theme(‘menu_creation_by_array’, $menutree, $trail);

This calls the theme function menu_creation_by_array() and sends it two arguments:
$menutree : $menutree is a multidimensional array of containing the information necessary to create links. It is formatted in the same pattern as the tree that you get from calling menu_tree_all_data(). For reference I recommend calling menu_tree_all_data(‘navigation’) and using the var_dump function to look at the structure. I copied and pasted this dump to a text file in order to refer to it as I was writing the JQuery Menu module. JQuery Menu does not need all of the elements provided by the menu_tree_all_data() function. Below is a list of the elements that are used by JQuery Menu:

$item[‘link’][‘href’] : The actual path to be linked to. It is best to use pre-alias paths such as node/1 etc… as the paths will automatically be converted at run time.

$item[‘link’][‘title’] : The text to be displayed in the link.

$item[‘link’][‘has_children’] : set to 1 or 0, this determines if the link will have a clickable plus or minus sign in the case of 1 or a normal list bullet in the case of 0.

$item[‘link’][‘expanded’] : set to 1 or 0, this determines if the link should be expanded by default.

$item[‘link’][‘options’][‘attributes’] : Any attributes such as classes that you want to pass as the $options array to the l() function can be set here. You should read up on the l() function at api.drupal.org for more information http://api.drupal.org/api/function/l/6.

$item[‘link’][‘hidden’] : If you want your item to remain in the tree but not to be displayed you can set hidden to 1 here.

Subsequent levels of the menu are created by generating the same structure from $item[‘below’]. So for a second level menu href it would look as follows: $item[‘below’] [‘link’][‘href’]. The best way to create such an array is to develop the logic in such a way that you can run the function recursively on itself as many times as needed to transverse all levels of the array you are creating. For examples of this you can look at the source code for the Advanced Taxonomy Blocks module.

$trail: The $trail argument for the theme(‘menu_creation_by_array’, $menutree, $trail); function is a simple indexed array of paths that are used to generate the active trail. For a typical menu this array is generated with menu_get_active_trail(). However is some situations as is the case for the Advanced Taxonomy Blocks module the active trail needed is not based on the menu but rather on the taxonomy hierarchy. Your module can implement the active trail based on the current page however it wants. JQuery menu will check the $trail array against all of the links in the hierarch and apply set those elements to be expanded. For an example of a simple trail array… say you are visiting a taxonomy page for term 3 who’s parent is term 2. If term 2 is a top level term then the trail might be as follows:

$trail =  array(
  0=>’taxonomy/term/2′,
  1=>’ taxonomy/term/3′,
);

You can decide how you implement the active trail but the best idea is to have the trail match the hierarchy of the menu so that the menu will open appropriately.