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. DO NOT SELECT AN ITEM THAT DOES NOT HAVE A CHILD ITEM'), '#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' => t('Website Top Nav With Submenus From JavaScript'), 'tnm' => t('Website Top Nav With Submenus Built From Markup'), 'lns' => t('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), ); $form['yuimenu_setid'] = array( '#type' => 'textfield', '#title' => t('Menu DIV ID'), '#description' => t('Define your own Menu ID (optional, for CSS)'), '#default_value' => variable_get('yuimenu_setid', 'productsandservices') ); 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; } /** * Generate js code for top markup style menu. */ function get_yui_top_markup () { $scr = ' '; return ($scr); } /** * Generate js code for top script style menu. */ function get_yui_top_script () { $scr = ''; return ($scr); } /** * when menu has a " or ' the script is fails. So replace them. * @param $inStr * Input string to replace. */ function rep_char ($inStr) { $fromChar= array("\"","\\"); $toChar = array("'","-"); $outStr = str_replace($fromChar, $toChar, $inStr); return ($outStr); //return t($inStr); } /** * Generate js code for top markup style menu. * @param $menu_id * Root menu id for composing the menu. */ 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; } /** * Generate html code for script style menu. * @param $menu_id * Root menu id for composing the menu. */ function get_html_menu_script ($menu_id) { $output .=' '; return $output; } /** * Generate menu as script. * @param $menu_id * Root menu id for composing the menu. */ function script_menu($menu_id) { $menu = load_menu($menu_id); if (is_array($menu) ) { $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; } /** * Generate root items as markup menu. * @param $menu_id * Root menu id for composing the menu. */ function get_html_menu_markup ($menu_id) { $output .=' '; return $output; } /** * Generate tree of markup style menu. * @param $menu_name * menu name * @param $mlid * menu id. * @param $menu * menu. */ 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; } /** * Generate root menu items as markup. * @param $menu * Menu items to compose body. */ function compose_markap_body($menu) { $output = ''; if (is_array($menu) ) { 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 .= '