Skip to content

AnshS-GIT/jQuery-contextMenu

Β 
Β 

Repository files navigation

πŸ₯³ jQuery ContextMenu Plugin & Polyfill πŸŽ‰

Greenkeeper badge

Travis npm npm CDNJS npm Buy us a tree

🌟 Features 🌟

$.contextMenu is a powerful tool designed for easy management of context menus! Perfect for applications with hundreds of elements that may show context menus. Its lightweight design ensures quick initialization and low memory usage. Plus, it dynamically generates DOM elements, so no need for pre-defined markup!

Sauce Test Status

πŸ“¦ Dependencies πŸ“¦

  • jQuery >= 1.8.2
  • jQuery UI position (optional but recommended)

Copy

<script> function copyToClipboard() { const text = `
# πŸ₯³ jQuery ContextMenu Plugin & Polyfill πŸŽ‰ [![Greenkeeper badge](https://badges.greenkeeper.io/swisnl/jQuery-contextMenu.svg)](https://greenkeeper.io/) [![Travis](https://img.shields.io/travis/com/swisnl/jQuery-contextMenu/master.svg?style=flat-square&maxAge=600)](https://app.travis-ci.com/github/swisnl/jQuery-contextMenu) [![npm](https://img.shields.io/npm/v/jquery-contextmenu.svg?style=flat-square&maxAge=600)](https://www.npmjs.com/package/jquery-contextmenu) [![npm](https://img.shields.io/npm/dm/jquery-contextmenu.svg?style=flat-square&maxAge=600)](https://www.npmjs.com/package/jquery-contextmenu) [![CDNJS](https://img.shields.io/cdnjs/v/jquery-contextmenu.svg?style=flat-square&maxAge=600)](https://cdnjs.com/libraries/jquery-contextmenu) [![npm](https://img.shields.io/npm/l/jquery-contextmenu.svg?style=flat-square)]() [![Buy us a tree](https://img.shields.io/badge/Treeware-%F0%9F%8C%B3-lightgreen.svg?style=flat-square)](https://plant.treeware.earth/swisnl/jQuery-contextMenu) ## 🌟 Features 🌟 \`$.contextMenu\` is a powerful tool designed for easy management of context menus! Perfect for applications with hundreds of elements that may show context menus. Its lightweight design ensures quick initialization and low memory usage. Plus, it dynamically generates DOM elements, so no need for pre-defined markup! - πŸ‘‰ [Features](http://swisnl.github.io/jQuery-contextMenu/index.html) - 🎨 [Demo](http://swisnl.githu ## Usage ## register contextMenu from javascript: ```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](http://swisnl.github.io/jQuery-contextMenu/demo.html). ## Version 3.0 beta 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. Check out the [3.x branch](https://github.com/swisnl/jQuery-contextMenu/tree/3.x), or install with `npm install jquery-contextmenu@next`. ## HTML5 Compatibility ## 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](https://bugzilla.mozilla.org/show_bug.cgi?id=617528)). The elements [a](http://www.whatwg.org/specs/web-apps/current-work/multipage/commands.html#using-the-a-element-to-define-a-command), [button](http://www.whatwg.org/specs/web-apps/current-work/multipage/commands.html#using-the-button-element-to-define-a-command), [input](http://www.whatwg.org/specs/web-apps/current-work/multipage/commands.html#using-the-input-element-to-define-a-command) and [option](http://www.whatwg.org/specs/web-apps/current-work/multipage/commands.html#using-the-option-element-to-define-a-command) usable as commands are being ignored altogether. It also doesn't (optically) distinguish between checkbox/radio and regular commands ([Bug #705292](https://bugzilla.mozilla.org/show_bug.cgi?id=705292)). * [contextmenu specs](http://www.w3.org/TR/html5/interactive-elements.html#context-menus) * [command specs](http://www.whatwg.org/specs/web-apps/current-work/multipage/commands.html) * [Browser support according to caniuse.com](http://caniuse.com/#search=context%20menu) Note: While the specs note <option>s to be renderd as regular commands, $.contextMenu will render an actual <select>. import contextMenu from HTML5 <menu>: ```javascript $.contextMenu("html5"); ``` ## Interaction Principles 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. ## Authors * [BjΓΆrn Brala](https://github.com/swisnl) * [Rodney Rehm](https://github.com/rodneyrehm) (original creator) * [Christiaan Baartse](https://github.com/christiaan) (single callback per menu) * [Addy Osmani](https://github.com/addyosmani) (compatibility with native context menu in Firefox 8) ## License `$.contextMenu` is published under the [MIT license](http://www.opensource.org/licenses/mit-license) This package is [Treeware](https://treeware.earth). If you use it in production, then we ask that you [**buy the world a tree**](https://plant.treeware.earth/swisnl/jQuery-contextMenu) to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats. ## Special thanks Font-Awesome icons used from [encharm/Font-Awesome-SVG-PNG](https://github.com/encharm/Font-Awesome-SVG-PNG). ## SWIS ❀️ Open Source [SWIS][link-swis] is a web agency from Leiden, the Netherlands. We love working with open source software. [link-swis]: https://www.swis.nl

About

jQuery contextMenu plugin & polyfill

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • HTML 82.5%
  • JavaScript 16.2%
  • SCSS 1.2%
  • Smarty 0.1%