[LOW:KNOWN ISSUE:1.0.11] Fix for submenu

Locked
User avatar
Sal
Joomla! Apprentice
Joomla! Apprentice
Posts: 46
Joined: Thu Aug 10, 2006 8:47 pm
Location: Frosinone

[LOW:KNOWN ISSUE:1.0.11] Fix for submenu

Post by Sal » Sat Oct 07, 2006 12:21 pm

Hello,
  joomla writes an id="active_menu" on the active menu item.
the problem is that it adds the same id even for the submenus.
This is an error reported by the css validator because you can't have more tags with the same id.
Also, it unables you to have a different style for the active submenu item.

so i made a little fix in the mosGetMenuLink function that you can find int joomla/modules/mod_mainmenu.php

Code: Select all

/**
* Utility function for writing a menu link
*/
function mosGetMenuLink( $mitem, $level=0, &$params, $open=null ) {
  global $Itemid, $mosConfig_live_site, $mainframe;

  $txt = '';
		
  switch ($mitem->type) {
    case 'separator':
    case 'component_item_link':
      break;
			
    case 'url':
      if ( eregi( 'index.php\?', $mitem->link ) ) {
        if ( !eregi( 'Itemid=', $mitem->link ) ) {
          $mitem->link .= '&Itemid='. $mitem->id;
        }
      }
      break;
				
    case 'content_item_link':
    case 'content_typed':
      // load menu params
      $menuparams = new mosParameters( $mitem->params, $mainframe->getPath( 'menu_xml', $mitem->type ), 'menu' );
				
      $unique_itemid = $menuparams->get( 'unique_itemid', 1 );
				
      if ( $unique_itemid ) {
        $mitem->link .= '&Itemid='. $mitem->id;
      } else {
        $temp = split('&task=view&id=', $mitem->link);
					
        if ( $mitem->type == 'content_typed' ) {
          $mitem->link .= '&Itemid='. $mainframe->getItemid($temp[1], 1, 0);
        } else {
          $mitem->link .= '&Itemid='. $mainframe->getItemid($temp[1], 0, 1);
        }
      }
      break;

    default:
      $mitem->link .= '&Itemid='. $mitem->id;
      break;
  }

  // Active Menu highlighting
  $current_itemid = $Itemid;
  if ( !$current_itemid ) {
    $id = '';
  } else if ( $current_itemid == $mitem->id ) {
    //---Sal
    if ($level > 0 ) {
      $id = 'id="active_submenu'. $params->get( 'class_sfx' ) .'"';
    } else {
      $id = 'id="active_menu'. $params->get( 'class_sfx' ) .'"';
    }
    //---
  } else if( $params->get( 'activate_parent' ) && isset( $open ) && in_array( $mitem->id, $open ) )  {
    //---Sal
    if ($level > 0 ) {
      $id = 'id="active_submenu'. $params->get( 'class_sfx' ) .'"';
    } else {
      $id = 'id="active_menu'. $params->get( 'class_sfx' ) .'"';
    }
    //---
  } else {
    $id = '';
  }

  if ( $params->get( 'full_active_id' ) ) {
    // support for `active_menu` of 'Link - Component Item'	
    if ( $id == '' && $mitem->type == 'component_item_link' ) {
      parse_str( $mitem->link, $url );
      if ( $url['Itemid'] == $current_itemid ) {
        //---Sal
        if ($level > 0 ) {
          $id = 'id="active_submenu'. $params->get( 'class_sfx' ) .'"';
        } else {
          $id = 'id="active_menu'. $params->get( 'class_sfx' ) .'"';
        }
        //---
      }
    }
			
    // support for `active_menu` of 'Link - Url' if link is relative
    if ( $id == '' && $mitem->type == 'url' && strpos( 'http', $mitem->link ) === false) {
      parse_str( $mitem->link, $url );
      if ( isset( $url['Itemid'] ) ) {
        if ( $url['Itemid'] == $current_itemid ) {
          $id = 'id="active_menu'. $params->get( 'class_sfx' ) .'"';
        }
      }
    }
  }
		
  // replace & with amp; for xhtml compliance
  $mitem->link = ampReplace( $mitem->link );

  // run through SEF convertor
  $mitem->link = sefRelToAbs( $mitem->link );

  $menuclass = 'mainlevel'. $params->get( 'class_sfx' );
  if ($level > 0) {
    $menuclass = 'sublevel'. $params->get( 'class_sfx');
  }

  // replace & with amp; for xhtml compliance
  // remove slashes from excaped characters
  $mitem->name = stripslashes( ampReplace($mitem->name) );

  switch ($mitem->browserNav) {
    // cases are slightly different
    case 1:
      // open in a new window
      $txt = '<a href="'. $mitem->link .'" target="_blank" class="'. $menuclass .'" '. $id .'>'. $mitem->name .'</a>';
      break;

    case 2:
      // open in a popup window
      $txt = "<a href=\"#\" onclick=\"javascript: window.open('". $mitem->link ."', '', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=780,height=550'); return false\" class=\"$menuclass\" ". $id .">". $mitem->name ."</a>\n";
      break;

    case 3:
      // don't link it
      $txt = '<span class="'. $menuclass .'" '. $id .'>'. $mitem->name .'</span>';
      break;

    default:	
      // open in parent window
      $txt = '<a href="'. $mitem->link .'" class="'. $menuclass .'" '. $id .'>'. $mitem->name .'</a>';
      break;
  }

  if ( $params->get( 'menu_images' ) ) {
    $menu_params = new stdClass();
    $menu_params = new mosParameters( $mitem->params );
    $menu_image = $menu_params->def( 'menu_image', -1 );
    if ( ( $menu_image != '-1' ) && $menu_image ) {
      $image = '<img src="'. $mosConfig_live_site .'/images/stories/'. $menu_image .'" border="0" alt="'. $mitem->name .'"/>';
      if ( $params->get( 'menu_images_align' ) ) {
        $txt = $txt .' '. $image;
      } else {
        $txt = $image .' '. $txt;
      }
    }
  }

  return $txt;
}

Last edited by miki89 on Fri Nov 10, 2006 1:55 pm, edited 1 time in total.

User avatar
Robin
Joomla! Master
Joomla! Master
Posts: 15753
Joined: Thu Aug 18, 2005 10:41 am

Re: Fix for submenu

Post by Robin » Tue Oct 17, 2006 1:14 pm

Q&T Note; Status > Under review

Thanks for the report, regards Robin

User avatar
miki89
Joomla! Explorer
Joomla! Explorer
Posts: 397
Joined: Wed Jan 04, 2006 3:28 pm
Location: Milan, Italy

Re: [UNDER REVIEW:1.0.11] Fix for submenu

Post by miki89 » Thu Nov 09, 2006 8:56 pm

Are you sure? I've tried to confirm the problem, but I always see only one "active_menu" id. Could you tell me exactly when and where you see the double id?
Thank you

Q&T note: Status -> Information Required      Impact low.
             
Imagination is more important than knowledge... (Albert Einstein)

User avatar
Sal
Joomla! Apprentice
Joomla! Apprentice
Posts: 46
Joined: Thu Aug 10, 2006 8:47 pm
Location: Frosinone

Re: [LOW:INFO REQ:1.0.11] Fix for submenu

Post by Sal » Thu Nov 09, 2006 11:26 pm

to miki98:

the problem only comes out when you want to highlight the entire branch. I mean setting the "active parent" parameter in the menu module from the module list.

Ex.:

Menu1
Menu2
  Menu21
  Menu22
Menu3

menu2 and menu22 have both id=active_menu. and that generates an error on the css validator because there are 2 ids with the same name.

hope this has been clear now.

User avatar
miki89
Joomla! Explorer
Joomla! Explorer
Posts: 397
Joined: Wed Jan 04, 2006 3:28 pm
Location: Milan, Italy

Re: [LOW:INFO REQ:1.0.11] Fix for submenu

Post by miki89 » Fri Nov 10, 2006 1:16 pm

Sal wrote: I mean setting the "active parent" parameter in the menu module from the module list.
ok I understand. now I'll test the fix.

Q&T note: status -> Under Review
Imagination is more important than knowledge... (Albert Einstein)

User avatar
miki89
Joomla! Explorer
Joomla! Explorer
Posts: 397
Joined: Wed Jan 04, 2006 3:28 pm
Location: Milan, Italy

Re: [LOW:UNDER REVIEW:1.0.11] Fix for submenu

Post by miki89 » Fri Nov 10, 2006 1:44 pm

effectively the fix works, but all the templates have to be changed introducing the new "active_submenu" id. it will cause a lot of problems.
if the W3C compliance is important for you, simply disable the "active_parent" parameter or apply this fix yourself and modify your template
this problem will not be fixed in 1.0.12

Q&T Note:    Status -> Known issue/limitation
Last edited by miki89 on Fri Nov 10, 2006 1:54 pm, edited 1 time in total.
Imagination is more important than knowledge... (Albert Einstein)

48thAve
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Thu Oct 12, 2006 12:04 pm

Re: [LOW:KNOWN ISSUE:1.0.11] Fix for submenu

Post by 48thAve » Thu Nov 30, 2006 8:47 am

I copied the submenu-fix code and pasted it into mod_mainmenu.php (replacing the old code) but when I view my page, only part of the page displays... up to where the menu would begin.  Do I need to change anything else? Thanks!

48thAve
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Thu Oct 12, 2006 12:04 pm

Re: [LOW:KNOWN ISSUE:1.0.11] Fix for submenu

Post by 48thAve » Thu Nov 30, 2006 1:18 pm

Nevermind. Instead, I used toubkal's css solution:
td div a#active_menu


Locked

Return to “Known Issues - Archive”