$.contextMenu is a management facility for - you guessed it - context menus. It was designed for an application where there are hundreds of elements that may show a context menu - so intialization speed and memory usage are kept fairly small. It also allows to register context menus without providing actual markup, as $ .contextMenu generates DOMElements as needed.
features - demo - documentation
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(e, key, currentMenuData){ alert("Foo!"); }}, bar: {name: "Bar", callback: function(e, key, currentMenuData){ alert("Bar!") }} } // there's more, have a look at the demos and docs... });
have a look at the demos.
Version 3.0 is a restructure of the javascript into something more sane written in ES6. It consolidates all API's so callbacks are better documented and more concise. The basics are still the same, but all callbacks are structured differently.
The goal of this refactor was mostly to make the ContextMenu easier to maintain, and make the API's more consise. It also adds JSdoc comments so the API documentation is generated from the code and it enables code completion.
Code coverage is also introduced in the test suite.
If you really want you can also use the ContextMenu class to instantiate the menu objects instead of the jQuery calls. It still requires jQuery to function.
import {ContextMenu, ContextMenuItemTypes} from 'jquery-contextmenu'; const contextMenu = new ContextMenu(); contextMenu.create({ // define which elements trigger this menu selector: ".with-cool-menu", // define the elements of the menu items: { foo: {name: "Foo", callback: function(e, key, currentMenuData){ alert("Foo!"); }}, bar: {name: "Bar", callback: function(e, key, currentMenuData){ alert("Bar!") }} } // there's more, have a look at the demos and docs... });
Check out the documentation for 3.0-beta for more information.
Update June 2017: The <menu> element has been deprecated in the html spec because of lack of support. This means the menu element won't be coming to browsers anymore, and the polyfill part of this menu is now deprecated.
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 are 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>:
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.
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.
Font-Awesome icons used from encharm/Font-Awesome-SVG-PNG.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4