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_menu */ function yuimenu_admin_settings() { $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(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 hook_menu(). */ function yuimenu_menu($may_cache) { if (!$may_cache) { $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'); } else { $items[] = array( 'path' => 'admin/settings/yuimenu', 'title' => t('YUI Menu Settings'), 'callback' => 'drupal_get_form', 'callback arguments' => 'yuimenu_admin_settings', 'access' => user_access('access administration pages'), '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($in_str) { $from_char= array("\"", "\\"); $to_char = array("'", "-"); $out_str = str_replace($from_char, $to_char, $in_str); return ($out_str); } function html_menu($pid = 1) { switch (variable_get('yuimenu_type', 'tns')) { case 'tns' : $output = get_html_menu_script($pid); break; case 'lns' : $output = get_html_menu_script($pid); break; case 'tnm' : $output = get_html_menu_markup($pid); break; } return $output; } function get_html_menu_script($pid) { $menu = menu_get_menu(); $output .= '
'; return $output; } function get_html_menu_markup($pid) { $menu = menu_get_menu(); $output .= '
    '; if (isset($menu['visible'][$pid]) && $menu['visible'][$pid]['children']) { if (count($menu['visible'][$pid]['children']) > 0) { $output .= compose_markap_body($pid); } } $output .= '
'; return $output; } function compose_markap_body($pid) { $menu = menu_get_menu(); if (isset($menu['visible'][$pid]) && $menu['visible'][$pid]['children']) { foreach ($menu['visible'][$pid]['children'] as $mid) { //modification here: $my_menu_temp=menu_get_item($mid); $my_menu_link=$my_menu_temp['path']; $my_menu_title=$my_menu_temp['title']; if (count($menu['visible'][$mid]['children']) > 0) { if (is_menu_child_of_root($mid)) { $output .= "
  • ". l($my_menu_title, $my_menu_link, array('class' => 'yuimenubaritemlabel')); } else { $output .= "
  • ". l($my_menu_title, $my_menu_link, array('class' => 'yuimenuitemlabel')); } $output .= '
      '; $output .= compose_markap_body($mid); $output .= '
  • '; } else { if (is_menu_child_of_root($mid)) { $output .= "
  • ". l($my_menu_title, $my_menu_link, array('class' => 'yuimenubaritemlabel')) ."
  • "; } else { $output .= "
  • ". l($my_menu_title, $my_menu_link, array('class' => 'yuimenuitemlabel')) ."
  • "; } } } } return ($output); } function is_menu_child_of_root($pid) { $menu = menu_get_menu(); $is_menu_child = FALSE; $myroot = variable_get('yuimenu_root', '1'); foreach ($menu['visible'][$myroot]['children'] as $root_child) { if ($root_child == $pid) $is_menu_child= TRUE; } return ($is_menu_child); } function script_menu($pid = 1) { $menu = menu_get_menu(); if (isset($menu['visible'][$pid]) && $menu['visible'][$pid]['children']) { $i=0; foreach ($menu['visible'][$pid]['children'] as $mid) { if (count($menu['visible'][$mid]['children'])>0) { $output .= "this.getItem(". $i .").cfg.setProperty(\"submenu\", { id: \"". rep_char($menu['visible'][$mid]['title']) ."\", itemdata: oSubmenuData[\"". rep_char($menu['visible'][$mid]['title']) ."\"] });\n"; } $i++; } } return $output; } function create_menu($pid = 1) { $menu = menu_get_menu(); $i=1; if (isset($menu['visible'][$pid]) && $menu['visible'][$pid]['children']) { foreach ($menu['visible'][$pid]['children'] as $mid) { $children = isset($menu['visible'][$mid]['children']) ? $menu['visible'][$mid]['children'] : NULL; $output .= "\n\"". rep_char($menu['visible'][$mid]['title']) ."\": [\n"; if (count($children) > 0) { $output .= create_inner_menu($mid); } if ($i 0) { $output .= "{ text: \"". rep_char($menu['visible'][$mid]['title']) ."\",url: \"". url(rep_char($menu['visible'][$mid]['path'])) ."\", submenu: { id: \"". url(rep_char($menu['visible'][$mid]['path'])) ."\", itemdata: [\n"; $output .= create_inner_menu($mid); $output .= "]}}"; } else { $output .= "{ text: \"". rep_char($menu['visible'][$mid]['title']) ."\", url: \"". url(rep_char($menu['visible'][$mid]['path'])) ."\" }\n"; } if ($j < count($menu['visible'][$pid]['children'])) { $output .= ","; } $j++; } } return $output; } function get_ani_scr() { return '// Animation object var oAnim; // "beforeshow" event handler for each submenu of the menu bar function onMenuBeforeShow(p_sType, p_sArgs) { var oBody, oShadow, oUL; if (this.parent) { oShadow = this.element.lastChild; oShadow.style.height = "0px"; if (oAnim && oAnim.isAnimated()) { oAnim.stop(); oAnim = null; } oBody = this.body; oUL = oBody.getElementsByTagName("ul")[0]; YAHOO.util.Dom.setStyle(oBody, "overflow", "hidden"); YAHOO.util.Dom.setStyle(oUL, "marginTop", ("-" + oUL.offsetHeight + "px")); } } function onTween(p_sType, p_aArgs, p_oShadow) { if (this.cfg.getProperty("iframe")) { this.syncIframe(); } if (p_oShadow) { p_oShadow.style.height = this.element.offsetHeight + "px"; } } function onAnimationComplete(p_sType, p_aArgs, p_oShadow) { var oBody = this.body, oUL = oBody.getElementsByTagName("ul")[0]; if (p_oShadow) { p_oShadow.style.height = this.element.offsetHeight + "px"; } YAHOO.util.Dom.setStyle(oUL, "marginTop", "auto"); YAHOO.util.Dom.setStyle(oBody, "overflow", "visible"); if (YAHOO.env.ua.ie) { YAHOO.util.Dom.setStyle(oBody, "zoom", "1"); } } // "show" event handler for each submenu of the menu bar function onMenuShow(p_sType, p_sArgs) { var oElement, oShadow, oUL; if (this.parent) { oElement = this.element; oShadow = oElement.lastChild; oUL = this.body.getElementsByTagName("ul")[0]; oAnim = new YAHOO.util.Anim(oUL, { marginTop: { to: 0 } },.5, YAHOO.util.Easing.easeOut); oAnim.onStart.subscribe(function () { oShadow.style.height = "100%"; }); oAnim.animate(); /* Refire the event handler for the "iframe" configuration property with each tween so that the size and position of the iframe shim remain in sync with the menu. */ if (YAHOO.env.ua.ie) { oShadow.style.height = oElement.offsetHeight + "px"; oAnim.onTween.subscribe(onTween, oShadow, this); } oAnim.onComplete.subscribe(onAnimationComplete, oShadow, this); } }'; } function yuimenu_block($op='list', $delta=0) { global $user; if ('lns' == variable_get('yuimenu_type', 'tns')) { // listing of blocks, such as on the admin/block page if ($op == "list") { $block[0]["info"] = t("YUI Menu"); return $block; } else if ($op == 'view') { // our block content // content variable that will be returned for display $block_content = '
    '; $block_content .= html_menu(variable_get('yuimenu_root', '1')); $block_content .= '
    '; $block['subject'] = $user->name; $block['content'] = $block_content; return $block; } } } function get_yui_left_script() { $scr = ''; return ($scr); }