Popup menu is no different to the regular drop down menu except the menu is displayed upon user click on element which trigger the menu. With NlsMenu you not only can create a standard popup menu but also create context sensitive menu. To use the NlsMenu as popup menu (context menu):
<script>
//menu on onclick event handler.
function menuClick(menuId, itemId) {
alert("Clicked Menu: " + menuId + ", item: " + itemId);
}
//display the popup menu.
function showPopupMenu(e) {
menuMgr.hideMenus();
main.showMenu(e.clientX, e.clientY, e.clientX, e.clientY, "", null);
}
</script>
<script>
var menuMgr = new NlsMenuManager("mgr");
//create the popup menu.
var main = menuMgr.createMenu("main");
main.addItem("1", "Add New", "");
main.addItem("2", "Edit", "");
main.addItem("3", "Delete", "");
main.addItem("4", "Insert ", "");
main.addSeparator();
main.addItem("5", "Others", "");
//set the menu onclick handler.
main.menuOnClick=menuClick;
</script>
<body>
...
<span onmousedown="showPopupMenu(event)" oncontextmenu="return false;">Click me to show the context menu!</span>
...
</body>
Useful function when working with context menu
For complete working context menu example, please see the context menu example in the menu package. |