--- currentMenu: items --- # Items - [options.items](#optionsitems) - [name](#name) - [callback](#callback) - [className](#classname) - [icon](#icon) - [disabled](#disabled) - [visible](#visible) - [type](#type) - [events](#events) - [value](#value) - [selected](#selected) - [radio](#radio) - [options](#options) - [height](#height) - [items](#items) - [accesskey](#accesskey) The items map contains the commands to list in the menu. Each command has a unique key identifying an item object. The value may either be an item (properties explained below), or a string (which will insert a separator, disregarding the string's content). It is also possible to define a seperator the same as an item, and use the `type`:`cm_seperator` to define it. ```javascript var items = { firstCommand: itemOptions, separator1: "-----", separator2: { "type": "cm_seperator" } command2: itemOptions } ``` ## options.items ### name Specify the human readable name of the command in the menu. This is used as the label for the option. `name`: `string` #### Example ```javascript var items = { firstCommand: { name: "Copy" } } ``` ### callback Specifies the callback to execute if clicked on The Callback is executed in the context of the triggering object. The first argument is the key of the command. The second argument is the options object. The Callback may return false to prevent the menu from being hidden. If no callback and no default callback is specified, the item will not have an action `callback`: `function(itemKey, opt)` #### Example ```javascript var items = { firstCommand: { name: "Copy", callback: function(itemKey, opt){ // Alert the key of the item and the trigger element's id. alert("Clicked on " + itemKey + " on element " + opt.$trigger.id); // Do not close the menu after clicking an item return false; } } } ``` ### className Specifies additional classNames to add to the menu item. Seperate multiple classes by using spaces. `className`: `string` #### Example ```javascript var items = { firstCommand: { name: "Copy", className: 'contextmenu-item-custom contextmenu-item-custom__highlight' } } ``` ### icon Specifies the icon class to set for the item. When using a string icons must be defined in CSS with selectors like `.context-menu-item.context-menu-icon-edit`, where `edit` is the icon class specified. When using a callback you can return a class string to use that as the class on the item. You can also modify the element by using the `$itemElement` argument. `icon`: `string` or `function(opt, $itemElement, itemKey, item)` #### Example ```javascript var items = { firstCommand: { name: "Copy", icon: function(opt, $itemElement, itemKey, item){ // Set the content to the menu trigger selector and add an bootstrap icon to the item. $itemElement.html(' ' + opt.selector); // Add the context-menu-icon-updated class to the item return 'context-menu-icon-updated'; } }, secondCommand: { name: "Paste", icon: "paste" // Class context-menu-icon-paste is used on the menu item. } } ``` ### disabled Specifies if the command is disabled (`true`) or enabled (`false`). May be a callback returning a `boolean`. The callback is executed in the context of the triggering object (so this inside the function refers to the element the context menu was shown for). The first argument is the `key` of the command. The second argument is the `options object`. `disabled`: `string` or `function(itemKey, opt)` #### Example ```javascript var items = { firstCommand: { name: "Copy", disabled: function(key, opt){ // Disable this item if the menu was triggered on a div if(opt.$trigger.nodeName === 'div'){ return true; } } } } ``` ### visible Specifies if the command is visible (`true`) or not (`false`). May be a callback returning a boolean. The callback is executed in the context of the triggering object (so this inside the function refers to the element the context menu was shown for). The first argument is the key of the command. The second argument is the `options object`. `disabled`: `string` or `function(itemKey, opt)` #### Example ```javascript var items = { firstCommand: { name: "Copy", visible: function(key, opt){ // Hide this item if the menu was triggered on a div if(opt.$trigger.nodeName === 'div'){ return false; } } } } ``` ### type Specifies the type of the command. `type`: `null`, `undefined`, `text`, `textarea`, `checkbox`, `radio`, `select`, `html` default: `null` Value | Description ---- | ---- `null`, `undefined` , `""` | The command is a simple clickable item. `"text"` | Makes the command an `` of type `text`.
The name followed by the `` are encapsulated in a `