Right click here
LEFT CLICK HERE
www.dynarch.com

Dynamically modify the context menu


    


So what do we have here? This sample shows you how you can dynamically modify the content of the menu, based on a series of factors such as external modifiers (the checkboxes) or the clicked element (right-clicking on "www.dynarch.com" displays an additional submenu "Rate www.dynarch.com" which isn't available otherwise).

For all this we're using a single event handler ("onPopup") which is passed to DynarchMenu.setup. This is a function reference. This function gets called each time a popup is opened, that is, for any popups and regardless the fact that it's a context menu or not. In this function we analize the ID of the popup that is to be displayed, using "this.id", and if that's "main-popup" we make a series of modifications to the menu using the simple JavaScript API described in the MenuItem Object documentation.

The label of the first item is set to the current hour—that will be the time the popup has opened, and the label of the last item will display the content of the element that was actually clicked.