Re[5]: Assign a context menu to a dynamically created HTML eleme
2005/02/04 14:31
Viewed 16196 times
Replies: 1/1

I analyzed your problem in more detail today.  I'm sorry it took so long for the right solution...  Now, here we go.  Define the menu like this:

<ul id="menu">
<li id="context-menu">
The label doesn't matter
<ul>
<li>... context menu</li>
<li>... items</li>
</ul>
</li>
</ul>

So note that I assigned an ID to the LI which holds the context menu contents.  Now, remember a reference to the DynarchMenu object when creating it:

var menu = DynarchMenu.setup("menu", { context: true });

Now we need to create a dynamic element and assign the context menu to it:

var div = document.createElement("div");
...
document.body.appendChild(div);
// this does it:
DynarchMenu.setupContext(div, menu.items["context-menu"]);

So there is actually an API for that :-)  I'm just sorry I forgot about it in the first place, I could have helped you faster.  To the “setupContext” function you need to pass a reference to the HTML element that should get a context menu and the item that holds the context menu--as you can see we can easily retrieve that using the “menu.items” hash, assuming we gave it an ID and have kept a reference to the DynarchMenu object.

Hope this helps.

 
Re[6]: Assign a context menu to a dynamically created HTML eleme
2005/02/04 15:07
Viewed 18221 times
Replies: 0/0
by cclc

Thank you a lot!
It's much better in this way!!! :-)
Best regards!

last
Google