Skip to content

Context Menu

Tom Taylor edited this page Dec 15, 2016 · 6 revisions

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.

Adding items

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" 
  }
]);

Displaying the context menu

It's possible to control the visibility of the context menu using the events system.

Show

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]);

Hide

To hide the menu:

Adapt.trigger('contextMenu:closeContextMenu', [VIEW]);

Events

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) { ... });
Clone this wiki locally