From 5212d2e8abdead0a6ae8d27c52ed7263537e6cd9 Mon Sep 17 00:00:00 2001 From: "Martin@MBP" Date: Sat, 18 Mar 2017 15:05:57 +0100 Subject: [PATCH] Pass `ui` argument to `open` event Close #113 --- CHANGELOG.md | 10 ++++++- Gruntfile.coffee | 63 ++++++++++++++++++++++------------------ README.md | 4 +++ jquery.ui-contextmenu.js | 7 +++-- test/tests.js | 9 ++++-- 5 files changed, 57 insertions(+), 36 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9992567..d4452d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,12 @@ -# 1.14.0-0 / Unreleased +# 1.15.1-0 / Unreleased + + * + +# 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" diff --git a/Gruntfile.coffee b/Gruntfile.coffee index 6de0e39..9a7b9b4 100644 --- a/Gruntfile.coffee +++ b/Gruntfile.coffee @@ -82,71 +82,76 @@ module.exports = (grunt) -> throttled: 5 browsers: [ { browserName: "chrome", platform: "Windows 8.1" } - { browserName: "firefox", 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: "6", platform: "Windows XP" } + # { browserName: "internet explorer", version: "7", platform: "Windows XP" } + # { browserName: "internet explorer", version: "8", platform: "Windows 7" } { browserName: "internet explorer", version: "11", platform: "Windows 8.1" } { browserName: "microsoftedge", platform: "Windows 10" } - { browserName: "safari", version: "9", platform: "OS X 10.11" } + # { browserName: "safari", version: "9", platform: "OS X 10.11" } + { browserName: "safari", version: "10", platform: "OS X 10.12" } ] testname: "jquery.ui-contextmenu qunit tests (jQuery UI 10)" # statusCheckAttempts: 180 recordVideo: false videoUploadOnPass: false - ui_12: + ui_11: # UI Menu 11+ dropped support for IE7 options: urls: [ - "http://localhost:9999/test/test-jquery-3-ui-1.12.html" + "http://localhost:9999/test/test-jquery-1.11-ui-1.11.html" + # "http://localhost:9999/test/index.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: 5 browsers: [ { browserName: "chrome", platform: "Windows 8.1" } - { browserName: "firefox", platform: "Windows 8.1" } + # { browserName: "firefox", platform: "Windows 8.1" } + # { browserName: "firefox", platform: "Windows XP" } { browserName: "firefox", platform: "Linux" } + # 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: "microsoftedge", platform: "Windows 10" } - { browserName: "safari", version: "9", platform: "OS X 10.11" } + # { 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" } ] - testname: "jquery.ui-contextmenu qunit tests (jQuery UI 12)" + testname: "jquery.ui-contextmenu qunit tests (jQuery UI 11+)" # statusCheckAttempts: 180 recordVideo: false videoUploadOnPass: false - ui: # UI Menu 11+ dropped support for IE7 + ui_12: options: urls: [ - "http://localhost:9999/test/test-jquery-1.11-ui-1.11.html" - # "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: 5 browsers: [ { browserName: "chrome", platform: "Windows 8.1" } { browserName: "firefox", platform: "Windows 8.1" } - # { browserName: "firefox", platform: "Windows XP" } { browserName: "firefox", platform: "Linux" } - # jQuery UI 11+ stopped support for IE 7 - # { 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: "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: "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" } ] - testname: "jquery.ui-contextmenu qunit tests (jQuery UI 11+)" + testname: "jquery.ui-contextmenu qunit tests (jQuery UI 12)" # statusCheckAttempts: 180 recordVideo: false videoUploadOnPass: false @@ -203,7 +208,7 @@ module.exports = (grunt) -> 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", "saucelabs-qunit:ui_12"] + 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 diff --git a/README.md b/README.md index 69add07..1c47bdf 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,10 @@ $("#container").contextmenu({ }); ``` +Alternatively we can + +initialaize the menu from embedded <ul> markup. + For more information: * [Read the Tutorial](https://github.com/mar10/jquery-ui-contextmenu/wiki) and diff --git a/jquery.ui-contextmenu.js b/jquery.ui-contextmenu.js index 1b21c68..13c48f2 100644 --- a/jquery.ui-contextmenu.js +++ b/jquery.ui-contextmenu.js @@ -279,7 +279,8 @@ $.widget("moogle.contextmenu", { /** Close popup. */ _closeMenu: function(immediately) { var self = this, - hideOpts = immediately ? false : this.options.hide; + hideOpts = immediately ? false : this.options.hide, + ui = { menu: this.$menu, target: $(this.currentTarget) }; // Note: we don't want to unbind the 'contextmenu' event $(document) @@ -296,10 +297,10 @@ $.widget("moogle.contextmenu", { self.previousFocus.focus(); self.previousFocus = null; } - self._trigger("close"); + self._trigger("close", null, ui); }); } else { - self._trigger("close"); + self._trigger("close", null, ui); } }, /** Handle $().contextmenu("option", key, value) calls. */ diff --git a/test/tests.js b/test/tests.js index 987d79f..8daf1d4 100644 --- a/test/tests.js +++ b/test/tests.js @@ -293,7 +293,7 @@ function _clickTest(menu, assert) { var $ctx, $popup, done = assert.async(); - assert.expect(3); + assert.expect(6); $("#container").contextmenu({ delegate: ".hasmenu", @@ -302,6 +302,7 @@ function _clickTest(menu, assert) { // hide: false, beforeOpen: function(event, ui) { log("beforeOpen(" + ui.target.text() + ")"); + assert.equal( ui.target.text(), "AAA", "beforeOpen: ui.target is set" ); }, create: function(event, ui) { log("create"); @@ -330,15 +331,17 @@ function _clickTest(menu, assert) { assert.equal( ui.cmd, "cut", "select: ui.cmd is set" ); assert.equal( ui.target.text(), "AAA", "select: ui.target is set" ); }, - open: function(event) { + open: function(event, ui) { log("open"); + assert.equal( ui.target.text(), "AAA", "open: ui.target is set" ); setTimeout(function() { entryEvent($popup, 0, "mouseenter"); click($popup, 0); }, 10); }, - close: function(event) { + close: function(event, ui) { log("close"); + assert.equal( ui.target.text(), "AAA", "open: ui.target is set" ); assert.equal(logOutput(), "createMenu,create,open(),beforeOpen(AAA),after open(),open,select(cut),close", "Event sequence OK.");