diff --git a/.editorconfig b/.editorconfig
index fe6e86c..a9d53aa 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -5,7 +5,7 @@ root = true
; Unix-style newlines with a newline ending every file
[*]
-; end_of_line = lf
+end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
@@ -16,11 +16,11 @@ indent_size = 4
; Tab indentation (no size specified)
[*.js]
-; indent_style = tab
-indent_style = space
-indent_size = 4
+indent_style = tab
+;indent_style = space
+;indent_size = 4
; Indentation override for all JS under lib directory
-[lib/**.js]
-indent_style = space
-indent_size = 2
+;[lib/**.js]
+;indent_style = space
+;indent_size = 2
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..bdb0cab
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,17 @@
+# Auto detect text files and perform LF normalization
+* text=auto
+
+# Custom for Visual Studio
+*.cs diff=csharp
+
+# Standard to msysgit
+*.doc diff=astextplain
+*.DOC diff=astextplain
+*.docx diff=astextplain
+*.DOCX diff=astextplain
+*.dot diff=astextplain
+*.DOT diff=astextplain
+*.pdf diff=astextplain
+*.PDF diff=astextplain
+*.rtf diff=astextplain
+*.RTF diff=astextplain
diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md
new file mode 100644
index 0000000..00404d1
--- /dev/null
+++ b/.github/CONTRIBUTING.md
@@ -0,0 +1,4 @@
+Thanks for contributing :+1:
+
+In lieu of an own guideline, please have a look at the
+[Fancytree Contributing Guidelines](https://github.com/mar10/fancytree/wiki/HowtoContribute#report-issues).
diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md
new file mode 100644
index 0000000..e6fc770
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE.md
@@ -0,0 +1,24 @@
+Thanks for contributing :-)
+
+Please add info below, then remove all unneeded lines from this issue report.
+
+
+### Expected and actual behavior
+
+... (Maybe even a screenshot? Any hints on the browser's debug console?)
+
+
+### Steps to reproduce the problem
+
+ 1. ...
+ 2. ...
+
+Could you set up a jsFiddle (http://jsfiddle.net/mar10/6o3u8a88/) or
+Plunker (http://plnkr.co/edit/Bbcoqy?p=preview) ?
+
+
+### Environment
+
+ - Browser type and version:
+ - jQuery and jQuery UI versions:
+ - ui-contextmenu version:
diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml
new file mode 100644
index 0000000..5c9953a
--- /dev/null
+++ b/.github/workflows/stale.yml
@@ -0,0 +1,30 @@
+name: Mark stale issues and pull requests
+
+on:
+ schedule:
+ - cron: "0 0 * * *"
+
+jobs:
+ stale:
+
+ runs-on: ubuntu-latest
+
+ steps:
+ - uses: actions/stale@v1
+ with:
+ repo-token: ${{ secrets.GITHUB_TOKEN }}
+ stale-issue-message: |
+ This issue has been automatically marked as stale because it has not had
+ recent activity. It will be closed if no further activity occurs.
+ Thank you for your contributions.
+ stale-pr-message: |
+ This pull request has been automatically marked as stale because it has not had
+ recent activity. It will be closed if no further activity occurs.
+ Thank you for your contributions.
+ stale-issue-label: 'stale'
+ exempt-issue-label: 'pinned'
+ stale-pr-label: 'stale'
+ exempt-pr-label: 'pinned'
+ days-before-stale: 90
+ days-before-close: 14
+ operations-per-run: 5
diff --git a/.gitignore b/.gitignore
index 3c58feb..242a85d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,6 @@
/.settings
/node_modules
+/test/triage/
.DS_Store
npm-debug.log
.sizecache.json
diff --git a/.travis.yml b/.travis.yml
index 62faf66..a238abe 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,6 +1,8 @@
language: node_js
node_js:
- - 0.10
+ # - 0.10
+ - "8"
+sudo: false
before_script:
- npm install -g grunt-cli
script: grunt travis --verbose
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 49f32c9..f1655ef 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,8 +1,76 @@
-# 1.10.1-0 / Unreleased
+# 1.19.0 / Unreleased
+ - [FEATURE] Add `appendTo` option.
+
+# 1.18.1 / 2017-08-28
+
+* [BUGFIX] Fix deprecation warnings when menu with `title` callback is opened
+
+# 1.18.0 / 2017-08-26
+
+* [CHANGE] Refactored entry update methods
+ - `setEntry(cmd, data)`:
+ Clarify that this method resets all attributes *not* passed in
+ `data` are reset to defaults.
+ Also, passing a plain title string as `data` is deprecated: use `setTitle()` instead.
+ - Add method `updateEntry(cmd, data)`.
+ Example: `updateEntry("info", {title: "Show info...", enable: false})`
+ Unlike `setEntry()`, this method only updates menu attibutes that are
+ passed in `data`, leaving other attributes intact.
+ - Add methods `getEntry()`, `getEntryWrapper()`, `setIcon`, `setTitle`
+ (in addition to the existing `enableEntry` and `showEntry`).
+
+# 1.17.0 / 2017-04-17
+
+* [FEATURE] #59 Allow callbacks for `disabled`, `title`, and `tooltip` options
+* [FEATURE] #116 `autoFocus` skips leading disabled entries.
+* [FEATURE] #118 New option `closeOnWindowBlur`
+* Use `.on()` / `.off()` syntax
+* Add check for missing `.delegate` option
+* Set @VERSION in minified script
+
+# 1.16.0 / 2017-03-30
+
+* [FEATURE] #114: Pass `extraData` argument to `select` and other events.
+ The same ui.extraData instance is passed to all events of a open-select-close
+ sequence, so it can also be used to pass data between events.
+
+# 1.15.0 / 2017-03-18
+
+* [FEATURE] #113: Pass `ui` argument to `open` event.
+
+# 1.14.0 / 2017-01-30
+
+* #108: Update AMD dependency to be compatible with the jQuery 1.12 layout:
+ "jquery-ui/ui/widgets/menu"
+ NOTE: this is not backwards compatible with jQuery 1.11 and before:
+ http://jqueryui.com/upgrade-guide/1.12/#official-package-on-npm
+
+# 1.13.1 / 2017-01-27
+
+* [BUGFIX] #109 Fix `setEntry(title)` for titles containing icons
+* [BUGFIX] #110 Fix `setEntry({...})` for jQuery UI 1.12
+
+# 1.13.0 / 2016-08-21
+
+* [FEATURE] Test with jQuery 3
+* [FEATURE] #104 Allow to pass mouse click events to `open()`
+* Update grunt to 1.0
+* Upate QUnit to 1.23 and refactor tests to use `assert`
+
+# 1.12.0 / 2016-05-18
+
+* [FEATURE] Support jQuery UI 1.12 (wrap menu items in separate `
` tags)
+* [FEATURE] #100 new menu option `isHeader` for category headers.
+* Add jQuery UI 1.12 sample with new 'Base' theme
+
+# 1.11.0 / 2015-09-10
+
+* [CHANGE] #98 Allow to show/hide separators
+* [FEATURE] #94 Add `main` field to package.json
# 1.10.0 / 2015-06-27
-* [FEATURE] New option `tooltip`, adds a `title` attribute to the menu markup
+* [FEATURE] New option `tooltip`, adds a `title` attribute to the menu markup
# 1.9.0 / 2015-04-20
@@ -32,7 +100,7 @@
# 1.7.0 / 2014-09-09
* [FEATURE] AMD support (topolm).
-* [FEATURE] CDN support (http://www.jsdelivr.com/#!jquery.ui-contextmenu).
+* [FEATURE] CDN support on [jsDelivr](http://www.jsdelivr.com/#!jquery.ui-contextmenu).
# 1.6.1 / 2014-08-18
@@ -51,10 +119,13 @@
# 1.3.0 / 2014-03-09
* [FEATURE] New optional parameter open(..., extraData).
-* [FEATURE] New option `autoTrigger: true` can be set to `false` to prevent opening menus on browser's `contextmenu` event
- (if you want to use the `open()` method instead).
-* [FEATURE] New option `preventContextMenuForPopup`to prevent opening the browser's system context menu on menu entries.
-* [CHANGE] `setEntry()` and `replaceMenu()` now allow to define titles with HTML markup.
+* [FEATURE] New option `autoTrigger: true` can be set to `false` to prevent
+ opening menus on browser's `contextmenu` event (if you want to use the `open()`
+ method instead).
+* [FEATURE] New option `preventContextMenuForPopup`to prevent opening the browser's
+ system context menu on menu entries.
+* [CHANGE] `setEntry()` and `replaceMenu()` now allow to define titles with HTML
+ markup.
# 1.2.4 / 2013-12-25
@@ -65,7 +136,8 @@
# 1.2.3 / 2013-10-19
* [CHANGE] Detection of separators compliant with UI Menu 1.10
-* [BUGFIX] Fixed setEntry for entries that don't have icons and handle missing `cmd` option.
+* [BUGFIX] Fixed setEntry for entries that don't have icons and handle missing
+ `cmd` option.
# 1.2.2 / 2013-07-28
@@ -104,3 +176,7 @@
* [FEATURE] Support `taphold` events.
* [FEATURE] Show / hide effects configurable.
* [BUGFIX] Fixed markup for disabled entries.
+
+# 0.2.0 / 2013-05-10
+
+* First release.
diff --git a/Gruntfile.coffee b/Gruntfile.coffee
index 34c9b7d..bb281e4 100644
--- a/Gruntfile.coffee
+++ b/Gruntfile.coffee
@@ -1,8 +1,8 @@
-#jshint node: true, camelcase: false
+#jshint node: true, camelcase: false
"use strict"
module.exports = (grunt) ->
grunt.initConfig
- pkg:
+ pkg:
grunt.file.readJSON("package.json")
connect:
@@ -32,7 +32,9 @@ module.exports = (grunt) ->
upload:
# FTP upload the demo files (requires https://github.com/mar10/pyftpsync)
- cmd: "pyftpsync --progress upload . ftp://www.wwwendt.de/tech/demo/jquery-contextmenu --delete-unmatched --omit dist,node_modules,.*,_* -x"
+ stdin: true # Allow interactive console
+ cmd: "pyftpsync upload . ftp://www.wwwendt.de/tech/demo/jquery-contextmenu --delete-unmatched --exclude dist,node_modules,.*,_*"
+ # cmd: "pyftpsync --progress upload . ftp://www.wwwendt.de/tech/demo/jquery-contextmenu --delete-unmatched --omit dist,node_modules,.*,_*"
jscs:
src: ["jquery.ui-contextmenu.js", "test/tests.js"]
@@ -46,89 +48,77 @@ module.exports = (grunt) ->
jshintrc: ".jshintrc"
qunit:
- all: ["test/index.html", "test/index-jquery-ui-1-10.html"]
-
- # replace: # grunt-text-replace
- # production:
- # src: ["build/**/*.js"]
- # overwrite : true
- # replacements: [ {
- # from : /@DATE/g
- # to : "<%= grunt.template.today('yyyy-mm-dd\"T\"HH:MM') %>"
- # },{
- # from : /buildType:\s*\"[a-zA-Z]+\"/g
- # to : "buildType: \"production\""
- # },{
- # from : /debugLevel:\s*[0-9]/g
- # to : "debugLevel: 1"
- # } ]
- # release:
- # src: ["dist/**/*.js"]
- # overwrite : true
- # replacements: [ {
- # from : /@VERSION/g
- # to : "<%= pkg.version %>"
- # } ]
+ all: [
+ "test/test-jquery-3-ui-1.12.html",
+ "test/test-jquery-1.12-ui-1.12.html",
+ "test/test-jquery-1.11-ui-1.11.html",
+ "test/test-jquery-1.9-ui-1.10.html",
+ ]
"saucelabs-qunit":
- ui_10:
+ options:
+ build: process.env.TRAVIS_JOB_ID
+ throttled: 5
+ # statusCheckAttempts: 180
+ recordVideo: false
+ videoUploadOnPass: false
+
+ ui_12:
options:
+ testname: "jquery.ui-contextmenu qunit tests (jQuery UI 12)"
urls: [
- # "http://localhost:9999/test/index.html",
- "http://localhost:9999/test/index-jquery-ui-1-10.html"
+ "http://localhost:9999/test/test-jquery-3-ui-1.12.html"
]
-
- # username: process.env.SAUCE_USERNAME,
- # key: process.env.SAUCE_ACCESS_KEY,
- build: process.env.TRAVIS_JOB_ID
- throttled: 8
browsers: [
- { browserName: "chrome", platform: "Windows 7" }
- { browserName: "firefox", platform: "Windows 7" }
- # { browserName: "firefox", platform: "Windows XP" }
+ { browserName: "chrome", platform: "Windows 8.1" }
+ { browserName: "firefox", platform: "Windows 8.1" }
{ browserName: "firefox", platform: "Linux" }
- { browserName: "internet explorer", version: "6", platform: "Windows XP" }
- { browserName: "internet explorer", version: "7", platform: "Windows XP" }
- { browserName: "internet explorer", version: "8", platform: "Windows 7" }
- { browserName: "internet explorer", version: "9", platform: "Windows 7" }
- { browserName: "internet explorer", version: "10", platform: "Windows 8" }
+ # jQuery UI 12+ stopped support for IE <= 10
{ browserName: "internet explorer", version: "11", platform: "Windows 8.1" }
- { browserName: "safari", version: "6", platform: "OS X 10.8" }
- { browserName: "safari", version: "7", platform: "OS X 10.9" }
- { browserName: "safari", version: "8", platform: "OS X 10.10" }
+ { browserName: "microsoftedge", platform: "Windows 10" }
+ # { browserName: "safari", version: "6", platform: "OS X 10.8" }
+ # { browserName: "safari", version: "7", platform: "OS X 10.9" }
+ # { browserName: "safari", version: "8", platform: "OS X 10.10" }
+ { browserName: "safari", version: "9", platform: "OS X 10.11" }
+ { browserName: "safari", version: "10", platform: "OS X 10.12" }
+ { browserName: "safari", version: "11", platform: "OS X 10.12" }
]
- testname: "jquery.ui-contextmenu qunit tests (jQuery UI 10)"
- ui: # UI Menu 11+ dropped support for IE7
+
+ ui_11: # UI Menu 11+ dropped support for IE7
options:
+ testname: "jquery.ui-contextmenu qunit tests (jQuery UI 11+)"
urls: [
- "http://localhost:9999/test/index.html",
- # "http://localhost:9999/test/index-jquery-ui-1-10.html"
+ "http://localhost:9999/test/test-jquery-1.11-ui-1.11.html"
]
-
- # username: process.env.SAUCE_USERNAME,
- # key: process.env.SAUCE_ACCESS_KEY,
- build: process.env.TRAVIS_JOB_ID
- throttled: 8
browsers: [
- { browserName: "chrome", platform: "Windows 7" }
- { browserName: "firefox", platform: "Windows 7" }
- { browserName: "firefox", platform: "Windows XP" }
+ { browserName: "chrome", platform: "Windows 8.1" }
{ browserName: "firefox", platform: "Linux" }
- # { browserName: "internet explorer", version: "6", platform: "Windows XP" }
- # { browserName: "internet explorer", version: "7", platform: "Windows XP" }
- { browserName: "internet explorer", version: "8", platform: "Windows 7" }
+ # jQuery UI 11+ stopped support for IE <= 7
+ # { browserName: "internet explorer", version: "8", platform: "Windows 7" }
{ browserName: "internet explorer", version: "9", platform: "Windows 7" }
{ browserName: "internet explorer", version: "10", platform: "Windows 8" }
{ browserName: "internet explorer", version: "11", platform: "Windows 8.1" }
- { browserName: "safari", version: "6", platform: "OS X 10.8" }
- { browserName: "safari", version: "7", platform: "OS X 10.9" }
- { browserName: "safari", version: "8", platform: "OS X 10.10" }
+ { browserName: "microsoftedge", platform: "Windows 10" }
+ { browserName: "safari", version: "10", platform: "OS X 10.12" }
+ ]
+
+ ui_10:
+ options:
+ testname: "jquery.ui-contextmenu qunit tests (jQuery UI 10)"
+ urls: [
+ "http://localhost:9999/test/test-jquery-1.9-ui-1.10.html"
+ ]
+ browsers: [
+ { browserName: "chrome", platform: "Windows 8.1" }
+ { browserName: "firefox", platform: "Linux" }
+ { browserName: "internet explorer", version: "11", platform: "Windows 8.1" }
+ { browserName: "microsoftedge", platform: "Windows 10" }
+ { browserName: "safari", version: "10", platform: "OS X 10.12" }
]
- testname: "jquery.ui-contextmenu qunit tests (jQuery UI 11+)"
uglify:
options:
- banner: "/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - " + "<%= grunt.template.today('yyyy-mm-dd') %> | " + "<%= pkg.homepage ? ' ' + pkg.homepage + ' | ' : '' %>" + " Copyright (c) <%= grunt.template.today('yyyy') %> <%= pkg.author.name %>;" + " Licensed <%= _.pluck(pkg.licenses, 'type').join(', ') %> */\n"
+ banner: "/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - " + "<%= grunt.template.today('yyyy-mm-dd') %> | " + "<%= pkg.homepage ? ' ' + pkg.homepage + ' | ' : '' %>" + " Copyright (c) 2013 -<%= grunt.template.today('yyyy') %> <%= pkg.author.name %>;" + " Licensed <%= _.map(pkg.licenses, 'type').join(', ') %> */\n"
report: "gzip"
build:
@@ -152,14 +142,19 @@ module.exports = (grunt) ->
yabs:
release:
common: # defaults for all tools
- manifests: ['package.json', 'bower.json', 'ui-contextmenu.jquery.json']
+ manifests: ['package.json', 'bower.json']
# The following tools are run in order:
check: { branch: ['master'], canPush: true, clean: true, cmpVersion: 'gte' }
run_test: { tasks: ['test'] }
- bump: {} # 'bump' also uses the increment mode `yabs:release:MODE`
+ bump: {} # 'bump' uses the increment mode `yabs:release:MODE` by default
run_build: { tasks: ['build'] }
+ replace_build:
+ files: ['jquery.ui-contextmenu.min.js']
+ patterns: [
+ { match: /@VERSION/g, replacement: '{%= version %}'}
+ ]
commit: {}
- check_after_build: { clean: true } # Fails if new files found
+ check_after_build: { clean: true } # Fails if new files are found
tag: {}
push: { tags: true, useFollowTags: true }
githubRelease:
@@ -168,17 +163,17 @@ module.exports = (grunt) ->
npmPublish: {}
bump_develop: { inc: 'prepatch' }
commit_develop: { message: 'Bump prerelease ({%= version %}) [ci skip]' }
- push_develop: {}
+ push_develop: {} # another push (append a suffix for a uniqu ename)
# Load "grunt*" dependencies
for key of grunt.file.readJSON("package.json").devDependencies
grunt.loadNpmTasks key if key isnt "grunt" and key.indexOf("grunt") is 0
-
+
grunt.registerTask "server", ["connect:demo"]
grunt.registerTask "dev", ["connect:dev", "watch:dev"]
grunt.registerTask "test", ["jshint", "jscs", "qunit"]
- grunt.registerTask "sauce", ["connect:sauce", "saucelabs-qunit:ui", "saucelabs-qunit:ui_10"]
+ grunt.registerTask "sauce", ["connect:sauce", "saucelabs-qunit:ui_12", "saucelabs-qunit:ui_11", "saucelabs-qunit:ui_10"]
if parseInt(process.env.TRAVIS_PULL_REQUEST, 10) > 0
# saucelab keys do not work on forks
# http://support.saucelabs.com/entries/25614798
@@ -186,7 +181,8 @@ module.exports = (grunt) ->
else
grunt.registerTask "travis", ["test", "sauce"]
grunt.registerTask "default", ["test"]
-
+ grunt.registerTask "ci", ["test"] # Called by 'npm test'
+
# "sauce",
grunt.registerTask "build", ["exec:tabfix", "test", "uglify"]
grunt.registerTask "upload", ["build", "exec:upload"]
diff --git a/LICENSE.txt b/LICENSE.txt
index 1a742e8..ff1e001 100644
--- a/LICENSE.txt
+++ b/LICENSE.txt
@@ -1,4 +1,4 @@
-Copyright 2013-2015 Martin Wendt and others (see commiter list on GitHub)
+Copyright 2013-2018 Martin Wendt and others (see commiter list on GitHub)
https://github.com/mar10/jquery-ui-contextmenu
Permission is hereby granted, free of charge, to any person obtaining
diff --git a/README.md b/README.md
index d5946cf..bcbb8d6 100644
--- a/README.md
+++ b/README.md
@@ -1,8 +1,13 @@
-# jquery.ui-contextmenu [](https://github.com/mar10/jquery-ui-contextmenu/releases/latest) [](https://travis-ci.org/mar10/jquery-ui-contextmenu) [](https://saucelabs.com/u/sauce-contextmenu)
+# jquery.ui-contextmenu
+[](https://github.com/mar10/jquery-ui-contextmenu/releases/latest)
+[](https://travis-ci.org/mar10/jquery-ui-contextmenu)
+[](https://saucelabs.com/u/sauce-contextmenu)
+[](https://www.npmjs.com/package/ui-contextmenu)
+[](https://www.jsdelivr.com/package/npm/ui-contextmenu),
-A jQuery plugin that provides a context menu (based on the standard [jQueryUI menu] widget).
+> A jQuery plugin that provides a context menu (based on the standard [jQueryUI menu] widget).
- * Define menus from `
` element or definition list (i.e.
+ * Define menus from `
` element or definition list (i.e.
`[{title: "Paste", cmd: "paste"}, ...]`).
* Themable using [jQuery ThemeRoller](http://jqueryui.com/themeroller/).
* Supports delegation (i.e. can be bound to elements that don't exist at the
@@ -26,24 +31,33 @@ See also the [Change Log](https://github.com/mar10/jquery-ui-contextmenu/blob/ma
[Live demo page](http://wwwendt.de/tech/demo/jquery-contextmenu/demo/):
[  ](http://wwwendt.de/tech/demo/jquery-contextmenu/demo/ "Live demo")
+See also the unit tests and live examples
+
+**More:**
+
+ * Play with [jsFiddle](http://jsfiddle.net/mar10/6o3u8a88/) or
+ [Plunker](http://plnkr.co/edit/Bbcoqy?p=preview)
+ * Run the [unit tests](http://rawgit.com/mar10/jquery-ui-contextmenu/master/test/index.html).
+
-## Tutorial
+## Getting Started
First, include dependencies:
-* jQuery 1.7+ (1.10 or later recommended)
-* jQuery UI 1.9+ (at least core, widget, menu), 1.11+ recommended
+* jQuery 1.7+ (3.x or later recommended)
+* jQuery UI 1.9+ (at least core, widget, menu), 1.12+ recommended
* One of the ThemeRoller CSS themes or a custom one
-* jquery.ui-contextmenu.js (also available as CDN on
- [jsdelivr](http://www.jsdelivr.com/#!jquery.ui-contextmenu)
- or [cdnjs](https://cdnjs.com/libraries/jquery.ui-contextmenu))
+* jquery.ui-contextmenu.js (also available as CDN on
+ [](https://www.jsdelivr.com/package/npm/ui-contextmenu),
+ [cdnjs](https://cdnjs.com/libraries/jquery.ui-contextmenu), or
+ [UNPKG](https://unpkg.com/ui-contextmenu@latest/jquery.ui-contextmenu.min.js))
+for example
```html
-
-
-
+
+
+
```
@@ -76,453 +90,18 @@ $("#container").contextmenu({
});
```
-The `delegate` option defines a CSS selector, which is evaluated for all
-elements inside the context element (`#container` in our example).
-In order to attach menus to *all* matching elements on the page that have
-`class="hasmenu"`, we may use `document` as context:
-```js
-$(document).contextmenu({
- delegate: ".hasmenu",
- ...
-});
-```
-**Note:** only one contextmenu widget instance can be bound to one element.
-
-The `menu` options may contain a (nested) array of entry defiitions.
-Following a list of available properties:
-
-
action
-
- Type: Function, default: n.a.
- Optional callback that will be executed when the entry is selected.
-
-
addClass
-
- Type: String, default: ""
- Additional class name(s) to be added to the entries <li> element.
- Separate multiple class names with a space.
- Custom CSS may be applied like .ui-menu .my-class { color: red; }.
-
-
cmd
-
- Type: String, default: ""
- Optional identifier associated with the menu entry.
- It can later be accessed in the select event as ui.cmd.
-
-
data
-
- Type: Object, default: {}
- Optional hash of additional properties that will be added to the entry's
- data attribute.
- It can later be accessed in the select event as ui.item.data().
-
-
disabled
-
- Type: Boolean, default: false
- Pass true to disable the entry.
-
-
title
-
- Type: String, default: ""
- The displayed name of the menu entry. Use dashes ("---") to
- define a separator.
-
-
uiIcon
-
- Type: String, default: ""
- If defined, an icon is added to the menu entry. For example passing
- "ui-icon-copy" will generate this element:
- <span class='ui-icon ui-icon-copy' />.
- See also <Icon Overview.
-
-
-
-Instead of handling all menu commands in the `select` event, it is also possible
-to attach callbacks directly to menu entries:
-```js
-$(document).contextmenu({
- delegate: ".hasmenu",
- menu: [
- {title: "Copy", uiIcon: "ui-icon-copy", action: function(event, ui){
- alert("Copy " + ui.target.text());
- }
- },
- ...
-});
-```
-
-### Initialize menu from an existing `
` element
-
-In this case `menu` must point to the markup:
-
-```js
-$(document).contextmenu({
- delegate: ".hasmenu",
- menu: "#options",
- select: function(event, ui) {
- ...
- }
-});
-```
-We also have to provide some HTML markup that defines the context menu structure,
-see [jQueryUI menu] for details:
-
-```html
-
-```
-
-
-### Modify the menu depending on the context
-
-Often we need to modify the menu before it is displayed, in order to reflect the
-current context.
-This can be done in the `beforeOpen` event:
-
-```js
-$(document).contextmenu({
- delegate: ".hasmenu",
- menu: [
- {title: "Cut", cmd: "cut", uiIcon: "ui-icon-scissors"},
- {title: "Copy", cmd: "copy", uiIcon: "ui-icon-copy"},
- {title: "Paste", cmd: "paste", uiIcon: "ui-icon-clipboard", disabled: true },
- ...
- ],
- beforeOpen: function(event, ui) {
- var $menu = ui.menu,
- $target = ui.target,
- extraData = ui.extraData; // optionally passed when menu was opened by call to open()
-
- // Optionally return false, to prevent opening the menu
-// return false;
-
- // En/disable single entries
- $(document).contextmenu("enableEntry", "paste", false);
- // Show/hide single entries
- $(document).contextmenu("showEntry", "cut", false);
- // Redefine the title of single entries
- $(document).contextmenu("setEntry", "copy", "Copy '" + $target.text() + "'")
- // Redefine all attributes of single entries
- $(document).contextmenu("setEntry", "cut", {title: "Cuty", uiIcon: "ui-icon-heart", disabled: true});
- // Redefine the whole menu
- $(document).contextmenu("replaceMenu", [{title: "aaa"}, {title: "bbb"}, ...]);
- // Redefine the whole menu from another HTML definition
- $(document).contextmenu("replaceMenu", "#options2");
- },
- ...
-});
-```
-
+Alternatively we can
+
+initialize the menu from embedded <ul> markup.
-## API documentation
-### Options
-
-
-
addClass
-
- Type: String,
- default: "ui-contextmenu"
- This class is added to the outer ul element.
-
-
autoFocus
-
- Type: Boolean,
- default: false
- Set keyboard focus to first menu entry on open.
-
-
autoTrigger
-
- Type: Boolean,
- default: true
- Set `false` to prevent opening on a browser's `contextmenu` event, which is
- normally triggered by a mouse rightclick.
- The menu can still be opened by calling the `open()` method.
-
-
delegate
-
- Type: String
- A selector to filter the elements that trigger the context menu.
-
-
hide
-
- Type: Boolean | Number | String | Object,
- default: { effect: "fadeOut", duration: "fast" }
- Effect applied when hiding the popup.
- See sample
- for possible option values.
-
-
ignoreParentSelect
-
- Type: Boolean, default: true
- If true, a click on a menu item that contains a sub-menu, will
- not trigger the select event.
-
-
menu
-
- Type: Object[] | String | jQuery
- jQuery object or selector of HTML markup that
- defines the context menu structure (see
- jQueryUI menu for details).
-
- If an array of objects is passed, it will be used to generate
- such markup on the fly.
-
-
position
-
- Type: Object | Function,
- default: {my: "left top", at: "center", of: event, collision: "fit"}
- Define position where popup opens. A simple position may be passed.
- Also a function may be specified, to recalculate position every time:
-
- Type: Boolean, default: false
- Prevent that a right click inside an open popup menu will open the browser's
- system context menu.
-
-
preventSelect
-
- Type: Boolean, default: false
- Prevent accidental text selection of potential menu targets on doubleclick
- or drag.
-
-
show
-
- Type: Boolean | Number | String | Object,
- default: { effect: "slideDown", duration: "fast"}
- Effect applied when showing the popup.
- See sample
- for possible option values.
-
-
taphold
-
- Type: Boolean, default: false
- Open menu on taphold events,
- which is especially useful for touch devices (but may require external
- plugins to generate taphold events).
-
-
tooltip
-
- Type: String, optional
- Add a title attribute to the menu markup, which will be displayed
- as tooltip by most browser (or external plugins).
-
-
uiMenuOptions
-
- Type: Object, default: {}
- Custom options passed to UI Menu, when the widget is created.
- Especially useful to tweak the position of submenus.
-
-
-
-
-### Methods
-
-
-
close()
-
- Close context menu if open.
- Call like $(...).contextmenu("close");.
-
-
enableEntry(cmd, flag)
-
- Enable or disable the entry. `flag` defaults to `true`
- Call like $(...).contextmenu("enableEntry", "paste", false);.
-
-
getMenu()
-
- Return the jQuery object for the menu's UL element.
-
-
isOpen()
-
- Return true if popup is visible.
-
-
open(target[, extraData])
-
- Open context menu on a specific target (target (as a jQuery object) must match the options.delegate filter).
- Call like $(...).contextmenu("open", $(target)[, extraData]);.
- Optional `extraData` will be available in event handlers as ui.extraData.
-
-
replaceMenu(menu)
-
- Replace the whole menu definition.
- Call like $(...).contextmenu("replaceMenu", "#menu2");.
- or $(...).contextmenu("replaceMenu", [{title: "aaa"}, {title: "bbb"}, ...]);.
-
-
setEntry(cmd, data)
-
- Redefine menu entry (title or all of it).
- `data` may be a title string or a menu definition object.
- Call like $(...).contextmenu("setEntry", "paste", "Paste link");.
-
-
showEntry(cmd, flag)
-
- Show or hide the entry. `flag` defaults to `true`
- Call like $(...).contextmenu("showEntry", "paste", false);.
-
-
-
-
-### Events
-
-jquery-contextmenu exposes events from [jQueryUI menu]: `blur`, `create`, `focus`, `select`.
-However, since the `event.target` parameter contains the menu item, we additionally pass the element
-that was right-clicked in `ui.target`.
-
-Events may be handled by passing a handler callback option:
-```js
-$("#container").contextmenu({
- [...]
- select: function(event, ui) {
- alert("select " + ui.cmd + " on " + ui.target.text());
- }
-});
-```
-
-Alternatively a handler may be bound, so this is equivalent:
-```js
-$("#container").bind("contextmenuselect", function(event, ui) {
- alert("select " + ui.cmd + " on " + ui.target.text());
-}
-```
+For more information:
-
-
beforeOpen(event, ui)
-
- Triggered just before the popup menu is opened.
- Return false to prevent opening.
- This is also a good place to modify the menu (i.e. hiding, disabling, or
- renaming entries, or replace the menu altogether).
-
-
blur(event, ui)
-
- Triggered when the menu loses focus (original jQuery UI Menu event).
-
-
close(event)
-
- Triggered when the menu is closed.
-
-
create(event, ui)
-
- Triggered when the contextmenu widget is created.
-
-
createMenu(event, ui)
-
- Triggered when the popup menu is created (original jQuery UI Menu `create` event).
-
-
focus(event, ui)
-
- Triggered when a menu gains focus or when any menu item is activated (original jQuery UI Menu event).
-
-
open(event)
-
- Triggered when the menu is opened.
-
-
select(event, ui)
-
- Triggered when a menu item is selected.
- ui.cmd contains the command id.
- Return false to prevent closing the menu.
-
-
-
-
-# Tips and Tricks
-### [Howto] Add right-aligned shortcut hints
-
-Simply add a tag of your choice to the title (for example ``)
-```js
-$(document).contextmenu({
- delegate: ".hasmenu",
- menu: [
- {title: "Edit title[F2]", cmd: "rename"},
- {title: "Copy [Ctrl+C]", cmd: "copy"}, ...
- ],
-```
-and make it right aligned via CSS:
-```css
-.ui-menu kbd {
- float: right;
-}
-```
-
-### [Howto] Enable keyboard control
-
-In order open a context menu with the keyboard, make sure the target elements
-are tabbable, for example by adding a `tabindex="0"` attribute.
-Also make sure the `autoFocus: true` option is set.
-This will allow to Use Tab and the Windows Menu keys.
-
-
-### [Howto] Modify the menu using an asynchronous request
-
-```js
-$(document).contextmenu({
- ...
- beforeOpen: function(event, ui) {
- // Immediate menu changes
- $(document).contextmenu("setEntry", "test", "(loading...)");
- // Menu opens, then we submit a request and wait for the resonse
- $.ajax({
- ...
- }).done(function(data) {
- // Modify the menu from the ajax response. The menu will be updated
- // while open
- $(document).contextmenu("setEntry", "test", {
- title: "New entry", cmd: "test",
- children: [ ... ]
- });
- });
- },
-```
-
-Alternatively we can delay the opening until the response arrives:
-```js
-$(document).contextmenu({
- ...
- beforeOpen: function(event, ui) {
- var dfd = new $.Deferred();
-
- $.ajax({
- ...
- }).done(function(data) {
- // Modify the menu from the ajax response. The menu will be opened
- // afterwards
- $(document).contextmenu("setEntry", "test", {
- title: "New entry", cmd: "test",
- children: [ ... ]
- });
- dfd.resolve(); // Notify about finished response
- });
-
- // Return a promise to delay opening until an async response becomes
- // available
- ui.result = dfd.promise();
- },
-```
+ * [Read the Tutorial](https://github.com/mar10/jquery-ui-contextmenu/wiki) and
+ [API Reference](https://github.com/mar10/jquery-ui-contextmenu/wiki/ApiRef)
+ * Have a look at the [Live demo page](http://wwwendt.de/tech/demo/jquery-contextmenu/demo/)
+ * Ask questions on [Stackoverflow](http://stackoverflow.com/questions/tagged/jquery-ui-contextmenu)
+ * Play with [jsFiddle](http://jsfiddle.net/mar10/6o3u8a88/) or
+ [Plunker](http://plnkr.co/edit/Bbcoqy?p=preview)
# Credits
diff --git a/bower.json b/bower.json
index c4eefde..7c27274 100644
--- a/bower.json
+++ b/bower.json
@@ -1,10 +1,11 @@
{
"name": "ui-contextmenu",
"description": "Turn a jQuery UI Menu widget into a contextmenu.",
- "version": "1.10.1-0",
+ "version": "1.18.2-0",
"main": [
"jquery.ui-contextmenu.js"
],
+ "moduleType": "globals",
"license": "MIT",
"ignore": [
"**/.*",
diff --git a/demo/demo.css b/demo/demo.css
new file mode 100644
index 0000000..2a16b0f
--- /dev/null
+++ b/demo/demo.css
@@ -0,0 +1,16 @@
+body {
+ font-family: "Trebuchet MS", "Helvetica", "Arial", "Verdana", "sans-serif";
+ font-size: 0.8em;
+}
+
+p.menu {
+ padding: 5px 16px;
+ background-color: #eee;
+ border: 2px outset;
+}
+
+p.menu b {
+ padding: 5px 16px;
+ background-color: #ccc;
+ border: 2px inset;
+}
\ No newline at end of file
diff --git a/demo/index-1-10.html b/demo/index-1-10.html
index 45ad6b5..6d0c609 100644
--- a/demo/index-1-10.html
+++ b/demo/index-1-10.html
@@ -2,39 +2,40 @@
- jquery.ui-contextmenu.js - Demo (jQuery 1.10)
+ jquery.ui-contextmenu.js - Demo (jQuery UI 1.10)
-
-
-
+
+
+
+
+
-
+
-
+
-
+
+
+
+
+
+
+
+