features - demo - documentation
- jQuery 1.7 (using new .on().off() event API)
- 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.
// ==ClosureCompiler==
// @compilation_level SIMPLE_OPTIMIZATIONS
// @output_file_name contextMenu.js
// @code_url http://medialize.github.com/jQuery-contextMenu/jquery-1.8.2.min.js
// @code_url http://medialize.github.com/jQuery-contextMenu/src/jquery.ui.position.js
// @code_url http://medialize.github.com/jQuery-contextMenu/src/jquery.contextMenu.js
// ==/ClosureCompiler==
- Rodney Rehm
- Christiaan Baartse (single callback per menu)
- Addy Osmani (compatibility with native context menu in Firefox 8)
$.contextMenu is published under the MIT license and GPL v3.
- fixing "opening a second menu can break the layer" - (Issue #105)
- fixing jQuery plugin manifest, again. yep. I'm that kind of a guy. :(
- fixing jQuery plugin manifest
- fixing "menu won't close" regression introduced by 1.6.1
- fixing potential html parsing problem
- upgrading to jQuery UI position v1.10.0
- replaced
CRLF
byLF
(no idea how this happened in the first place...) - adding
options.reposition
to dis/allow simply relocating a menu instead of rebuilding it (Issue #104)
- adding DOM Element bound context menus - (Issue 88)
- adding class
context-menu-active
to define state on active trigger element - (Issue 92) - adding demo for TouchSwipe activation
- adding export of internal functions and event handlers - (Issue 101)
- fixing key "watch" might translate to Object.prototype.watch in callbacks map - (Issue 93)
- fixing menu and submenu width calculation - (Issue 18)
- fixing unused variables - (Issue 100)
- fixing iOS "click" compatibility problem - (Issue 83)
- fixing separators to not be clickable - (Issue 85)
- fixing issues with fixed positioned triggers (Issue 95)
- fixing word break problem - (Issue 80)
- adding context menu options to input command events (Issue 72, dtex)
- code cosmetics for JSLint
- fixing issue with animation and remove on hide (Issue #64)
- fixing backdrop would not remove on destroy (Issue #63)
Note: git tag of version is v1.6.20
?!
- fixing backdrop would not position properly in IE6 (Issue #59)
- fixing nested input elements not accessible in Chrome / Safari (Issue #58)
Note: git tag of version is missing...?!
- fixing sub-menu positioning when
$.ui.position
is not available (Issue #56)
Note: git tag of version is missing...?!
- fixing html5
<menu>
import (Issue #53)
- fixing
options
to default tooptions.trigger = "right"
- fixing variable name typo (Within Issue #51)
- fixing menu not closing while opening other menu (Within Issue #51)
- adding workaround for
contextmenu
-bug in Firefox 12 (Within Issue #51)
- added vendor-prefixed user-select to CSS
- fixed issue with z-indexing when
<body>
is used as a trigger (Issue #49)
- allowing to directly open another element's menu while a menu is shown (Issue #48)
- fixing autohide option that would not properly hide the menu
- options.build() would break default options (Issue #47)
- $.contextMenu('destroy') would not remove backdrop
- exposing $trigger to dynamically built custom menu-item types (Issue #42)
- fixing repositioning of open menu (formerly accidental re-open)
- adding asynchronous example
- dropping ignoreRightClick in favor of proper event-type detection
- prevent invoking callback of first item of a sub-menu when clicking on the sub-menu-item (Issue #41)
- providing
opt.$trigger
to show event (Issue #39)
- ignoreRightClick would not prevent right click when menu is already open (Issue #38)
- If build() did not return any items, an empty menu was shown (Issue #33)
- Capturing Page Up and Page Down keys to ignore like space (Issue #30)
- Added Home / End keys to jump to first / last command of menu (Issue #29)
- Bug hitting enter in an <input> would yield an error (Issue #28)
- Non-ASCII character in jquery.contextMenu.js caused compatibility issues in Rails (Issue #27)
- Bug contextmenu event was not passed to build() callback (Issue #24)
- Bug sub-menu markers would not display properly in Safari and Chrome (Issue #25)
- Bug Internet Explorer would not close menu when giving input elements focus (Issue #23)
- Bug not set z-index of sub-menus might not overlap the main menu correctly (Issue #22)
- Bug
console.log is undefined
- Bug sub-menus would not properly update their disabled states (Issue #16) [again…]
- Bug sub-menus would not properly adjust width accoring to min-width and max-width (Issue #18)
- Bug sub-menus would not properly update their disabled states (Issue #16)
- Added dynamic menu creation (Issue #15)
- Bug positioning <menu> when trigger element is
position:fixed
(Issue #14)
- Bug key handler would caputure all key strokes while menu was visible (essentially disabling F5 and co.)
- Bug opt.$trigger was not available to disabled callbacks
- jQuery bumped to 1.7.1
- Bug where <menu> imports would not pass action (click event) properly
- Upgraded to jQuery 1.7 (changed dependecy!)
- Added internal events
contextmenu:focus
,contextmenu:blur
andcontextmenu:hide
- Added custom <command> types
- Bug where
className
wasn't properly set on <menu>
- Added support for accesskeys
- Bug where two sub-menus could be open simultaneously
- Bug in HTML5 import
- Bug in HTML5 detection
- Added compatibility to <menuitem> for Firefox 8
- Upgraded to jQuery 1.6.2
- Bug #1 TypeError on HTML5 action passthru
- Bug #2 disbaled callback not invoked properly
- Feature #3 auto-hide option for hover trigger
- Feature #4 option to use a single callback for all commands, rather than registering the same function for each item
- Option to ignore right-click (original "contextmenu" event trigger) for non-right-click triggers
- Initial $.contextMenu handler