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:13

Need To Access Menu Item's Attributes


Poster: Bob Martin
Dated: Friday August 27 2004 - 20:31:10 BST

I would like to access a menu item's title from a Javascript function. Initially, I just passed it as an argument to my function, but since our menu is HUGE and some menu item titles are really LONG, I would prefer to only pass it down once in the server-built .js file to save bandwidth and for faster client load times.

Is there an API to access a menu item's attributes, such as title, from within an onfunction-called .js function?


Poster: John
Dated: Saturday August 28 2004 - 17:44:04 BST

See if either of these will help...

http://www.milonic.com/menu_methods.php
http://www.milonic.com/menu_variables.php


Poster: kevin3442
Dated: Monday August 30 2004 - 19:08:55 BST

Hi Bob,

Is your intent to retrieve current attributes or to change them? I have some functions that would probably help. If you want aq general function that will let ou change any property in a targeted item, you might look here.

Cheers,

Kevin


Poster: Bob Martin
Dated: Friday September 3 2004 - 17:08:37 BST

Kevin,

Initially I only want to retrieve a menu item's attributes, but I'll look over your referenced thread and see if that'll help.

Thanks.

Bob


Poster: kevin3442
Dated: Friday September 3 2004 - 21:34:33 BST

Hi Bob,
Bob Martin wrote:
...Initially I only want to retrieve a menu item's attributes, ...

Here area couple of functions that will let you get the curernt setting of any property, in any item, within any menu.

Getting a Property Setting by Item Number

Here's a function:
Code:
function mm_getItemNumberProperty(menuName, itemNum, codeRef)
{
  var menuNum = getMenuByName(menuName);
  if (itemNum >= _m[menuNum][0].length) return -1;
  return _mi[_m[menuNum][0][itemNum]][codeRef];
}

There are three parameters:

(1) - menuName is the name of the menu containing the target item.

(2) - itemNum is the number of the item within the menu, starting at 0, for the first item in the menu, and up to the total number of items in the menu minus 1 (i.e., like an array index). So, if a menu contains 5 items, the itemNum for that menu would range from 0 to 4. If you pass an itemNum outside of the valid range, the function will return -1 as an error state.

(3) - codeRef is the code reference number for the property you are interested in. You'll find the codeRef for each menu item property in the table on the quick refs page for menu item propertes.

So, suppose you had a menu defined like so:
Code:
with(milonic=new menuname("newspapers")){
style=mainStyle;
aI("text=Los Angeles Times;url=http://www.latimes.com/");
aI("text=New York Times;url=http://www.nytimes.com/");
aI("text=USA Today;url=http://www.usatoday.com/");
aI("text=Wall Street Journal;url=http://www.wsj.com/");
aI("text=Washington Post;url=http://www.washingtonpost.com/");
}

If you wanted to get value of the text property (codeRef = 1) of the third menu item (itemNum = 2), you'd use the following call:
Code:
title = mm_getItemNumberProperty('newspapers',2,1);

The title variable would now contain the string USA Today.

Getting a Property Setting by "Item Name"

Here's a similar function that gets the value of a property within a menu item, but rather than identifying the item by number, you identify it by it's text.
Code:
function mm_getItemNameProperty(menuName, itemName, codeRef)
{
  menuName = menuName.toLowerCase();
  for (i=0; i<_mi.length; i++)
    if (_mi[i][1].replace(/\&nbsp\;/ig,' ') == itemName && _m[_mi[i][0]][1] == menuName) break;
  if (i == _mi.length) return -1;
  return _mi[i][codeRef];
}

There are three parameters:

(1) - menuName is the name of the menu containing the target item.

(2) - itemName is the name of the item whose properties you want to examine. Since the menu system does not assign an internal item name, I use the text that appears in the menu item itself, and so the itemName is given in the text= property of the aI() function that defined the menu item. We're looking for an exact match here, so remember that it is case sensitive, and leading and trailing spaces also count. Speaking of spaces, when calling the function, substitute a normal space in itemName for any &nbsp; in the text property of the item's aI() definition. For example, if your menu item was defined with one or more non-breaking spaces, like so:
Code:
aI("text=Downloads&nbsp;Page;url=downloads.html;");

then the itemName you pass in the function call would still be 'Downloads Page'.

(3) - codeRef is the code reference number for the property you are interested in. You'll find the codeRef for each menu item property in the table on the quick refs page for menu item propertes.

So, if you wanted to get the current url (codeRef = 2) of the "New York Times" menu item, in the "newspapers" menu defined above, you'd call
Code:
url = mm_getItemNameProperty('newspapers','New York Times',2);

The url variable would now contain the string, http://www.nytimes.com/

Hope that helps,

Kevin

Yes!


Poster: Bob Martin
Dated: Tuesday September 7 2004 - 21:43:00 BST

Kevin,

These functions work like a champ. Thanks for all of your help!

Bob


Poster: sbraun
Dated: Friday December 15 2006 - 14:11:48 GMT

Hello Bob & Kevin,

I am trying to use your code from above, but I guess that I don't know how. I don't know enough js to know where I'm going wrong.

I've set up a test page to experiment with the code, but I'm not getting any results.

Can you please take a quick look at my source, which holds your code, and let me know how to implement it properly.

http://faust.blueboxgrid.com/crew/testpage.tpl

Many thanks.
sbraun