Disable or Modify Menu items based on page being viewed

Having problems with DHTML Menu? There is usually somebody here who knows the answer.
Post Reply
jshep@magma.ca
Beginner
Beginner
Posts: 4
Joined: Mon Sep 15, 2003 5:51 pm
Location: Ottawa, Canada
Contact:

Disable or Modify Menu items based on page being viewed

Post by jshep@magma.ca »

I have a number of "common" menu items that are displayed on all pages at various directory levels. I would like to disable or modify menu items based on the page being viewed. Can anyone suggest an easyway of doing this?

Thanks

Jim
User avatar
Ruth
 Team
 Team
Posts: 8763
Joined: Thu May 15, 2003 5:02 am
Location: Yucaipa, CA
Contact:

Post by Ruth »

I'm not sure either of these topics will help, but THIS one has to do with inserting items, and farther down in the topic is information on a function to remove an item. THIS topic has information on removing items and a module for editing items. Hope this helps.

Ruth
twisted6
Advanced
Advanced
Posts: 10
Joined: Fri Jan 16, 2004 10:53 pm
Location: Canada, eh?

Post by twisted6 »

I use this technique very often...

Put these two statements near the top of the menu_data.js file.

Code: Select all

var dir = location.href.substring(0,location.href.lastIndexOf('/')+1);
var thefile = location.href.substring(dir.length,location.href.length+1);
Check the file where appropriate. This logic enables the menu item for a specific page, but you just have to change the If statement to suit your application.

Code: Select all

if (thefile == "about.html")	{	
	aI("text=Conditional Page;url=whatever.html");
}
If you want to check for all files that start with a particular string, eg. prod*, try this:

Code: Select all

if (thefile.substring(0,"prod".length) == "prod")	{
	aI("text=Conditional Page;url=whatever.html");
}
User avatar
Ruth
 Team
 Team
Posts: 8763
Joined: Thu May 15, 2003 5:02 am
Location: Yucaipa, CA
Contact:

Post by Ruth »

Thanks for the help, Twisted6. We really appreciate it. :D

Ruth
User avatar
kevin3442
Milonic God
Milonic God
Posts: 2460
Joined: Sat Sep 07, 2002 12:09 am
Location: Lincoln, NE
Contact:

Post by kevin3442 »

Hi Jim,
jshep@magma.ca wrote:...I would like to disable or modify menu items based on the page being viewed...

Twisted6's ideas are very useful if you want to conditionally include or exclude a menu item in a menu. In other words, by wrapping the call to aI() inside of an "if", the menu item defined by that aI() call will appear in the menu if the condition is met, but will not appear at all in the menu if the condition is not met.

Extending Twisted6's approach, you could always include an item in a menu, but have it appear to be enabled or disabled depending on the conditional test. (You could make an item appear to be disabled by altering the oncolor, onbgcolor, etc... there's even a type=disabled item property that you might find useful). In other words, you could add an "else" to the condition:

Code: Select all

if (condition is met) {
  aI("..."); // menu item with enabled appearance and behavior
}
else {
  aI("..."); // menu item with disabled appearance and behavior.
}
Finally, if you want to be able to modify a menu item's appearance and behavior programatically, after the page has been rendered, you can do so with a function called mm_changeItemProperty(), which is described in detail in this post.

Cheers,

Kevin
Post Reply