Re: Assign a context menu to a dynamically created HTML element
2005/02/03 15:24
Viewed 8222 times
Replies: 1/5

Well, for now the solution that you found is best. There's another possible workaround--clone the UL element that defines the menu before calling "DynarchMenu.setup(...)" and you can reuse it later. You can clone it with, say, "var clone = document.getElementById("menu").clone(true)" and on subsequent requests call "DynarchMenu.setup(clone)".

We will create a simpler API in the future.

Re[2]: Assign a context menu to a dynamically created HTML eleme
2005/02/03 16:14
Viewed 10239 times
Replies: 1/4
by cclc

Thanks a lot for your prompt reply. Actually I thought on the solution you suggested, but I really don't like to call the "setup" method each time a new element is created, especially when there are a lot of HTML elements in the document that need to be parsed (I imagine a large tree, dynamic, with 2000-3000 nodes, each node having a context menu assigned). I'm thinking on another solution: creating a single element in the document, hidden, standard assigning the context menu using "setup" and, for all dynamic created elements of that type, treat "oncontextmenu" and "onclick" handlers through the similar handlers in the hidden element:
<!--
triggerCtxMenu = function(e, someInfo) {
//do something with "someInfo" like storing it in a global variable for further reference
getElementById("myhiddenelement").onclick(e);
}
<mydynamicelement onclick="triggerCtxMenu(event, 'some info about the element');" >
-->
What do you think about it?

last
Re[3]: Assign a context menu to a dynamically created HTML eleme
2005/02/03 20:53
Viewed 12096 times
Replies: 1/3

You could try the idea but I'm not sure you will be able to determine the element that was actually clicked on in your handler.

last
Google