forked from swisnl/jQuery-contextMenu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docs.html
executable file
·576 lines (506 loc) · 29.4 KB
/
docs.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
<head>
<meta charset="utf-8" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>jQuery contextMenu Plugin</title>
<meta name="description" content="simple contextMenu generator for interactive web applications based on jQuery" />
<script src="jquery-1.8.2.min.js" type="text/javascript"></script>
<script src="prettify/prettify.js" type="text/javascript"></script>
<script src="screen.js" type="text/javascript"></script>
<link href="screen.css" rel="stylesheet" type="text/css" />
<link href="prettify/prettify.sunburst.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-8922143-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body>
<a id="github-forkme" href="https://github.com/medialize/jQuery-contextMenu"><img src="http://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub" /></a>
<div id="container">
<h1><a href="https://github.com/medialize/jQuery-contextMenu">jQuery contextMenu</a></h1>
<ul class="menu">
<li><a href="index.html">About</a></li>
<li><a href="demo.html">Demo</a></li>
<li class="active"><a href="docs.html">Documentation</a></li>
<li><a href="http://rodneyrehm.de/en/">Author</a></li>
</ul>
<ul class="toc">
<li>
<a href="#register">Register new contextMenu</a>
<ul>
<li><a href="#options">options (at registration)</a></li>
<li><a href="#items">options.items</a></li>
<li><a href="#opt">opt (options at runtime)</a></li>
<li><a href="#types">Custom Command Types</a></li>
</ul>
</li>
<li><a href="#disable-trigger">Disable a contextMenu trigger</a></li>
<li><a href="#enable-trigger">Enable a contextMenu trigger</a></li>
<li><a href="#show-trigger">Manually show a contextMenu</a></li>
<li><a href="#hide-trigger">Manually hide a contextMenu</a></li>
<li><a href="#unregister-contextMenu">Unregister contextMenu</a></li>
<li><a href="#unregister-all">Unregister all contextMenus</a></li>
<li><a href="#helper-import-values">Helper: Import values for <input></a></li>
<li><a href="#helper-export-values">Helper: Export values from <input></a></li>
<li><a href="#events">Events</a></li>
<li><a href="#html5-import">HTML5 <menu> import</a></li>
<li><a href="#html5-shiv">HTML5 <menu> shiv/polyfill</a></li>
<li><a href="#ui-position">$.ui.position</a></li>
</ul>
<h2 id="register">Register new contextMenu</h2>
<p>To register a new contextMenu:</p>
<pre class="prettyprint lang-js">$.contextMenu( options );</pre>
<h3 id="options">options (at registration)</h3>
<dl>
<dt id="options-selector"><em>(string)</em> selector</dt>
<dd>
<p>No Default Value - specification is Mandatory</p>
<p>The selector matching the trigger objects.</p>
<p>Example: <code>"span.with-context"</code>.</p>
</dd>
<dt id="options-items"><em>(object)</em> items</dt>
<dd>
<p>No Default Value - specification is Mandatory</p>
<p>Items to be listed in contextMenu. See <a href="#items">Items</a>.</p>
<p>Example: <code>{ one: {name: "one", callback: function(key, opt){ alert("Clicked on " + key); } }}</code></p>
</dd>
<dt id="options-appendTo"><em>(selector | DOMElement)</em> appendTo</dt>
<dd>
<p>default: document.body</p>
<p>Specifies the DOMElement the generated menu is to be appended to</p>
<p>Example: <code>"#context-menus-container"</code>.</p>
</dd>
<dt id="options-trigger"><em>(string)</em> trigger</dt>
<dd>
<p>default: <em>"right"</em></p>
<p>Specifies the event to show the contextMenu</p>
<p>Possible values: "right", "left", "hover", "none"</p>
</dd>
<dt id="options-reposition"><em>(boolean)</em> reposition</dt>
<dd>
<p>
Specifies if a menu should be repositioned (true) or rebuilt (false) if a second trigger event (like a right click) is performed
on the same trigger element (or its children) while the menu is still visible.
</p>
</dd>
<dt id="options-delay"><em>(int)</em> delay</dt>
<dd>
<p>default: <em>200</em></p>
<p>Specifies the time in milliseconds to wait before showing the menu. Only applies to <code>trigger: "hover"</code></p>
</dd>
<dt id="options-autohide"><em>(boolean)</em> autoHide</dt>
<dd>
<p>default: <em>false</em></p>
<p>Specifies if the menu must be hidden when the mouse pointer is moved out of the trigger and menu elements</p>
</dd>
<dt id="options-zIndex"><em>(int)</em> zIndex</dt>
<dd>
<p>default: <em>1</em></p>
<p>Specifies the offset to add to the calculated zIndex of the trigger element. Set to <em>0</em> to prevent zIndex manipulation</p>
</dd>
<dt id="options-className"><em>(string)</em> className</dt>
<dd>
<p>Specifies additional classNames to add to the menu element</p>
</dd>
<dt id="options-animation"><em>(object)</em> animation</dt>
<dd>
<p>default: <em>{duration: 500, show: "slideDown", hide: "slideUp"}</em></p>
<p>
animation properties take effect on showing and hiding the menu.
<em>duration</em> specifies the duration of the animation in milliseconds.
<em>show</em> and <em>hide</em> specify jQuery methods to show and hide elements.
</p>
<p>Possible show and hide animations: <code>{show: "show", hide: "hide"}</code>, <code>{show: "fadeIn", hide: "fadeOut"}, …</code>
</dd>
<dt id="options-events"><em>(object)</em> events</dt>
<dd>
<p>The show and hide events are triggered before the menu is shown or hidden.</p>
<p>The event handlers are executed in the context of the triggering object. <em>this</em> will thus reference the jQuery handle of the trigger object.</p>
<p>A reference to the current <a href="#opt">options</a> object is passed</p>
<p>The event handlers may return <em>false</em> to prevent the show or hide process.</p>
<p>Example: <code>{show: function(opt){ this.addClass('currently-showing-menu'); alert("Selector: " + opt.selector); }}</code></p>
</dd>
<dt id="options-position"><em>(function)</em> position</dt>
<dd>
<p>Position the context menu.</p>
<p>The function is executed in the context of the trigger object.</p>
<p>The first argument ist the <em>$menu</em> jQuery object</p>
<p>The second and third arguments are <em>x</em> and <em>y</em> coordinates provided by the showing event</p>
<p><em>x</em> and <em>y</em> may either be integers denoting the offset from the top left corner, undefined, or the string "maintain". If the string "maintain" is provided, the current position of the <em>$menu</em> must be used. If the coordinates are undefined, appropriate coordinates must be determined. An example of how this can be achieved is provided with <a href="#options-determinePosition">determinePosition</a>.</p>
<p>Example: <code>{position: function(opt, x, y){opt.$menu.css({top: 123, left: 123});}}</code></p>
</dd>
<dt id="options-determinePosition"><em>(function)</em> determinePosition</dt>
<dd>
<p>Determine the position of the menu in respect to the given trigger object.</p>
<p>Hint: <a href="http://docs.jquery.com/UI/Position">jQuery UI's position()</a> may ease things up.</p>
<p>Example: <code>$menu.css('display', 'block').position({ my: "center top", at: "center bottom", of: this, offset: "0 5"}).css('display', 'none');</code></p>
</dd>
<dt id="options-callback"><em>(function)</em> callback</dt>
<dd>
<p>Specifies the default callback to be used in case an item does not expose its own callback.</p>
<p>The default callback behaves just like <a href="#items-callback">item.callback</a>.</p>
<p>Example: <code>{callback: callback: function(key, opt){ alert("Clicked on " + key + " on element " + opt.$trigger.attr("id")); }}</code></p>
</dd>
<dt id="options-build"><em>(function)</em> build</dt>
<dd>
<p>Callback that's supposed to return the <em>options</em> object on demand</p>
<p>The callback is executed with two arguments given: the jQuery reference to the triggering element and the original contextemnu event.
It is executed without context (so this won't refer to anything useful).</p>
<p>If the <em>build</em> callback is found at registration, the menu is not built right away. The menu creation is delayed to the point where the menu is actually called to show. Dynamic menus don't stay in the DOM. After a menu created with <em>build</em> is hidden, its DOM-footprint is destroyed.</p>
<p>With <em>build</em>, only the options <a href="#options-selector">selector</a> and <a href="#options-trigger">trigger</a> may be specified in the
options object. All other options need to be returned from the <em>build</em> callback.</p>
<p>the <em>build</em> callback may return a boolean <em>false</em> to signal contextMenu to not display a context menu</p>
<pre class="prettyprint lang-js">{selector: ".awesome-menu",
build: function($trigger, e){
return {
callback: function(){},
items: {
foo: {name: "Foo"}
}
};
}};</pre>
</dd>
</dl>
<h3 id="items">options.items</h3>
<p>The <em>items</em> 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).</p>
<pre class="prettyprint lang-js">var items = {
command1: commandOptions,
separator1: "-----",
command2: commandOptions
}</pre>
<dl>
<dt id="items-name"><em>(string)</em> name</dt>
<dd>
<p>Specified the human readable name of the command in the menu</p>
<p>This is a mandatory property</p>
</dd>
<dt id="items-callback"><em>(function)</em> callback</dt>
<dd>
<p>Specifies the callback to execute if clicked on</p>
<p>
The Callback is executed in the context of the triggering object.
The first argument is the <em>key</em> of the command.
The second argument is the <a href="#opt">options</a> object.
The Callback may return <em>false</em> to prevent the menu from being hidden.
</p>
<p>Example: <code>{ command1: {name: "Foobar", callback: function(key, opt){ alert("Clicked on " + key + " on element " + opt.$trigger.id); } }}</code></p>
<p>If no callback and no <a href="#options-callback">default callback</a> is specified, the item will not have an action</p>
</dd>
<dt id="items-className"><em>(string)</em> className</dt>
<dd>
<p>Specifies additional classNames to add to the item element</p>
</dd>
<dt id="items-icon"><em>(string)</em> icon</dt>
<dd>
<p>Specifies the icon class to set for the item.</p>
<p>Icons must be defined in CSS with selectors like <code>.context-menu-item.icon-<em>edit</em></code>, where <em>edit</em> is the icon class.</p>
</dd>
<dt id="items-disabled"><em>(function|boolean)</em> disabled</dt>
<dd>
<p>Specifies if the command is disabled (<em>true</em>) or enabled (<em>false</em>).</p>
<p>
May be a callback returning a boolean.
The Callback is executed in the context of the triggering object (so <code>this</code> inside the function refers to the element the context menu was shown for).
The first argument is the <em>key</em> of the command.
The second argument is the <a href="#opt">options</a> object.
</p>
<p>Example: { command1: {name: "Foobar", callback: function(key, opt){ return true; } }}</p>
</dd>
<dt id="items-type"><em>(string)</em> type</dt>
<dd>
<p>Specifies the type of the command.</p>
<p><em>null</em>, <em>undefined</em> and the <em>empty-string</em> make the command a simple clickable item.</p>
<p><em>"text"</em> makes the command an <input> of type text. The name followed by the <input> are encapsulated in a <label>.</p>
<p><em>"textarea"</em> makes the command a <textarea>. The name followed by the <input> are encapsulated in a <label>.</p>
<p><em>"checkbox"</em> makes the command an <input> of type checkbox. The name preceeded by the <input> are encapsulated in a <label>. The checkbox-element is moved to the icon space</p>
<p><em>"radio"</em> makes the command an <input> of type radio. The name preceeded by the <input> are encapsulated in a <label>. The radio-element is moved to the icon space</p>
<p><em>"select"</em> makes the command a <select>. The name followed by the <select> are encapsulated in a <label>.</p>
<p><em>"html"</em> makes an non-command element.</p>
</dd>
<dt id="items-events"><em>(object)</em> events</dt>
<dd>
<p>Events to register on <input> elements</p>
<p>Only used with <a href="#items-type">types</a> <em>"text"</em>, <em>"textarea"</em>, <em>"radio"</em>, <em>"checkbox"</em> and <em>"select"</em>.</p>
<p>Example: { command1: {name: "Foobar", type: "text", events: {keyup: function(e){alert(e.keyCode);}} }}</p>
<p>The contents of the options object are passed to jQuery event.data.</p>
<p>Example: { command1: {name: "Foobar", type: "text", events: {keyup: function(e){alert(e.data.$trigger.attr("id"));}} }}</p>
</dd>
<dt id="items-value"><em>(string)</em> value</dt>
<dd>
<p>The value of the <input> element.</p>
<p>Only used with <a href="#items-type">types</a> <em>"text"</em>, <em>"textarea"</em> and <em>"radio"</em>.</p>
</dd>
<dt id="items-selected"><em>(string|boolean)</em> selected</dt>
<dd>
<p>The selected option of a <select> element and the checked property for <em>"checkbox"</em> and <em>"radio"</em> types.</p>
<p>Expecting a boolean when used with <a href="#items-type">types</a> <em>"checkbox"</em> and <em>"radio"</em>.</p>
<p>Expecting a string when used with <a href="#items-type">type</a> <em>"select"</em></p>
</dd>
<dt id="items-radio"><em>(string)</em> radio</dt>
<dd>
<p>Specifies the group of the radio elements.</p>
<p>Only used with <a href="#items-type">type</a> <em>"radio"</em>.</p>
</dd>
<dt id="items-options"><em>(object)</em> options</dt>
<dd>
<p>Specifies the <option>s for the <select> element.</p>
<p>Only used with <a href="#items-type">type</a> <em>"select"</em>.</p>
<p>Example: <code>{name: "select box", selected: "two", options: {one: "red", two: "blue", three: "green"}}</code></p>
</dd>
<dt id="items-height"><em>(int)</em> height</dt>
<dd>
<p>The height in pixel <textarea> element. If not specified, the height is defined by CSS.</p>
<p>Only used with <a href="#items-type">type</a> <em>"textarea"</em>.</p>
</dd>
<dt id="items-items"><em>(object)</em> items</dt>
<dd>
<p>Commands to show in a sub-menu.</p>
</dd>
<dt id="items-accesskey"><em>(string)</em> accesskey</dt>
<dd>
<p>Character(s) to be used as accesskey.</p>
<p>
Considering »a b c« $.contextMenu will first try to use »a« as the accesskey, if already taken, it'll fall through to »b«.
Words are reduced to the first character, so »hello world« is treated as »h w«.
</p>
<p>
Note: Accesskeys are treated unique throughout one menu. This means an item in a sub-menu can't
occupy the same accesskey as an item in the main menu.
</p>
</dd>
<dt id="items-node"><em>(jQuery)</em> $node</dt>
<dd>
<p>Reference to the <li> command element</p>
<p>created by contextMenu on registration</p>
</dd>
<dt id="items-input"><em>(jQuery)</em> $input</dt>
<dd>
<p>Reference to the <input> or <select> of the command element.</p>
<p>Only available with <a href="#items-type">type</a> <em>"text"</em>, <em>"textarea"</em>, <em>"checkbox"</em>, <em>"radio"</em> and <em>"select"</em>.</p>
<p>created by contextMenu on registration</p>
</dd>
<dt id="items-label"><em>(jQuery)</em> $label</dt>
<dd>
<p>Reference to the <label> of the command element</p>
<p>Only available with <a href="#items-type">type</a> <em>"text"</em>, <em>"textarea"</em>, <em>"checkbox"</em>, <em>"radio"</em> and <em>"select"</em>.</p>
<p>created by contextMenu on registration</p>
</dd>
<dt id="items-node"><em>(jQuery)</em> $menu</dt>
<dd>
<p>Reference to the <ul> sub-menu element</p>
<p>created by contextMenu on registration</p>
</dd>
</dl>
<h3 id="opt">opt (options at runtime)</h3>
<p><em>opt</em> is a reference to the <em>options</em> object passed at contextMenu registration</p>
<dl>
<dt id="opt-trigger"><em>(jQuery)</em> $trigger</dt>
<dd>
<p>The element triggering the menu</p>
</dd>
<dt id="opt-menu"><em>(jQuery)</em> $menu</dt>
<dd>
<p>The menu element</p>
</dd>
<dt id="opt-callbacks"><em>(object)</em> callbacks</dt>
<dd>
<p>Registered callbacks of all commands (including those of sub-menus)</p>
</dd>
<dt id="opt-commands"><em>(object)</em> commands</dt>
<dd>
<p>Registered commands (including those of sub-menus)</p>
</dd>
<dt id="opt-inputs"><em>(object)</em> inputs</dt>
<dd>
<p>Registered commands of input-type (including those of sub-menus)</p>
<p>Access a specific <input>: <code>opt.inputs[key].$input</code></p>
</dd>
<dt id="opt-hasTypes"><em>(boolean)</em> hasTypes</dt>
<dd>
<p>flag denoting if the menu contains input elements</p>
</dd>
<dt id="opt-ns"><em>(string)</em> ns</dt>
<dd>
<p>The namespace (including leading dot) all events for this contextMenu instance were registered under</p>
</dd>
</dl>
<h3 id="types">Custom Command Types</h3>
<p>Besides the built-in <a href="#items-type">command types</a> custom handlers can be defined.
The command generator must be placed in <code>$.contextMenu.types</code>. It is identified
by the key given in that object. The generator function is executed in the context of the
new command's <li> within the menu. <code>item</code> is the object passed at creation.
Use this to pass values from your definition to the generator. <code>opt</code> is the current
menu level, <code>root</code> is the menu's root-level <code>opt</code> (relevant for sub-menus only).
</p>
<p>
A custom command type can be whatever you like it to be, it can behave how ever you want it to behave.
Besides the keyboard interaction paradigm (up, down, tab, escape) key-events are passed on to the
<li> which can be accessed via <code>$(this).on('keydown', …);</code>
</p>
<p>
Note that you'll probably want to disable default action handling (click, pressing enter) in favor of
the custom command's behavior.
</p>
<pre class="prettyprint lang-js">$.contextMenu.types.myType = function(item, opt, root) {
$('<span>' + item.customName + '</span>').appendTo(this);
this.on('contextmenu:focus', function(e) {
// setup some awesome stuff
}).on('contextmenu:blur', function(e) {
// tear down whatever you did
}).on('keydown', function(e) {
// some funky key handling, maybe?
});
};
$.contextMenu({
selector: '.context-menu-custom',
items: {
label: {type: "myType", customName: "Foo Bar"}
}
});</pre>
<h2 id="disable-trigger">Disable a contextMenu trigger</h2>
<p>disable contextMenu to be shown on specified trigger elements</p>
<pre class="prettyprint lang-js">$(".some-selector").contextMenu(false);</pre>
<h2 id="enable-trigger">Enable a contextMenu trigger</h2>
<p>enable contextMenu to be shown on specified trigger elements</p>
<pre class="prettyprint lang-js">$(".some-selector").contextMenu(true);</pre>
<h2 id="show-trigger">Manually show a contextMenu</h2>
<p>show the contextMenu of the first element of the selector (position determined by <a href="#options-determinePosition">determinePosition</a>):</p>
<pre class="prettyprint lang-js">$(".some-selector").contextMenu();</pre>
<pre class="prettyprint lang-js">$(".some-selector").contextMenu({x: 123, y: 123});</pre>
<h2 id="hide-trigger">Manually hide a contextMenu</h2>
<p>hide the contextMenu of the first element of the selector:</p>
<pre class="prettyprint lang-js">$(".some-selector").contextMenu("hide");</pre>
<h2 id="unregister-contextMenu">Unregister contextMenu</h2>
<p>To unregister / destroy a specific contextMenu:</p>
<pre class="prettyprint lang-js">$.contextMenu( 'destroy', <em>selector</em> );</pre>
<p><em>selector</em> expects the (string) selector that the contextMenu was registered to</p>
<h2 id="unregister-all">Unregister all contextMenus</h2>
<p>To unregister / destroy all contextMenus:</p>
<pre class="prettyprint lang-js">$.contextMenu( 'destroy' );</pre>
<h2 id="helper-import-values">Helper: Import values for <input></h2>
<p>To fill input commands with values from a map:</p>
<pre class="prettyprint lang-js">{events: {
hide: function(opt){
$.contextMenu.getInputValues(opt, {command1: "foo", command2: "bar"});
}
}
}</pre>
<p>To fill input commands with values from data-attributes:</p>
<pre class="prettyprint lang-js">{events: {
hide: function(opt){
$.contextMenu.getInputValues(opt, this.data());
}
}
}</pre>
<h2 id="helper-export-values">Helper: Export values from <input></h2>
<p>To fetch values from input commands:</p>
<pre class="prettyprint lang-js">{events: {
hide: function(opt){
var values = $.contextMenu.setInputValues(opt}
}
}</pre>
<p>To save values from input commands to data-attributes:</p>
<pre class="prettyprint lang-js">{events: {
hide: function(opt){
$.contextMenu.setInputValues(opt, this.data()); }
}
}</pre>
<h2 id="events">Events</h2>
<dl>
<dt>contextmenu</dt>
<dd>
<p>Trigger context menu to be shown for a trigger object.</p>
<p>Available on <em>trigger object</em>. The Event must be supplied with coordinates for the menu: <code>{pageX: 123, pageY:123}</code></p>
<pre class="prettyprint lang-js">$('.context-menu-one').first().trigger(
$.Event('contextmenu', {pageX: 123, pageY: 123})
);</pre>
<pre class="prettyprint lang-js">$('.context-menu-one').first().trigger("contextmenu");</pre>
<p>will invoke <a href="#options-determinePosition">determinePosition</a> to position the menu</p>
</dd>
<dt>prevcommand</dt>
<dd>
<p>Select / highlight the previous possible command</p>
<p>Available on <em>context menu</em>.</p>
<pre class="prettyprint lang-js">opt.$menu.trigger("prevcommand");</pre>
</dd>
<dt>nextcommand</dt>
<dd>
<p>Select / highlight the next possible command</p>
<p>Available on <em>context menu</em>.</p>
<pre class="prettyprint lang-js">opt.$menu.trigger("nextcommand");</pre>
</dd>
<dt>contextmenu:hide</dt>
<dd>
<p>Hide the menu</p>
<p>Available on <em>context menu</em>.</p>
<pre class="prettyprint lang-js">opt.$menu.trigger("contextmenu:hide");</pre>
</dd>
<dt>contextmenu:focus</dt>
<dd>
<p>React to a command item being focused</p>
<p>Triggered on <em>context menu item</em> when mouse or keyboard interaction lead to a "hover state" for that command item.</p>
<pre class="prettyprint lang-js">$(document.body).on("contextmenu:focus", ".context-menu-item",
function(e){ console.log("focus:", this); });</pre>
</dd>
<dt>contextmenu:blur</dt>
<dd>
<p>Available on each <em>context menu item</em>.</p>
<p>Triggered on <em>context menu item</em> when mouse or keyboard interaction lead from a "hover state" to "default state" for that command item.</p>
<pre class="prettyprint lang-js">$(document.body).on("contextmenu:blur", ".context-menu-item",
function(e){ console.log("blur:", this); });</pre>
</dd>
<dt>keydown</dt>
<dd>
<p>Available on each <em>context menu item</em>.</p>
<p>Triggered on <em>context menu item</em> when keyboard interaction could not be handled by jQuery.contextMenu.</p>
<pre class="prettyprint lang-js">$(document.body).on("keydown", ".context-menu-item",
function(e){ console.log("key:", e.keyCode); });</pre>
</dd>
</dl>
<h2 id="html5-import">HTML5 <menu> import</h2>
<p>considering the following HTML <code>$.contextMenu.fromMenu($('#html5menu'))</code> will return a proper <a href="#items">items</a> object
<pre class="prettyprint lang-html"><menu id="html5menu" type="context" style="display:none">
<command label="rotate" onclick="alert('rotate')">
<command label="resize" onclick="alert('resize')">
<menu label="share">
<command label="twitter" onclick="alert('twitter')">
<hr>
<command label="facebook" onclick="alert('facebook')">
</menu>
</menu></pre>
<p><code>$.contextMenu.fromMenu()</code> will properly import (and thus handle) the following elements. Everything else is imported as <code>{type: "html"}</code></p>
<ul>
<li><menu></li>
<li><hr></li>
<li><a></li>
<li><command type="command|radio|checkbox"> (W3C Specification)</li>
<li><menuitem type="command|radio|checkbox"> (Firefox 8)</li>
<li><input type="text|radio|checkbox"></li>
<li><select></li>
<li><textare></li>
<li><label for="someId"></li>
<li><label> the text <input|textarea|select></li>
</ul>
<p>The <menu> must be hidden but not removed, as all command events (clicks) are passed-thru to the original command element!</p>
<p>Note: While the specs note <option>s to be renderd as regular commands, $.contextMenu will render an actual <select>.</p>
<h2 id="html5-shiv">HTML5 <menu> shiv/polyfill</h2>
<p>Engaging the HTML5 polyfill (ignoring $.contextMenu if context menus are available natively):</p>
<pre class="prettyprint lang-js">$(function(){ $.contextMenu("html5"); });</pre>
<p>Engaging the HTML5 polyfill (ignoring browser native implementation):</p>
<pre class="prettyprint lang-js">$(function(){ $.contextMenu("html5", true); });</pre>
<h2 id="ui-position">$.ui.position</h2>
<p>
The <a href="http://jqueryui.com/demos/position/">position utility of jQuery UI</a> makes relative positioning very simple. But the real beauty is <em>collision detection</em>,
allowing the contextMenu to be shown to the left side of the pointer, if there's not enough space to the right.
Its use is optional, if you want to shape off some more bytes by sacrificing usability: go ahead…
</p>
</div>
</body>
</html>