A context menu is a menu that with several types of options and actions
var contextMenu = new thinkmap.contextmenu.ContextMenu();
contextMenu.item('center',"Make Center").onshow(function(evt) {
// only make the item visible if an entity exists
this.visible(!!evt.entity);
}).onaction(function(evt){
// call this function when the user selects this menu option
makeCenter(evt.entity);
});
contextMenu.item('expand',"Expand").onshow(function(evt) {
this.visible(!!evt.entity && evt.entity.isType('node'));
// change text of the item depending on if the entity is already
// expanded or collapsed
this.item(evt.entity.isExpanded ? 'Expand this!' : 'Collapse this!');
}).onaction(function(evt) {
// take the appropriate action depending on if the entity is
// expanded or collapsed
if (evt.entity.isExpanded) {
collapse(evt.entity);
delete evt.entity.isExpanded;
} else {
expand(evt.entity);
evt.entity.isExpanded = true;
}
});
display.contextMenu(contextMenu); // bind menu to the display
Constructs a new ContextMenu which can then be added to a display to provide a menu with series of options and actions.
var contextMenu = new thinkmap.contextmenu.ContextMenu();
contextMenu.item('center',"Make Center").onshow(function(evt) {
// only make the item visible if an entity exists
this.visible(!!evt.entity);
}).onaction(function(evt){
// call this function when the user selects this menu option
makeCenter(evt.entity);
});
contextMenu.item('expand',"Expand").onshow(function(evt) {
this.visible(!!evt.entity && evt.entity.isType('node'));
// change text of the item depending on if the entity is already
// expanded or collapsed
this.item(evt.entity.isExpanded ? 'Expand this!' : 'Collapse this!');
}).onaction(function(evt) {
// take the appropriate action depending on if the entity is
// expanded or collapsed
if (evt.entity.isExpanded) {
collapse(evt.entity);
delete evt.entity.isExpanded;
} else {
expand(evt.entity);
evt.entity.isExpanded = true;
}
});
display.contextMenu(contextMenu); // bind menu to the display
Hides this menu.
the event be dispatched to any 'hide' event listeners on the menu
Constructs or returns the menu item with the unique given code. This is the primary method used for constructing new menu options which can then be configured.
Show this menu, passing along an event object.
Traditionally context menus are associated with displays, but this doesn't have to be the case. They can be used with any element and a custom event. The event is passed along to the individual items that can make use of it.
the event associated with showing this menu. This is required.
Add a listener to this EventSource
the name of the event to listen for
the callback to add
this eventsource
Dispatch an event from this EventSource, supplying arguments to the listeners via an Array, rather than var-args.
the name of the event to dispatch
this EventSource
Dispatch an event from this EventSource
the name of the event to dispatch
optional arguments sent to the event listeners
this EventSource
Fire an event from this EventSource
the name of the event to dispatch
optional arguments sent to the event listeners
this EventSource
Remove a listener from this EventSource
the name of the event to remove the listener for
the callback to remove
this eventsource
Add a listener to this EventSource
the name of the event to listen for
the callback
this eventsource
Add a listener to this EventSource, which will be called at most once and will be removed the first time the given event fires.
the name of the event to listen for
the callback to add
this eventsource
Remove a listener from this EventSource
the name of the event to remove the listener for
the callback to remove
this eventsource
this event is fired when the the menu has become hidden
this event is fired when the menu is about to be shown
this event is fired when the user selects an action on the menu