-
Notifications
You must be signed in to change notification settings - Fork 288
Context Menu
The Context Menu module adds the ability to attach an in-situe pop-up menu with a list of arbitrary commands to the different content types (course, menu, page, article, block, component).
For ease of use, the module is accessible from the 'Origin' object.
The addItem
function is used to add further commands to the list, and expects to be passed a [TYPE]
(string), which can be any of: course
, menu
, page
, article
, block
, component
, and [OPTIONS]
(object/array of objects):
Single item:
Origin.contextMenu.addItem('course', {
"text": 'Delete',
"callbackEvent": 'delete'
});
Multiple items
Origin.contextMenu.addItem('block', [
{
"text": "Edit",
"callbackEvent": "edit"
},
{
"text": "Save",
"callbackEvent": "save"
}
]);
It's possible to control the visibility of the context menu using the events system.
To show the menu, you must trigger the open event and pass the view (which is used to determine which menu is shown -- the view.model's type is used for this).
Adapt.trigger('contextMenu:open', [VIEW]);
To hide the menu:
Adapt.trigger('contextMenu:closeContextMenu', [VIEW]);
When a Context Menu item is clicked it triggers an event (string) with the following syntax, and passes the current view to any listener functions.
contextMenu:[type]:[callbackEvent]
An example of a block delete listener:
Adapt.on('contextMenu:block:delete', function(blockView) { ... });