Milonic provide full featured pull down web menus for some of the worlds largest companies
click here to see what it can do for you

Download Milonic DHTML Menu
Buy Milonic DHTML Menu

Back To Start Of Archive
Taken From The Forum: Help & Support for DHTML Menu Version 5+
Forum Topic: Click to view post
Last Updated: Saturday July 14 2012 - 06:07:51

Programatically / dynamically set properties


Poster: JMM
Dated: Thursday December 18 2003 - 19:40:21 GMT

Is there a way to programatically set individual menu and style properties and menu items? E.g. after setting up a menu using the normal syntax
Code:
with(milonic=new menuname("facility")){
style=VHRC_sub_menu_style;
top="offset=+4";

aI('text=Directions;url=/inside/facility/directions.html;');

. . .

}
is there a way to change individual properties, something like facility.top = "offset=+20", and add / remove menu items?


Poster: Maz
Dated: Friday December 19 2003 - 0:53:56 GMT

Well, yes there is or was one, but I don't see it listed and can't remember what it was exactly. I'm sure someone will know, or a forum search.

Sorry,
maz


Poster: kevin3442
Dated: Saturday December 20 2003 - 1:27:55 GMT

You can modify menu and menu item properties programatically. I've been playing around with some methods, but still have some kinks to work out (didn't know I'd be posting it). As for adding or removing menu items, I have an idea or two, but haven't been able to try them yet to see if they work. If you're willing to wait a bit, I'll probably be able to post something early next week. Just wanted to let you know that I've read your post and think I can help, but it'll take a little longer. Any specific properties you're interested in changing? A list would be helpful (some seem easier than others).

Kevin


Poster: JMM
Dated: Monday December 29 2003 - 14:59:15 GMT

Thanks for the replies, sorry I let this lapse. The reason I asked originally is because I wanted to use the same menu as part of two different designs. Everything about the menu would be the same except for the positioning, as controlled by the top and left properties, so I was hoping I could load the same menu data file for both designs and then just change those properties before drawing the menus. I ended up setting those top and left values in the menu data file with a variable, which I assigned a value to just before the code calling for the menu data file.


The other specific thing I was interested in was adding / removing menu items after initially defining the menu. It was the same situation, I wanted to use the same menu as part of two different designs, but on the homepage of the site I didn't want a link to "Home" and on the other pages I did. I'd hate to have two separate copies of the same code for the menu definition with just the addition / omission of one menu item as the only difference. I guess I could always generate the menu data file dynamically with PHP (or whatever), but I was wondering if there was a way to do it just throught the JavaScript.


Poster: kevin3442
Dated: Tuesday December 30 2003 - 20:31:36 GMT

JMM wrote:
Thanks for the replies, sorry I let this lapse.

NP... it's not like I actually replied early last week either! Holidays have been very busy indeed so far.
Quote:
...Everything about the menu would be the same except for the positioning, as controlled by the top and left properties, so I was hoping I could load the same menu data file for both designs and then just change those properties before drawing the menus. I ended up setting those top and left values in the menu data file with a variable, which I assigned a value to just before the code calling for the menu data file.

You can change the position of the menu programatically after it has been rendered. But, if you can figure out the desired location before the menu is rendered, as you did, I think that's the better approach. If you do it after the menu is already visible, then the user may see the menu appear briefly and then change locations; visually better to avoid this "jump" effect if you can.

Quote:
The other specific thing I was interested in was adding / removing menu items after initially defining the menu. It was the same situation, I wanted to use the same menu as part of two different designs, but on the homepage of the site I didn't want a link to "Home" and on the other pages I did...

Programatically adding items is something I have yet to figure out. But I can help you with removing items.

The following functions will help:
Code:
function mm_getItemByName(itemName)
{
  for (i=0; i<_mi.length; i++) if (_mi[i][1].indexOf(itemName) != -1) return i;
  return -1;
}

function mm_removeItem(itemName)
{
  var itemNum = mm_getItemByName(itemName);
  if (itemNum == -1) return;

  var idx = 0;
  newItemArr = new Array();
  for (i=0; i<_m[_mi[itemNum][0]][0].length; i++) if (_m[_mi[itemNum][0]][0][i] != itemNum) newItemArr[idx++] = _m[_mi[itemNum][0]][0][i];
  _m[_mi[itemNum][0]][0] = newItemArr;
  BDMenu(_mi[itemNum][0]);
}

mm_removeItem() is the funciton you'd call to remove an item, as specified by the item's name. The passed parameter, itemName, is the name of the menu item, as defined by the text= property in the item's aI() definition. itemName is case sensitive.

mm_getItemByName() resolves the internal item ID based on the menu item's name; you won't call it directly in this case, but it is called from mm_removeItem(), so both functions are required to remove a menu item.

Suppose you have a menu item defined like so:
Code:
aI("text=Home;url=index.html;status=To the home page;");

You could remove this item from the menu system by calling
Code:
mm_removeItem('Home');

In your case, you could call the function from the body's onload event, on your home page. One catch: depending on how quickly your menu loads and renders, the user may see the 'Home' item briefly, and then see it disappear.

Caveat #1: right now, mm_removeItem() only takes one parameter, the itemName. Since there is no internal item name like there is for menu names, the itemName is based on the actual text the item displays. So, the search fo itemName is going to return on the first menu item it finds that displays that text. This may not be ideal if you have multiple menu items that display the same text. I plan to change the function so that you can specify the menu name as well, but I have not done so yet (feel free to change it if you like).

Caveat #2: I have only tested these two functions in: IE6, NS7, and Opera 7.2, in win2k. They worked in all three of these browser/OS combinations, but I have no idea about others.

BTW: have you considered leaving the menu the same on all pages, including the Home page, then using the built-in methods for highlighting the user's current location within the menu?

Hope that helps,

Kevin


Poster: Hergio
Dated: Saturday January 3 2004 - 17:48:53 GMT

Also look at some of the examples Milonic has up on the main website. For example, this http://www.milonic.com/menusample.php?sampleid=23 shows an example of how to get at some of the innards of the menu on the fly.