features - demo - documentation
- jQuery >=1.8.2
- jQuery UI position (optional but recommended)
register contextMenu from javascript:
$.contextMenu({
// define which elements trigger this menu
selector: ".with-cool-menu",
// define the elements of the menu
items: {
foo: {name: "Foo", callback: function(key, opt){ alert("Foo!"); }},
bar: {name: "Bar", callback: function(key, opt){ alert("Bar!") }}
}
// there's more, have a look at the demos and docs...
});
have a look at the demos.
Firefox 8 implemented contextmenu using the <menuitem> tags for menu-structure. The specs however state that <command> tags should be used for this purpose. $.contextMenu accepts both.
Firefox 8 does not yet fully implement the contextmenu specification (Ticket #617528). The elements a, button, input and option usable as commands are being ignored altogether. It also doesn't (optically) distinguish between checkbox/radio and regular commands (Bug #705292).
Note: While the specs note <option>s to be renderd as regular commands, $.contextMenu will render an actual <select>. import contextMenu from HTML5 <menu>:
$.contextMenu("html5");
You're (obviously) able to use the context menu with your mouse. Once it is opened, you can also use the keyboard to (fully) navigate it.
- ↑ (up) previous item in list, will skip disabled elements and wrap around
- ↓ (down) next item in, will skip disabled elements and wrap around
- → (right) dive into sub-menu
- ← (left) rise from sub-menu
- ↵ (return) invoke command
- ⇥ (tab) next item or input element, will skip disabled elements and wrap around
- ⇪ ⇥ (shift tab) previous item or input element, will skip disabled elements and wrap around
- ⎋ (escape) close menu
- ⌴ (space) captured and ignore to avoid page scrolling (for consistency with native menus)
- ⇞ (page up) captured and ignore to avoid page scrolling (for consistency with native menus)
- ⇟ (page down) captured and ignore to avoid page scrolling (for consistency with native menus)
- ↖ (home) first item in list, will skip disabled elements
- ↘ (end) last item in list, will skip disabled elements
Besides the obvious, browser also react to alphanumeric key strokes. Hitting r
in a context menu will make Firefox (8) reload the page immediately. Chrome selects the option to see infos on the page, Safari selects the option to print the document. Awesome, right? Until trying the same on Windows I did not realize that the browsers were using the access-key for this. I would've preferred typing the first character of something, say "s" for "save" and then iterate through all the commands beginning with s. But that's me - what do I know about UX? Anyways, $.contextMenu now also supports accesskey handling.
- Björn Brala
- Rodney Rehm (original creator)
- Christiaan Baartse (single callback per menu)
- Addy Osmani (compatibility with native context menu in Firefox 8)
$.contextMenu is published under the MIT license
Font-Awesome icons used from encharm/Font-Awesome-SVG-PNG.