diff options
Diffstat (limited to 'jquery_drawer.module')
-rw-r--r-- | jquery_drawer.module | 45 |
1 files changed, 41 insertions, 4 deletions
diff --git a/jquery_drawer.module b/jquery_drawer.module index 5f759d3..f382b66 100644 --- a/jquery_drawer.module +++ b/jquery_drawer.module @@ -70,14 +70,52 @@ function jquery_drawer_block($op = 'list', $delta = 0, $edit = array()) { case 'view': // Get all terms from a given vocabulary - $vid = variable_get('jquery_drawer', '1'); - $menu = taxonomy_node_tree_parents($vid); + $vid = variable_get('jquery_drawer', '1'); + $menu = taxonomy_node_tree_parents($vid); + + // Remove empty menus + foreach ($menu as $key => $term) { + if (jquery_drawer_check_empty($term->tid)) { + unset($menu[$key]); + } + } + $block['content'] = theme('jquery_drawer', $menu); return $block; } } /** + * Check empty menus. + */ +function jquery_drawer_check_empty($tid) { + $parents = array(); + $nodes = jquery_drawer_select_nodes(array($tid)); + $children = jquery_drawer_get_children($tid); + + while ($node = db_fetch_object($nodes)) { + $parents[] = $node; + } + + if (empty($parents) && empty($children)) { + return TRUE; + } +} + +/** + * Static version of taxonomy_select_nodes(). + */ +function jquery_drawer_select_nodes($tid) { + static $cache = array(); + + if (empty($cache[$tid])) { + $cache[$tid] = taxonomy_select_nodes(array($tid)); + } + + return $cache[$tid]; +} + +/** * Implementation of hook_menu(). */ function jquery_drawer_menu() { @@ -119,7 +157,6 @@ function jquery_drawer_theme() { * @ingroup themeable */ function theme_jquery_drawer($menu) { - $output = '<ul id="drw_tabs">'; $output .= implode((array) module_invoke_all('jquery_drawer')); @@ -189,7 +226,7 @@ function jquery_drawer_page($tid = NULL) { if (!isset($cache[$tid])) { $output = ''; - $nodes = taxonomy_select_nodes(array($tid)); + $nodes = jquery_drawer_select_nodes(array($tid)); $base = variable_get('jquery_drawer_link', 'node'); $tree = jquery_drawer_get_children($tid); $output .= '<ul id="drw_item" class="hidden">'; |