logo

/Context Menu|v2.1.6

Class

new ContextMenu(container, options)contextmenu.jsline 54

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 --//
var ContextMenu = require('tui-context-menu'); // node, commonjs
var ContextMenu = tui.ContextMenu; // distribution file

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

Instance Methods

destroy()contextmenu.jsline 120

Destructor

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

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 489

Unregister context menu

PARAMETERS
NameTypeDescription

selector

string

css selector used for register context menu

RETURNS:
{

boolean

} - whether unregister is successful?
Resizable