The context menu is generated when you click the right mouse button on a specific element.
When you select each menu, or click outside of the area where the menu closes.
<html>
<head>
....
<link href="tui-context-menu.css" rel="stylesheet">
</head>
<body>
....
<script type="text/javascript" src="tui-context-menu.min.js"></script>
....
</body>
</html><!-- Notice: The wrapper element must be located below the body. -->
<!-- Tag to create the context menu -->
<div id="tui-context-menu-container"></div>
<!-- Tag to attach the context menu -->
<div id="tui-context-menu-target"></div>var menu = new tui.ContextMenu(document.getElementById('tui-context-menu-container'));- title :
stringEach menu name - command :
stringKey value of each menu (optional) - seperator :
booleanWhether to use menu separators (optional) - menu :
Array.<object>Submenu of each menu (optional)
var menuData = [
{title: 'open'},
{separator: true},
{
title: 'export',
menu: [
{title: 'png'},
{title: 'jpg', command: 'exportToJPG'}
]
}
]function handleClick(e, cmd) {
console.log(cmd); // title or command value of menu data
}- arguments[0] :
stringElement selector to create the context menu - arguments[1] :
functionCallback function for the custom event - arguments[2] :
ArrayMenu data
menu.register(document.getElementById('tui-context-menu-target'), handleClick, menuData);You can see the action from example.
menu.unregister(document.getElementById('tui-context-menu-target'));menu.destroy();