Elxis CMS Forum

Extensions => Modules => Topic started by: pavel on April 09, 2009, 11:27:55

Title: DSMenu - all li items always "active"
Post by: pavel on April 09, 2009, 11:27:55
I am using DSMenu module on my main menu.  Here is the problem I have:

All <li> items of the menu (including second level items) are printed with "active" css.  So every single item is <li class="active">...</li>

On my testing server same DSMenu installation is producing the normal code as it should, where only a current page shows <li class="active">..
I checked again and again, I have the same files of the module on my testing server and on a live site. 

That means that some other file on a live site produces this error.  Would anybody have any idea what can cause this?

Title: Re: DSMenu - all li items always "active"
Post by: pavel on April 09, 2009, 13:31:25
Ok, I think I found what was causing a problem.  The code that is responsible for assigning a class "active" to the current <li> tag is following:

Code: [Select]
if ($row->link != "seperator" &&
$current_itemid == $row->id ||
$row->id == $highlight ||
(sefRelToAbs($Itemid == $id))) {
$li = "<li class=\"active\">";
echo $li;

I removed the following and error disappeared, everything shows without problems:
Code: [Select]
(sefRelToAbs($Itemid == $id))
I don't know why it was causing a problem on my site installation and same code works fine on my test server. At least it works now!
Title: Re: DSMenu - all li items always "active"
Post by: pavel on April 09, 2009, 15:12:09
The "catch" of removing (sefRelToAbs($Itemid == $id)) is that now only the top level menu shows <li class="active> where appropriate and it does not add "active" class for sublevel menus  :(
so I am back to square one.

MODIFIED:

So toplevel menu gets highlighted where necessary, sublevel menu does not get highlighted at all.
Title: Re: DSMenu - all li items always "active"
Post by: Ivan Trebješanin on April 09, 2009, 16:06:28
Hi pavel,

Thank you for debugging. This module was written using PHP4, and should be rewriten it in PHP5. What is your PHP version?
Title: Re: DSMenu - all li items always "active"
Post by: pavel on April 09, 2009, 16:28:55
I am using latest version of Elxis which works only with PHP5, so on both servers I am running PHP5.

I have noticed, that if I remove (sefRelToAbs($Itemid == $id))) part, then no submenu items get highlighted at all. Leaving it on gets highlighted ALL items, toplevel and sublevel, so there must be something about ($Itemid == $id) that produces error in the script (for my live installation).
Title: Re: DSMenu - all li items always "active"
Post by: datahell on April 09, 2009, 20:16:25
sefRelToAbs($Itemid == $id)
This is totally wrong! The first input of the sefRelToAbs function should be a link:

sefRelToAbs($link, $seolink='');

Usage example
sefRelToAbs('index.php?option=com_weblinks&Itemid=45', 'links/');

Replace this:
if ($row->link != "seperator" && $current_itemid == $row->id
|| $row->id == $highlight ||
(sefRelToAbs($Itemid == $id))) {
$li = "<li class=\"active\">";
echo $li;

With this:

if ($row->link != "seperator" && (($current_itemid == $row->id) || ($row->id == $highlight))) {
$li = "<li class=\"active\">";
echo $li;
Title: Re: DSMenu - all li items always "active"
Post by: pavel on April 09, 2009, 23:17:11
The code above produced some php errors, but this worked:

Code: [Select]
if ($row->link != "seperator" && ($current_itemid == $row->id || $row->id == $highlight)) {
$li = "<li class=\"active\">";
}
echo $li;

Now only the current menu item gets highlighted, providing that the menu item points to the content item or a component. 

I have one top level menu item with three sublevel menu items (of URL-link type), which are pointing to the IOS Gallery albums (to go straight to the images of the album).  For these links it does not work.

If I turn off SEO, then a link to the content item has the following format:
index.php?option=com_content&task=blogcategory&id=25&Itemid=92
There is an ID and Itemid, so above code works for it.

A link to the gallery album has the following format:
index.php?option=com_gallery&task=category&cid=1&Itemid=101
index.php?option=com_gallery&task=category&cid=4&Itemid=101
There is cid (different for different category) and Itemid (stays the same, as it belongs to the component IOS Gallery).

The reason why it was working on my test serverinstallation and wasn't working on my live installation is because all links on my test server were pointing to the content and on live installation I had links to the gallery albums + sefRelToAbs was producing an error.

I thought that changing the code as following would work (it does not produce any errors, but it is not working).

Code: [Select]
               $li =  "\n".$indents[$n][1] ;
                        $current_itemid = trim( mosGetParam( $_REQUEST, 'Itemid', 0 ) );
$currentcat = intval(mosGetParam($_REQUEST, 'cid', 0));

if ($row->link != "seperator" && ($current_itemid == $row->id || $row->id == $highlight || $currentcat == $row->cid)) {
$li = "<li class=\"active\">";
}
echo $li;

I am not a programmer, so I apologize if I combined apples and oranges in one soup. :)
Title: Re: DSMenu - all li items always "active"
Post by: datahell on April 09, 2009, 23:42:43
I did nt wrote it like this. You need to change just the first line.

Change this:
if ($row->link != "seperator" && $current_itemid == $row->id
|| $row->id == $highlight ||
(sefRelToAbs($Itemid == $id))) {

To this:
if ($row->link != "seperator" && (($current_itemid == $row->id) || ($row->id == $highlight))) {
Title: Re: DSMenu - all li items always "active"
Post by: pavel on April 09, 2009, 23:54:10
It works for content items, now I need to figure out how to make it work for gallery items  ::)
Title: Re: DSMenu - all li items always "active"
Post by: Blacksoll on September 10, 2009, 17:47:37
I think that i'm facing the same problem.
I tryed the above but with no luck. I need your help for debugging.......
My site link is http://levitostasio.gr
Title: Re: DSMenu - all li items always active
Post by: datahell on September 10, 2009, 18:50:34
blacksoll you should make your menu shorter as it does n't fit on a single line for screen resolutions smaller than 1200px width.
Title: Re: DSMenu - all li items always "active"
Post by: Blacksoll on September 10, 2009, 19:57:04
O.K. I unpublish some and now fits.
But the problem remains............I don't even know if this is the same as pavel has.........Should i open a new topic ?