Context Menu API
The Context Menu API allows you to create and manage custom context menus in your plugin. This API provides an easy way to add menus and other contextual interfaces.
Getting Started
To use the Context Menu API in your Acode plugin, first require it:
js
acode.require('contextmenu')
API Reference
Creating a Context Menu
The main function to create a context menu:
js
contextmenu(content, options)
Parameters:
content
: String - The HTML content to show in the menuoptions
: Object - Configuration options (optional)
You can also create a menu with just options:
js
contextmenu(options)
Context Menu Options
The options object accepts these properties:
left
: Number - Left position in pixelstop
: Number - Top position in pixelsbottom
: Number - Bottom position in pixelsright
: Number - Right position in pixelstransformOrigin
: String - CSS transform-origin propertytoggler
: HTMLElement - Element that toggles the menuonshow
: Function - Called when menu is shownonhide
: Function - Called when menu is hiddenitems
: Array - Menu items as [text, action] pairsonclick
: Function - Called when an item is clickedonselect
: Function - Called when an item is selectedinnerHTML
: Function - Returns HTML string for menu content
Menu Methods
The returned menu object has these methods:
show()
- Display the menuhide()
- Hide the menudestroy()
- Remove the menu completely
Basic Example
Here's a simple example of creating and using a context menu:
js
const menu = contextmenu('Menu Content', {
top: 50,
left: 100,
items: [
['Item 1', 'action1'],
['Item 2', 'action2']
],
onselect(action) {
console.log('Selected:', action);
}
});
// Show the menu
menu.show();
// Hide the menu
menu.hide();