function accordion_menu_output in Accordion Menu 6
Same name and namespace in other branches
- 7 includes/view.inc \accordion_menu_output()
Returns rendered accordion menu tree.
Parameters
array $tree: An associative array of the menu tree.
string $config: The configuration settings for the menu block.
string $active_menu: The active menu item for the JS settings.
Return value
string An HTML string of the menu tree.
See also
1 call to accordion_menu_output()
- _accordion_menu_block_view in includes/
view.inc - Implements hook_block_view().
File
- includes/
view.inc, line 151 - Provides view routines.
Code
function accordion_menu_output($tree, $config, &$active_menu = '') {
$output = '';
$items = array();
// Pull out just the menu items we are going to render so that we
// get an accurate count for the first/last classes.
foreach ($tree as $data) {
if (!$data['link']['hidden']) {
$items[] = $data;
}
}
$item_count = count($items);
$flip = array(
'even' => 'odd',
'odd' => 'even',
);
$zebra = 'even';
foreach ($items as $i => $data) {
$subtree = _accordion_menu_subtree($data['link']);
$subtree = menu_tree_output($subtree);
// Add CSS classes.
$class = array();
$class[] = 'accordion-header accordion-header-' . ($i + 1);
if ($i == 0) {
$class[] = 'first';
}
if ($i == $item_count - 1) {
$class[] = 'last';
}
if ($subtree) {
$class[] = 'has-children';
}
else {
$class[] = 'no-children';
}
if ($data['link']['in_active_trail']) {
$class[] = 'active-trail';
$data['link']['localized_options']['attributes']['class'] .= ' active-trail';
}
if ($data['link']['href'] == $_GET['q'] || $data['link']['href'] == '<front>' && drupal_is_front_page()) {
$class[] = 'active';
}
$class[] = $zebra = $flip[$zebra];
$class[] = 'menu-mlid-' . $data['link']['mlid'];
$class = implode(' ', $class);
// Allow menu-specific theme overrides.
$hooks = array(
'accordion_menu_header__' . str_replace('-', '_', $config['delta']),
'accordion_menu_header__' . str_replace('-', '_', $config['menu_name']),
'accordion_menu_header',
);
$element['attributes']['class'] = $class;
$element['title'] = $data['link']['title'];
$element['href'] = $data['link']['href'];
$element['localized_options'] = !empty($data['link']['localized_options']) ? $data['link']['localized_options'] : array();
$element['below'] = $subtree;
$element['original_link'] = $data['link'];
$element['bid'] = array(
'module' => 'accordion_menu',
'delta' => $config['delta'],
);
$element['config'] = $config;
$element['count'] = $i + 1;
// Output the header and submenu items.
$output .= theme($hooks, $element);
if ($data['link']['in_active_trail'] == '1') {
$active_menu = $i;
}
}
// Add class to handle flash of unstyled content in IE 7 and 8.
$output = str_replace('ul class="menu"', 'ul class="menu hide-at-first"', $output);
return $output;
}