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?
Need To Access Menu Item's Attributes
-
- Advanced
- Posts: 26
- Joined: Tue Nov 18, 2003 9:54 pm
See if either of these will help...
http://milonic.com/menu_methods.php
http://milonic.com/menu_variables.php
http://milonic.com/menu_methods.php
http://milonic.com/menu_variables.php
John
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
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
-
- Advanced
- Posts: 26
- Joined: Tue Nov 18, 2003 9:54 pm
Hi Bob,
Getting a Property Setting by Item Number
Here's a function:
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:
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:
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.
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 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:
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
The url variable would now contain the string, http://www.nytimes.com/
Hope that helps,
Kevin
Here area couple of functions that will let you get the curernt setting of any property, in any item, within any menu.Bob Martin wrote:...Initially I only want to retrieve a menu item's attributes, ...
Getting a Property Setting by Item Number
Here's a function:
Code: Select all
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];
}
(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: Select all
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/");
}
Code: Select all
title = mm_getItemNumberProperty('newspapers',2,1);
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: Select all
function mm_getItemNameProperty(menuName, itemName, codeRef)
{
menuName = menuName.toLowerCase();
for (i=0; i<_mi.length; i++)
if (_mi[i][1].replace(/\ \;/ig,' ') == itemName && _m[_mi[i][0]][1] == menuName) break;
if (i == _mi.length) return -1;
return _mi[i][codeRef];
}
(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 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: Select all
aI("text=Downloads 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: Select all
url = mm_getItemNameProperty('newspapers','New York Times',2);
Hope that helps,
Kevin
-
- Advanced
- Posts: 26
- Joined: Tue Nov 18, 2003 9:54 pm
Yes!
Kevin,
These functions work like a champ. Thanks for all of your help!
Bob
These functions work like a champ. Thanks for all of your help!
Bob
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
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