• Stars
    star
    2,244
  • Rank 20,522 (Top 0.5 %)
  • Language
    HTML
  • License
    MIT License
  • Created over 13 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

jQuery contextMenu plugin & polyfill

jQuery contextMenu plugin & polyfill

Greenkeeper badge

Travis npm npm CDNJS npm Buy us a tree

$.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

Sauce Test Status

Dependencies

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

Usage

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.

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, 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). 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");

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

License

$.contextMenu is published under the MIT license

This package is Treeware. If you use it in production, then we ask that you buy the world a tree 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.

SWIS ❀️ Open Source

SWIS is a web agency from Leiden, the Netherlands. We love working with open source software.

More Repositories

1

json-api-client

A PHP package for mapping remote {json:api} resources to Eloquent like models and collections.
PHP
204
star
2

laravel-fulltext

Fulltext indexing and searching for Laravel
PHP
180
star
3

json-api-server

Set up a JSON API in Laravel in just a few minutes.
PHP
105
star
4

laravel-nova-mirror

Automatically update a git repository with Laravel Nova releases
PHP
75
star
5

vagrant-remove-old-box-versions

Vagrant plugin to check your downloaded boxes and remove every box that is not the lastest downloaded version
Ruby
75
star
6

vue-cli-plugin-svg-sprite

vue-cli 3 plugin to build an SVG sprite
JavaScript
70
star
7

filament-backgrounds

Beautiful backgrounds for Filament auth pages
PHP
30
star
8

php7-upgrade-tools

A set of tools for upgrading applications to PHP 7
24
star
9

geocoder-php-nationaal-georegister-provider

Nationaal Georegister provider for Geocoder PHP
PHP
21
star
10

nuxt-lucide-icons

This Nuxt module makes working with Lucide icons a breeze!
TypeScript
21
star
11

laravel-graylog2

Log your Laravel application errors to Graylog2
PHP
20
star
12

laravel-mix-svg-sprite

SVG sprite component for Laravel Mix
JavaScript
17
star
13

textsnippet

Create a snippet of text highlighting a given string
PHP
14
star
14

gists

Gists from @swisnl
PHP
12
star
15

php-http-fixture-client

Fixture client for PHP-HTTP
PHP
8
star
16

game-of-tests-laravel

Laravel package for a Game of Tests
PHP
8
star
17

json-api-client-laravel

A PHP package for mapping remote {json:api} resources to Eloquent like models and collections.
PHP
8
star
18

game-of-tests

Some classes to parse git repositories in search for tests, gives a list of tests with their owner to create a ranking of tests written.
PHP
7
star
19

sass-rhythm

Helper function for maintaining rhythm in your css
SCSS
6
star
20

laravel-mautic

Laravel wrapper for Mautic API
PHP
6
star
21

build-size

Parse and compare build size
JavaScript
4
star
22

laravel-javascript-data-response

JavaScript data response macro for Laravel
PHP
4
star
23

pdfcrowd-client

A client for the pdfcrowd.com API. Includes a Laravel service provider.
PHP
3
star
24

game-of-tests-laravel-demo

Game of Tests demo site
PHP
3
star
25

laravel-static-request-cache

Cache static responses based on content-type to static files.
PHP
3
star
26

omnipay-redsys

RedSys driver for the Omnipay PHP payment processing library
PHP
2
star
27

laravel-lti-provider

Laravel LTI provider
PHP
2
star
28

phpstan-faker

PHP
2
star
29

laravel-psr-http-client-bridge

Laravel PSR-18 HTTP Client Bridge
PHP
2
star
30

sass-custom-box

BEM-compatible SASS mixins for styling radioboxes and checkboxes
SCSS
1
star
31

php-cs-fixer-bitbucket

PHP CS Fixer Bitbucket reporter
PHP
1
star
32

flysystem-encrypted

Flysystem Adapter Encryption Decorator
PHP
1
star
33

leiduhfy

Jouw website op z'n leids op 3 oktober
JavaScript
1
star
34

pdok-geodatastore-api

A client for the PDOK Geodatastore API.
PHP
1
star
35

phpcs-bitbucket

PHP_CodeSniffer Bitbucket reporter
PHP
1
star
36

guzzle-fixture-handler

Fixture handler for Guzzle 6+
PHP
1
star
37

phpmd-bitbucket

PHPMD Bitbucket renderer
PHP
1
star