diff options
-rw-r--r-- | jquery_drawer.info | 3 | ||||
-rw-r--r-- | jquery_drawer.module | 76 |
2 files changed, 21 insertions, 58 deletions
diff --git a/jquery_drawer.info b/jquery_drawer.info index 964b777..9713ed5 100644 --- a/jquery_drawer.info +++ b/jquery_drawer.info @@ -3,4 +3,5 @@ name = jQuery Drawer description = Show menu with jQuery.drawer functionality. core = 6.x version = "6.x-0.1" -dependencies[] = menu taxonomy_node_tree +dependencies[] = menu +dependencies[] = taxonomy_node_tree diff --git a/jquery_drawer.module b/jquery_drawer.module index 4a49162..7dad139 100644 --- a/jquery_drawer.module +++ b/jquery_drawer.module @@ -121,21 +121,22 @@ function theme_jquery_drawer($menu) { /** * Menu callback. + * + * @TODO: split themeable output from logic. */ function jquery_drawer_page($tid = NULL) { - // First render all nodes whose parent is $term + $output = ''; + $nodes = taxonomy_select_nodes(array($tid)); + $output .= '<ul id="drw_item" class="hidden">'; - $output = ''; - $nodes = taxonomy_select_nodes(array($tid)); - + // First render all nodes whose parent is $term while ($node = db_fetch_object($nodes)) { $link['title'] = $node->title; $link['href'] = 'node/'. $node->nid; $output .= theme('jquery_drawer_link', $link); } - // Then render all nodes whose terms are children of $term - + // Check for child terms $vid = variable_get('jquery_drawer', '1'); $terms = taxonomy_node_tree_taxonomy_get_tree($vid, $tid); @@ -143,18 +144,21 @@ function jquery_drawer_page($tid = NULL) { $filter[] = $term->tid; } - $query = 'SELECT node.nid, node.title, term_node.tid FROM {node} LEFT JOIN - {term_node} ON term_node.nid = node.nid WHERE term_node.tid IN (%s) - AND node.status = "1"'; + if (isset($filter) && !empty($filter)) { + // Then render all nodes whose terms are children of $term + $query = 'SELECT node.nid, node.title, term_node.tid FROM {node} LEFT JOIN + {term_node} ON term_node.nid = node.nid WHERE term_node.tid IN (%s) + AND node.status = "1"'; - $nodes = db_query(db_rewrite_sql($query), implode(',', $filter)); - $tree = taxonomy_node_tree_build($nodes, $terms); + $nodes = db_query(db_rewrite_sql($query), implode(',', $filter)); + $tree = taxonomy_node_tree_build($nodes, $terms); - // format output - $output .= '<ul id="drw_item" class="hidden">'; - foreach ($tree as $term) { - $output .= jquery_drawer_menu_build($term); + // format output + foreach ($tree as $term) { + $output .= taxonomy_node_tree_list($term, 'jquery_drawer', 'hidden', 'node'); + } } + $output .= '</ul></li>'; // Display output @@ -165,48 +169,6 @@ function jquery_drawer_page($tid = NULL) { } /** - * Recursively build the menu. - * - * @ingroup themeable - * @TODO: integrate with taxonomy_node_tree - */ -function jquery_drawer_menu_build($term) { - - global $_jquery_drawer_id; - - if ($_jquery_drawer_id == NULL) { - $_jquery_drawer_id = 0; - } - - $_jquery_drawer_id++; - - if (isset($term->tid)) { - $output .= '<li>'; - $output .= $term->name; - if (isset($term->below)) { - $output .= '<ul id="jquery_drawer[ul]['. $_jquery_drawer_id .']" class="hidden">'; - foreach ($term->below as $child) { - $output .= jquery_drawer_menu_build($child); - } - $output .= '</ul>'; - } - else if (isset($term->nodes)) { - $output .= '<ul id="jquery_drawer[ul]['. $_jquery_drawer_id .']" class="hidden">'; - foreach ($term->nodes as $node) { - $output .= '<li>'; - $output .= '<a href="'. $GLOBALS['base_url'] .'/node/'. $node->nid .'">'. $node->title .'</a>'; - } - $output .= '</ul>'; - $output .= '</li>'; - } - $output .= '</li>'; - } - - return $output; - -} - -/** * jQuery Drawer Javascript theme function. * * @ingroup themeable |