diff --git a/.jscsrc b/.jscsrc new file mode 100644 index 0000000..25ba9b9 --- /dev/null +++ b/.jscsrc @@ -0,0 +1,82 @@ +{ + "requireCurlyBraces": [ + "if", + "else", + "for", + "while", + "do", + "try", + "catch" + ], + "requireOperatorBeforeLineBreak": true, + "requireParenthesesAroundIIFE": true, + "requireMultipleVarDecl": "onevar", + "requireCommaBeforeLineBreak": true, + "requireCamelCaseOrUpperCaseIdentifiers": true, + "requireDotNotation": true, + "maximumLineLength": { + "value": 100, + "tabSize": 4, + "allowUrlComments": true, + "allowRegex": true + }, + "validateQuoteMarks": { "mark": "\"", "escape": true }, + + "disallowMixedSpacesAndTabs": "smart", + "disallowTrailingWhitespace": true, + "disallowMultipleLineStrings": true, + "disallowTrailingComma": true, + + + "requireSpacesInFunctionExpression": { + "beforeOpeningCurlyBrace": true + }, + "requireSpaceAfterKeywords": [ + "if", + "else", + "for", + "while", + "do", + "switch", + "return", + "try", + "catch" + ], + "requireSpacesInsideObjectBrackets": "all", + "requireSpacesInsideArrayBrackets": "all", + "requireSpacesInConditionalExpression": true, + "requireSpaceAfterBinaryOperators": true, + "requireLineFeedAtFileEnd": true, + "requireSpaceBeforeBinaryOperators": [ + "=", "+=", "-=", "*=", "/=", "%=", "<<=", ">>=", ">>>=", + "&=", "|=", "^=", "+=", + + "+", "-", "*", "/", "%", "<<", ">>", ">>>", "&", + "|", "^", "&&", "||", "===", "==", ">=", + "<=", "<", ">", "!=", "!==" + ], + "requireSpacesInAnonymousFunctionExpression": { + "beforeOpeningCurlyBrace": true + }, + "requireSpacesInNamedFunctionExpression": { + "beforeOpeningCurlyBrace": true + }, + "validateLineBreaks": "LF", + + "disallowKeywords": [ "with" ], + "disallowKeywordsOnNewLine": [ "else" ], + "disallowSpacesInFunctionExpression": { + "beforeOpeningRoundBrace": true + }, + "disallowSpacesInNamedFunctionExpression": { + "beforeOpeningRoundBrace": true + }, + "disallowSpacesInAnonymousFunctionExpression": { + "beforeOpeningRoundBrace": true + }, + "disallowSpaceAfterObjectKeys": true, + "disallowSpaceAfterPrefixUnaryOperators": true, + "disallowSpaceBeforePostfixUnaryOperators": true, + "disallowSpaceBeforeBinaryOperators": [ ",", ":" ], + "disallowMultipleLineBreaks": true +} diff --git a/CHANGELOG.md b/CHANGELOG.md index 378051f..e54a330 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,12 @@ -# 1.6.2 / Unreleased +# 1.8.1-0 / Unreleased + +# 1.8.0 / 2014-11-23 +* [FEATURE] #80 setEntry() supports creating nested menus +* [FEATURE] #81 beforeOpen event accepts deferred as return value +* [BUGFIX] entry data attached to parentLi instead of `` +* Use jscs + +# 1.7.0 / 2014-09-09 * [FEATURE] AMD support (topolm). * [FEATURE] CDN support (http://www.jsdelivr.com/#!jquery.ui-contextmenu). diff --git a/Gruntfile.coffee b/Gruntfile.coffee index 40dde83..625ef84 100644 --- a/Gruntfile.coffee +++ b/Gruntfile.coffee @@ -34,13 +34,19 @@ module.exports = (grunt) -> # 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" + jscs: + src: ["jquery.ui-contextmenu.js", "test/tests.js"] + options: + config: ".jscsrc" + force: true + jshint: files: ["jquery.ui-contextmenu.js", "test/tests.js"] options: jshintrc: ".jshintrc" qunit: - all: ["test/index.html", "test/index-jquery-ui-1-11.html"] + all: ["test/index.html", "test/index-jquery-ui-1-10.html"] # replace: # grunt-text-replace # production: @@ -69,25 +75,27 @@ module.exports = (grunt) -> options: urls: [ "http://localhost:9999/test/index.html", - "http://localhost:9999/test/index-jquery-ui-1-11.html" + "http://localhost:9999/test/index-jquery-ui-1-10.html" ] # username: process.env.SAUCE_USERNAME, # key: process.env.SAUCE_ACCESS_KEY, build: process.env.TRAVIS_JOB_ID - throttled: 11 + throttled: 12 browsers: [ { browserName: "chrome", platform: "Windows 7" } { browserName: "firefox", platform: "Windows 7" } - { browserName: "firefox", platform: "Windows XP" } + # { browserName: "firefox", platform: "Windows XP" } { 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 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" } { browserName: "internet explorer", version: "11", platform: "Windows 8.1" } - { browserName: "safari", platform: "OS X 10.8" } + { 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" } ] testname: "jquery.ui-contextmenu qunit tests" @@ -101,25 +109,30 @@ module.exports = (grunt) -> dest: "jquery.ui-contextmenu.min.js" watch: - jshint: + dev: options: atBegin: true - files: ["jquery.ui-contextmenu.js"] - tasks: ["jshint"] + files: ["jquery.ui-contextmenu.js", "test/tests.js"] + tasks: ["jshint", "jscs"] + # jshint: + # options: + # atBegin: true + # files: ["jquery.ui-contextmenu.js"] + # tasks: ["jshint"] yabs: release: common: # defaults for all tools manifests: ['package.json', 'bower.json', 'ui-contextmenu.jquery.json'] # The following tools are run in order: - check: { clean: true, branch: ['master'], canPush: true } + check: { branch: ['master'], canPush: true, clean: true, cmpVersion: 'gte' } run_test: { tasks: ['test'] } bump: {} # 'bump' also uses the increment mode `yabs:release:MODE` run_build: { tasks: ['build'] } commit: {} check_after_build: { clean: true } # Fails if new files found tag: {} - push: { tags: true } + push: { tags: true, useFollowTags: true } githubRelease: repo: "mar10/jquery-ui-contextmenu" draft: false @@ -133,8 +146,8 @@ module.exports = (grunt) -> grunt.loadNpmTasks key if key isnt "grunt" and key.indexOf("grunt") is 0 grunt.registerTask "server", ["connect:demo"] - grunt.registerTask "dev", ["connect:dev", "watch:jshint"] - grunt.registerTask "test", ["jshint", "qunit"] + grunt.registerTask "dev", ["connect:dev", "watch:dev"] + grunt.registerTask "test", ["jshint", "jscs", "qunit"] grunt.registerTask "sauce", ["connect:sauce", "saucelabs-qunit"] if parseInt(process.env.TRAVIS_PULL_REQUEST, 10) > 0 # saucelab keys do not work on forks diff --git a/MIT-LICENSE.txt b/MIT-LICENSE.txt index 6b19a3a..d631b1d 100644 --- a/MIT-LICENSE.txt +++ b/MIT-LICENSE.txt @@ -1,4 +1,4 @@ -Copyright 2014 Martin Wendt and others (see commiter list on GitHub) +Copyright 2013-2014 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 e595c6a..a902cae 100644 --- a/README.md +++ b/README.md @@ -28,16 +28,16 @@ See also the [Change Log](https://github.com/mar10/jquery-ui-contextmenu/blob/ma First, include dependencies, i.e. -* jQuery 1.7+ (1.10 recommended) -* jQuery UI 1.9+ (at least core, widhet, menu), 1.11 recommended +* jQuery 1.7+ (1.10 or later recommended) +* jQuery UI 1.9+ (at least core, widget, menu), 1.11 recommended * One of the ThemeRoller CSS themes or a custom one * jquery.ui-contextmenu.js (also [available as CDN](http://www.jsdelivr.com/#!jquery.ui-contextmenu)) ```html - + - + ``` @@ -370,7 +370,7 @@ $("#container").bind("contextmenuselect", function(event, ui) { # Tips and Tricks -### Add right-aligned shortcut hints +### [Howto] Add right-aligned shortcut hints Simply add a tag of your choice to the title (for example ``) ```js @@ -389,6 +389,55 @@ and make it right aligned via CSS: ``` +### [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 updated + // while open + $(document).contextmenu("setEntry", "test", { + title: "New entry", cmd: "test", + children: [ ... ] + }); + }); + }, +``` + +Alternively 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(); + }, +``` + + # Credits Thanks to all [contributors](https://github.com/mar10/jquery-ui-contextmenu/contributors). diff --git a/bower.json b/bower.json index 8448d0d..edf8a03 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "ui-contextmenu", "description": "Turn a jQuery UI Menu widget into a contextmenu.", - "version": "1.7.0", + "version": "1.8.0", "main": [ "jquery.ui-contextmenu.js" ], diff --git a/demo/index-1-10.html b/demo/index-1-10.html index 3ae41d7..45ad6b5 100644 --- a/demo/index-1-10.html +++ b/demo/index-1-10.html @@ -2,7 +2,7 @@ - jquery.ui-contextmenu.js - Demo + jquery.ui-contextmenu.js - Demo (jQuery 1.10) diff --git a/demo/index.html b/demo/index.html index eda0e5f..acc9b9b 100644 --- a/demo/index.html +++ b/demo/index.html @@ -2,11 +2,11 @@ - jquery.ui-contextmenu.js - Demo‚ + jquery.ui-contextmenu.js - Demo - + - + @@ -67,7 +67,7 @@ $(function(){ /* Enable a themeroller theme-switching using a combobox. */ $("#switcher").themeswitcher({ - jqueryuiversion: "1.11.1", + jqueryuiversion: "1.11.2", themepath: "//code.jquery.com/ui/", imgpath: "../lib/Super-Theme-Switcher/images/", loadTheme: "Smoothness" @@ -86,9 +86,8 @@ {title: "Paste Ctrl+V", cmd: "paste", uiIcon: "ui-icon-clipboard", disabled: true }, {title: "----"}, {title: "More", children: [ - {title: "Sub 1 (using callback)", action: function(event, ui) { alert("action callback sub1");} }, - {title: "Sub 2 with a long title[F2]", cmd: "sub2"}, - {title: "Sub 3 ", cmd: "sub3"} + {title: "Sub 1 (callback)", action: function(event, ui) { alert("action callback sub1");} }, + {title: "Edit [F2]", cmd: "sub2"}, ]} ], // Handle menu selection to implement a fake-clipboard @@ -188,9 +187,6 @@

jquery.ui-contextmenu.js

-

Sample 1

diff --git a/demo/sample.png b/demo/sample.png new file mode 100644 index 0000000..0211cf8 Binary files /dev/null and b/demo/sample.png differ diff --git a/jquery.ui-contextmenu.js b/jquery.ui-contextmenu.js index 01b85ea..e5c78b5 100644 --- a/jquery.ui-contextmenu.js +++ b/jquery.ui-contextmenu.js @@ -5,7 +5,7 @@ * * @see https://github.com/mar10/jquery-ui-contextmenu * - * Copyright (c) 2014, Martin Wendt (http://wwWendt.de). Licensed MIT. + * Copyright (c) 2013-2014, Martin Wendt (http://wwWendt.de). Licensed MIT. */ (function( factory ) { @@ -18,413 +18,443 @@ factory( jQuery ); } }(function( $ ) { - "use strict"; - var supportSelectstart = "onselectstart" in document.createElement("div"), - match, uiVersion; - $.widget("moogle.contextmenu", { - version: "@VERSION", - options: { - autoTrigger: true, // open menu on browser's `contextmenu` event - delegate: null, // selector - hide: { effect: "fadeOut", duration: "fast"}, - ignoreParentSelect: true, // Don't trigger 'select' for sub-menu parents - menu: null, // selector or jQuery pointing to