A module to have a css/javascript based drop down and javascript based pop-up menu for site navigation.

', array('!link' => l('admin/build/block', 'admin/build/block'))); break; } return $output; } /* * Settings form as implemented by hook_admin */ function yuimenu_admin() { $form['yuimenu_root'] = array( '#type' => 'select', '#title' => t('Root of Menu Tree'), '#description' => t('Select the root item of menu tree.'), '#default_value' => variable_get('yuimenu_root','1'), '#options' => menu_parent_options(menu_get_menus(), 0), ); $form['yuimenu_type'] = array( '#type' => 'select', '#title' => t('Menu Display type'), '#description' => t('Select the display type of the menu.'), '#default_value' => variable_get('yuimenu_type','tna'), '#options' => array('tns' =>'Website Top Nav With Submenus From JavaScript', 'tnm' =>'Website Top Nav With Submenus Built From Markup', 'lns' =>'Website Left Nav With Submenus From JavaScript') ); $form['yuimenu_animate'] = array( '#type' => 'checkbox', '#title' => t('Animated Menu'), '#description' => t('To enable animation while opening menu check this.'), '#default_value' => variable_get('yuimenu_animate',0), ); return system_settings_form($form); } /** * Implemention of init(). */ function yuimenu_init() { $yui_source = variable_get('yui_source','http://yui.yahooapis.com/2.5.0'); // the order of script and style sheet is important. Don't change. yui_add_js('menu', $yui_source, '/build/yahoo-dom-event/yahoo-dom-event.js'); if (variable_get('yuimenu_animate',0)) { yui_add_js('menu', $yui_source, '/build/animation/animation-min.js'); } yui_add_css('menu', $yui_source, '/build/menu/assets/skins/sam/menu.css'); yui_add_js('menu', $yui_source, '/build/container/container_core-min.js'); yui_add_js('menu', $yui_source, '/build/menu/menu-min.js'); switch (variable_get('yuimenu_type','tns')) { case 'tns': $script_body_to_html_head = get_yui_top_script(); break; case 'tnm': $script_body_to_html_head = get_yui_top_markup(); break; case 'lns': $script_body_to_html_head = get_yui_left_script(); break; } drupal_set_html_head($script_body_to_html_head); //drupal_add_css(drupal_get_path('module', 'yuimenu') .'/yuimenu.css'); } /** * Implemention of hook_menu(). */ function yuimenu_menu() { $items['admin/settings/yuimenu'] = array( 'title' => t('YUI Menu Settings'), 'page callback' => 'drupal_get_form', 'page arguments' => array('yuimenu_admin'), 'access arguments' => array('administer site configuration'), 'type' => MENU_NORMAL_ITEM, ); return $items; } function get_yui_top_markup () { $scr = ' '; return ($scr); } function get_yui_top_script () { $scr = ''; return ($scr); } /* * when menu has a " or ' the script is fails. So replace them. */ function rep_char ($inStr) { $fromChar= array("\"","\\"); $toChar = array("'","-"); $outStr = str_replace($fromChar, $toChar, $inStr); return ($outStr); //return t($inStr); } function html_menu($menu_id = 'navigation:0') { switch (variable_get('yuimenu_type','tns')) { case 'tns' : $output = get_html_menu_script($menu_id); break; case 'lns' : $output = get_html_menu_script($menu_id); break; case 'tnm' : $output = get_html_menu_markup($menu_id); break; } return $output; } function get_html_menu_script ($menu_id) { $output .='
'; return $output; } function script_menu($menu_id) { $menu = load_menu($menu_id); $i=0; foreach ($menu as $menu_item) { $mlid = $menu_item['link']['mlid']; if ($menu_item['link']['hidden'] == 0) { if ($menu_item['link']['has_children'] != 0) { $output .= 'this.getItem('. $i .').cfg.setProperty("submenu", oSubmenuData['.$i.']);'."\n"; } $i++; } } return $output; } function get_html_menu_markup ($menu_id) { $output .='
    '; list($menu_name, $mlid) = explode(':', $menu_id); $output .= compose_markap_body_tree($menu_name, $mlid); $output .='
'; return $output; } function compose_markap_body_tree($menu_name, $mlid = NULL, $menu = NULL) { $menu = load_menu($menu_name.':'.$mlid); if ($menu) { $output .= compose_markap_body($menu); } return $output; } function compose_markap_body($menu) { $output = ''; foreach ($menu as $menu_item) { $mlid = $menu_item['link']['mlid']; // Check to see if it is a visible menu item. if ($menu_item['link']['hidden'] == 0) { // Build class name based on menu path // e.g. to give each menu item individual style. // Strip funny symbols. //BA $clean_path = str_replace(array('http://', '<', '>', '&', '=', '?', ':'), '', $menu_item['link']['href']); // Convert slashes to dashes. //BA $clean_path = str_replace('/', '-', $clean_path); //BA $path_class = 'menu-path-'. $clean_path; // If it has children build a nice little tree under it. if (is_menu_child_of_root($menu_item['link']['plid'])) { $yuiliclass = 'yuimenubaritem'; $yuihrefclass = 'yuimenubaritemlabel'; } if ((!empty($menu_item['link']['has_children'])) && (!empty($menu_item['below']))) { // Keep passing children into the function 'til we get them all. $children = compose_markap_body($menu_item['below']); // Build the child UL. $output .= '
  • '. l($menu_item['link']['title'], $menu_item['link']['href'],array('attributes' => array('class'=>$yuihrefclass))); $output .= '
      '."\n"; $output .= $children; $output .= "
  • \n"; } else { $output .= '
  • '. l($menu_item['link']['title'], $menu_item['link']['href'],array('attributes' => array('class'=>$yuihrefclass))) .'
  • '."\n"; } } } return $output; } function is_menu_child_of_root ($plid) { list($root_menu_name, $root_mlid) = explode(':', variable_get('yuimenu_root','navigation:0')); if ($plid == $root_mlid) return true; return false; } function create_menu($menu_id) { $menu = load_menu($menu_id); $j=1; foreach ($menu as $menu_item) { if ($menu_item['link']['hidden'] == 0) { $mlid = $menu_item['link']['mlid']; $output .= "\n{\n".'id: "' . rep_char($menu_item['link']['title']) . '",'."\nitemdata: [\n"; if ($menu_item['link']['has_children'] > 0) { $output .= create_inner_menu($menu_item['link']['menu_name'].':'.$mlid); } $output .= ']}'.($j++ 0) { $output .= "{ text: \"".rep_char($menu_item['link']['title'])."\",url: \"".url(rep_char($menu_item['link']['href']))."\", submenu: { id: \"".url(rep_char($menu_item['link']['title']))."\", itemdata: [\n"; $output .= create_inner_menu($menu_item['link']['menu_name'].':'.$mlid); $output .= "]}}".($j++name; $block['content'] = $block_content; return $block; } } } function get_yui_left_script () { $scr = ''; return ($scr); } ?>