logo

/Context Menu|v2.1.9

Class

new ContextMenu(container, options)contextmenu.jsline 58

tui-context-menu creates a menu when the right mouse button is clicked.
To register a context menu, please refer to ContextMenu#register.

PARAMETERS
NameTypeDescription

container

HTMLElement

container for placing context menu floating layers

options

object

options for context menu

PROPERTIES
NameTypeDescription

delay

number = 130

delay for displaying submenu

usageStatistics

boolean = true

Send the hostname to google analytics.
If you do not want to send the hostname, this option set to false.

EXAMPLES
//-- #1. Get Module --//
//ES6
import ContextMenu from 'tui-context-menu';

// CommonJS
const ContextMenu = require('tui-context-menu'); 

// Browser
const ContextMenu = tui.ContextMenu;

//-- #2. Use property --//
const container = document.getElementById('context-menu');
const contextMenu = new ContextMenu(container);

Instance Methods

destroy()contextmenu.jsline 124

Destructor

register(selector, callback, menuItems)contextmenu.jsline 466

Register context menu

PARAMETERS
NameTypeDescription

selector

string

css selector for displaying contextmenu at secondary mouse button click

callback

function

callback for each menu item clicked

menuItems

Array.<MenuItem>

MenuItem schema

EXAMPLES
const contextMenu = new ContextMenu(document.getElementById('context-menu'));

function onClick(ev, cmd) {
  console.log(`${ev.type}ed ${cmd}.`);
}

contextMenu.register('#folder', [
  {title: 'Open'},
  {
    title: 'Create',
    menu: [
      {title: 'a File', cmd: 'Create a file'},
      {title: 'a Folder', cmd: 'Create a folder'}
    ]
  }
]);

// When click 'a File': "Create a file"

unregister(selector)contextmenu.jsline 491

Unregister context menu

PARAMETERS
NameTypeDescription

selector

string

css selector used for register context menu

RETURNS:
{

boolean

} - whether unregister is successful?
Resizable