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:53
how do i use the id property?
Poster: dameat
Dated: Tuesday October 3 2006 - 18:08:21 BST
I see from the changelog that an 'id' property was added for menu items back in August. How does one use that property?
Basically, I am trying to change menu item properties for a specific set of menu items. Thus, I'd like to be able to access a specific menu item, i would assume by its id, and change, say, its text color. However, I'm not sure how I use the id property to access the menu item.
Thanks for any insight...
--Greg
Poster: kevin3442
Dated: Tuesday October 3 2006 - 21:38:13 BST
Hi Greg,
I haven't used it, but I would suppose that you could use it with getElementById(), to get the item object, then manipulate it's styles etc. Alternatively, a function like this might work for you:
Code:
function mm_changeItemPropertyById(itemID, codeRef, newValue, updateDisplay)
{
for (i=0; i<_mi.length; i++) if (_mi[i][103] == itemID) break;
if (i == _mi.length) return;
_mi[i][codeRef] = newValue;
if (updateDisplay) BDMenu(_mi[i][0]);
}
{
for (i=0; i<_mi.length; i++) if (_mi[i][103] == itemID) break;
if (i == _mi.length) return;
_mi[i][codeRef] = newValue;
if (updateDisplay) BDMenu(_mi[i][0]);
}
Put that function at the top of your menu_data.js file. Passed paramters are as follows:
(1) - itemID is the id of the menu item you want to change.
(2) - codeRef is the index or "code reference" of the property that you want to change. Each menu item property has a unique "code reference" number; these numbers are found in the "Code Ref" column of the quick reference table that lists the menu item properties. For example, the codeRef for an item's offbgcolor property is 7, the codeRef for the item's URL property is 2.
(3) - newValue is the new value that you want to assign to the identified menu item property, for the targeted menu item. This might be a numeric or a string value, depending on what type of property you are changing (a color or URL would be a string, widths would be numeric).
(4) - updateDisplay is a boolean indicating that you do (true) or do not (false) want to force an immediate update for display pruposes. You'd typically want to use true for visual properties, like color or size, especially if the menu is already visible when you make the change. You could use false for "behavioral" properties, like openonclick or the URL, things that won't be used until the next time the item is moused over or clicked (using true for these shouldn't hurt, I think, but would cause an additional, probably unnecessary function call).
For example, suppose you have a "Products" menu item like the one defined below. Note that it has been given an id=products (each menu item would have a unique id... no quotes necessary).
Code:
aI("text=Products;id=products;url=whatever.htm;");
Calling the function like so:
Code:
mm_changeItemPropertyById('products', 8, '#000000', true);
would change the item's offcolor (codeRef 8) to black.
Code:
mm_changeItemPropertyById('products', 7, '#ffffff', true);
would change the item's offbgcolor (codeRef 7) to white.
Alternatively, there is a function described here that might be useful. Note, however, that it's been awhile since that function was written... don't know how well it still works.
There is also a plugin called mm_menueditapi.js that you could try. It has functions in it [mm_editItem() and mm_editItemByItemRef()] that will allow you to change multiple properties -- basically the entire item -- all in one function call. Right-click here and select "Save Target As..." to save a copy. The available functions are described in the .js file's comments, at the top.
Hope that helps,
Kevin
Poster: dameat
Dated: Tuesday October 3 2006 - 22:53:59 BST
nope - the 'id' property does not seem to have any effect on the ids for HTML elements, i.e. you can't access the items via getElementById. However, I am able to do what I wanted by writing a function similar to the one you posted, which steps through a set of menu items and compares the id property (103). I was hoping there would be a builtin function or, better yet, an array by which you could access the individual menu items via the id.
Poster: Ruth
Dated: Tuesday October 3 2006 - 22:54:38 BST
Hi,
There is a demo for the function Kevin mentioned. It seems to still work and it uses the newest menu version.
http://support.milonic.com/demos/change ... /index.htm
Ruth