Currently this is not possible with your code; instead it creates a
new version of the menu each time the menu is activated.
Further, it's not easy to add or delete submenus because you're storing
them as hash elements rather than array elements (so you have to
renumber everything if you want to delete a submenu).
It doesn't have to be that way. Two small changes to the way the
program works would alleviate these problems:
1) If it exists, delete the created menu from the div (or whatever you
have) before you create a new menu. A fast way to do this is to set
innerHTML to "".
2) Instead of using one big hash full of nothing but hashes, use an
array for all the menu elements rather than just numbering some of the
hash elements.
It should be noted that you don't have to use the "new Hash" syntax to
refer to hashes, nor do you have to use "new Array" for arrays. This
piece of code will work perfectly well in javascript, and do what I'm
talking about:
domMenu_data = {"domMenu_main":{"contents":"Home",
"contentsHover":"Home",
"uri":"http://example.com",
"target":"_self",
"statusText","Mojavelinux.com
homepages",
"elements":[
{"contents":"News",
"uri":"http://mojavelinux.com",
"target":"_blank"
"statusText","Latest
mojavelinux.com news"
},
{"contents":"Cooker",
"uri":"http://www.example.com",
"statusText,"Released open source
programs"
}]
}
}
//Accessing a particular element:
alert(domMenu_data.domMenu_main.contents);
//Delete the first menu element:
domMenu_data.domMenu_main.elements[0]=null;
//Alternatively, you could do
"domMenu_data.domMenu_main.elements.shift();"
//Add a new menu element to the end of the array:
domMenu_data.domMenu_main.elements.push({"contents":"Demos",
"uri":"http://www.example.com",
"statusText":"Program demos"
});
Please let me know if you're going to do anything. Your menu tool is
one of the best I've seen and I'd very much like to make use of it.