Coder Social home page Coder Social logo

jquery-contextmenu's Introduction

jQuery contextMenu plugin & polyfill

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

If you like this implementation, go ahead an rate jQuery contextMenu at jQuery Plugins.

Dependencies

  • jQuery 1.7 (using new .on().off() event API)
  • 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.

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)

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.

Minify

use Google Closure Compiler:

// ==ClosureCompiler==
// @compilation_level SIMPLE_OPTIMIZATIONS
// @output_file_name contextMenu.js
// @code_url http://medialize.github.com/jQuery-contextMenu/jquery-1.7.1.min.js
// @code_url http://medialize.github.com/jQuery-contextMenu/jquery.ui.position.js
// @code_url http://medialize.github.com/jQuery-contextMenu/jquery.contextMenu.js
// ==/ClosureCompiler==    

Authors

License

$.contextMenu is published under the MIT license and GPL v3.

Changelog

1.5.2

  • 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)

1.5.1

  • Bug sub-menus would not properly update their disabled states (Issue #16)

1.5

1.4.4

  • Bug positioning <menu> when trigger element is position:fixed (Issue #14)

1.4.3

  • Bug key handler would caputure all key strokes while menu was visible (essentially disabling F5 and co.)

1.4.2

  • Bug opt.$trigger was not available to disabled callbacks
  • jQuery bumped to 1.7.1

1.4.1

  • Bug where <menu> imports would not pass action (click event) properly

1.4

  • Upgraded to jQuery 1.7 (changed dependecy!)
  • Added internal events contextmenu:focus, contextmenu:blur and contextmenu:hide
  • Added custom <command> types
  • Bug where className wasn't properly set on <menu>

1.3

  • Added support for accesskeys
  • Bug where two sub-menus could be open simultaneously

1.2.2

  • Bug in HTML5 import

1.2.1

  • Bug in HTML5 detection

1.2

  • Added compatibility to <menuitem> for Firefox 8
  • Upgraded to jQuery 1.6.2

1.1

  • 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

1.0

  • Initial $.contextMenu handler

jquery-contextmenu's People

Contributors

rodneyrehm avatar adjohu avatar addyosmani avatar

Stargazers

jag avatar

Watchers

jag avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.