Skip to main content

Context Menu

OBR.contextMenu

A context menu is shown when an item is selected, this API allows you to extend that menu with custom buttons.

Reference

Methods

create

async create(contextMenu)

Create a context menu item.

Parameters

NAMETYPEDESCRIPTION
contextMenuContextMenuItemThe context menu item to create

remove

async remove(id)

Remove a context menu item.

Parameters

NAMETYPEDESCRIPTION
idstringThe ID of the context menu to remove

Type Definitions

ContextMenuItem

A single context menu item.

TYPE
object

Properties

NAMETYPEDESCRIPTION
idstringThe ID of this context menu item
iconsContextMenuIcon[]An array of icons to use
onClickContextMenuClickHandlerA callback function triggered when the context menu item is clicked
shortcutstringAn optional key combination to use as a shortcut
embedContextMenuEmbedAn optional embedded url to provide custom controls in the context menu

ContextMenuIcon

An icon for a context menu item.

TYPE
object

Properties

NAMETYPEDESCRIPTION
iconstringThe url of the icon as either a relative or absolute path
labelstringThe label to use for the tooltip of the icon
filterContextMenuIconFilterAn optional filter to control when this icon will be shown

ContextMenuIconFilter

A filter to control when an icon will be shown. If this filter returns true then this icon will be shown. If no filter returns true then the context menu item won't be shown.

TYPE
object

Properties

NAMETYPEDESCRIPTION
minnumberAn optional minimum number of items selected, defaults to 1
maxnumberAn optional maximum number of items selected
permissions("UPDATE" | "DELETE" | "CREATE" | Permission)[]An optional array of permissions needed for the selected items, defaults to no permissions needed
roles("GM" | "PLAYER")[]An optional array of roles needed for the player, defaults to no role needed
everyKeyFilter[]An optional array of filters to run on the selected items. Every item must pass this filter for a success
someKeyFilter[]An optional array of filters to run on the selected items. Only one item must pass this filter for a success

ContextMenuClickHandler

A callback when a context menu item is clicked.

TYPE
function

Parameters

NAMETYPEDESCRIPTION
contextContextMenuContextThe context for this menu
elementIdstringThe ID of the button clicked

ContextMenuContext

The context for a menu item.

TYPE
object

Properties

NAMETYPEDESCRIPTION
itemsItem[]An array of Items that are currently selected
selectionBoundsBoundingBoxA bounding box for the current selection

ContextMenuEmbed

An embedded view in the context menu popup.

TYPE
object

Properties

NAMETYPEDESCRIPTION
urlstringThe url of the site to embed
heightnumberAn optional height of the embed in pixels