C-Menu Example

Left click here!
Left click here or elsewhere to close menu.

Documentation

CMenu.AddButton(id, name, [icon path])
Function will add one item to the menu. Example:
myMenu.AddButton(1,"Push me");
myMenu.AddButton(2,"Push me with Icon", "/img/menu_button.png");

CMenu.AddCheck(id, name, initialSelect, [checkIcons])
Function will add one checkable item to the menu. Example:
myMenu.AddCheck(3,"Play / Pause",false);
myMenu.AddCheck(4,["Play", "Pause"],true);
myMenu.AddCheck(5,["Play", "Pause"],true, 
				["/img/menu_play.png","/img/menu_pause.png"]
				);
myMenu.AddCheck(6,["Yes", "No"],true, 
				["/img/check_yes.png","/img/check_no.png"]
				);

CMenu.AddSeperator()
Adds a horizontal line to the menu.
CMenu.popup(x,y)
Popup the menu at screen position x,y [px]. The following reasons can close the menu: Remarks:
If you use the example below, note that the event-callback "mousedown_callback" must be assigned by addEvent.
Because event handler like <element onclick="mousedown_callback"> or getElementById("test").onclick=mousedown_callback; can't be used to determine correct mouse position.
Example:
function mousedown_callback(evt){
	evt = (evt) ? evt : ((window.event) ? window.event : "");
	var elem = (evt.target) ? evt.target : evt.srcElement;
	// use cross-browser aware function to determine the correct mouse position.
	var pos = extractMouseFromEvent(evt);
	// Popup the menu:
	myMenu.popup(pos.x,pos.y);	
	// Stop event from bubbling
	// That is necessary because the event will bubble up until it reaches
	// the body element. 
	// But body left-click will close all CMenus.
	evt.cancelBubble=true; 
}

CMenu.DeleteById(id)
Delete item with ID id.
bool CMenu.suppressExitItem
Set this value to true to suppress the hard coded item to close the menu. Example:
	myMenu.suppressExitItem = true;

bool CMenu.GetItemById(id)
Returns an Item-Object with following members: Example:
	var item = myMenu.GetItemById(3);
	item.name = "New Name"
	// For Check-Items:
	item.checked = true;