From 5a2591c9b0496210b91eeb5b296228376b2d8107 Mon Sep 17 00:00:00 2001 From: "Martin@MBP" Date: Tue, 24 Jun 2014 23:02:10 +0200 Subject: [PATCH 01/12] Bump prerelease (1.4.3-0) [ci skip] --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 013db5c..207fe42 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ui-contextmenu", - "version": "1.4.2", + "version": "1.4.3-0", "title": "jQuery UI context menu plugin", "description": "Turn a jQuery UI Menu widget into a contextmenu.", "keywords": [ From 24a958c171f6e0959d50f9fc8dc9c8815a9d3576 Mon Sep 17 00:00:00 2001 From: "Martin@MBP" Date: Thu, 26 Jun 2014 07:50:38 +0200 Subject: [PATCH 02/12] Auto generate manifest Closed #20 --- Gruntfile.coffee | 3 ++- bower.json | 2 +- package.json | 4 ++-- ui-contextmenu.jquery.json | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Gruntfile.coffee b/Gruntfile.coffee index 6c74e50..5d8d42a 100644 --- a/Gruntfile.coffee +++ b/Gruntfile.coffee @@ -92,7 +92,8 @@ module.exports = (grunt) -> run_test: { tasks: ['test'] } bump: {} # 'bump' also uses the increment mode `yabs:release:MODE` run_build: { tasks: ['build'] } - commit: { add: '.' } + commit: {} + check_after_build: { clean: true } # Fails if new files found tag: {} push: { tags: true } bump_develop: { inc: 'prepatch' } diff --git a/bower.json b/bower.json index 42357a1..a529061 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.4.2", + "version": "1.4.3-0", "main": [ "jquery.ui-contextmenu.js" ], diff --git a/package.json b/package.json index 207fe42..6bafcc0 100644 --- a/package.json +++ b/package.json @@ -46,9 +46,9 @@ "grunt-exec": "~0.4.0", "grunt-saucelabs": "~4.1.2", "grunt-contrib-watch": "~0.5.3", - "grunt-yabs": "0.0.5" + "grunt-yabs": "0.0.6" }, "scripts": { "test": "grunt ci --verbose" } -} \ No newline at end of file +} diff --git a/ui-contextmenu.jquery.json b/ui-contextmenu.jquery.json index 2b9376b..c5417c2 100644 --- a/ui-contextmenu.jquery.json +++ b/ui-contextmenu.jquery.json @@ -1,6 +1,6 @@ { "name": "ui-contextmenu", - "version": "1.4.2", + "version": "1.4.3-0", "title": "jQuery UI context menu plugin", "description": "Turn a jQuery UI Menu widget into a contextmenu.", "keywords": [ From fa513118eda627102f289e15486162364953fe0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vas=20G=C3=A1bor?= Date: Tue, 1 Jul 2014 17:34:51 +0200 Subject: [PATCH 03/12] The command must be specified in the data-command attribute of the
  • element instead of the anchor's href. --- README.md | 13 +++++++------ jquery.ui-contextmenu.js | 13 ++++--------- test/index.html | 10 +++++----- test/tests.js | 8 ++++---- 4 files changed, 20 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index cf2738f..427fe5c 100644 --- a/README.md +++ b/README.md @@ -94,18 +94,19 @@ $(document).contextmenu({ }); ``` -We also have to provide some HTML markup that defines the context menu -structure (see [jQueryUI menu] for details): +We also have to provide some HTML markup that defines the context menu structure, see +[jQueryUI menu] for details. jQuery UI 1.11 removed the requirement to use anchors in menu +items, so the `` tags should be omitted: ```html ``` diff --git a/jquery.ui-contextmenu.js b/jquery.ui-contextmenu.js index bd162e7..189c690 100644 --- a/jquery.ui-contextmenu.js +++ b/jquery.ui-contextmenu.js @@ -11,12 +11,6 @@ "use strict"; var supportSelectstart = "onselectstart" in document.createElement("div"); - /** Return command without leading '#' (default to ""). */ - function normCommand(cmd){ - return (cmd && cmd.match(/^#/)) ? cmd.substring(1) : (cmd || ""); - } - - $.widget("moogle.contextmenu", { version: "1.4.0-1", options: { @@ -144,7 +138,7 @@ isParent = (ui.item.has(">a[aria-haspopup='true']").length > 0), $a = ui.item.find(">a"), actionHandler = $a.data("actionHandler"); - ui.cmd = normCommand($a.attr("href")); + ui.cmd = ui.item.attr("data-command"); ui.target = $(this.currentTarget); // ignore clicks, if they only open a sub-menu if( !isParent || !this.options.ignoreParentSelect){ @@ -254,7 +248,7 @@ }, /** Return ui-menu entry ( or
  • tag). */ _getMenuEntry: function(cmd, wantLi){ - var $entry = this.$menu.find("li a[href=#" + normCommand(cmd) + "]"); + var $entry = this.$menu.find("li[data-command=" + cmd + "] a"); return wantLi ? $entry.closest("li") : $entry; }, /** Close context menu. */ @@ -331,10 +325,11 @@ $.extend($.moogle.contextmenu, { // hyphen, em dash, en dash: separator as defined by UI Menu 1.10 $parentLi.text(entry.title); }else{ + $parentLi.attr("data-command", entry.cmd); $a = $("", { // text: "" + entry.title, html: "" + entry.title, // allow to pass HTML markup - href: "#" + normCommand(entry.cmd) + href: "#" }).appendTo($parentLi); if( $.isFunction(entry.action) ){ $a.data("actionHandler", entry.action); diff --git a/test/index.html b/test/index.html index ef48ae8..34dda46 100644 --- a/test/index.html +++ b/test/index.html @@ -30,14 +30,14 @@

    Sample Markup

    diff --git a/test/tests.js b/test/tests.js index 983eaa6..aa7b88c 100644 --- a/test/tests.js +++ b/test/tests.js @@ -275,7 +275,7 @@ function _clickTest(menu){ // }, select: function(event, ui){ // window.console.log("select"); - var t = ui.item ? $(ui.item).find("a:first").attr("href") : ui.item; + var t = ui.item ? $(ui.item).attr("data-command") : ui.item; log("select(" + t + ")"); equal( ui.cmd, "cut", "select: ui.cmd is set" ); equal( ui.target.text(), "AAA", "select: ui.target is set" ); @@ -301,7 +301,7 @@ function _clickTest(menu){ setTimeout(function(){ // TODO: why is focus() called twice? - equal(logOutput(), "createMenu,create,open(),beforeOpen(AAA),after open(),open,select(#cut),close", + equal(logOutput(), "createMenu,create,open(),beforeOpen(AAA),after open(),open,select(cut),close", "Event sequence OK."); start(); }, 1000); @@ -349,7 +349,7 @@ asyncTest("Array menu", function(){ }, 10); }, select: function(event, ui){ - var t = ui.item ? $(ui.item).find("a:first").attr("href") : ui.item; + var t = ui.item ? $(ui.item).attr("data-command") : ui.item; log("select(" + t + ")"); equal( ui.cmd, "cut", "select: ui.cmd is set" ); equal( ui.target.text(), "AAA", "select: ui.target is set" ); @@ -367,7 +367,7 @@ asyncTest("Array menu", function(){ log("after open()"); setTimeout(function(){ - equal(logOutput(), "open(),after open(),open,select(#cut),cut action,close", + equal(logOutput(), "open(),after open(),open,select(cut),cut action,close", "Event sequence OK."); start(); }, 500); From 01a936909348b3390c83cfce07c9a49af9232834 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vas=20G=C3=A1bor?= Date: Tue, 1 Jul 2014 18:08:04 +0200 Subject: [PATCH 04/12] The actionHandler is stored in the
  • element instead of the element. --- jquery.ui-contextmenu.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/jquery.ui-contextmenu.js b/jquery.ui-contextmenu.js index 189c690..13e366b 100644 --- a/jquery.ui-contextmenu.js +++ b/jquery.ui-contextmenu.js @@ -136,8 +136,7 @@ // User selected a menu entry var retval, isParent = (ui.item.has(">a[aria-haspopup='true']").length > 0), - $a = ui.item.find(">a"), - actionHandler = $a.data("actionHandler"); + actionHandler = ui.item.data("actionHandler"); ui.cmd = ui.item.attr("data-command"); ui.target = $(this.currentTarget); // ignore clicks, if they only open a sub-menu @@ -332,7 +331,7 @@ $.extend($.moogle.contextmenu, { href: "#" }).appendTo($parentLi); if( $.isFunction(entry.action) ){ - $a.data("actionHandler", entry.action); + $parentLi.data("actionHandler", entry.action); } if(entry.uiIcon){ $a.append($("").addClass(entry.uiIcon)); From 8f3f32e4362adcd384fcb4a94d5154439f90bb0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vas=20G=C3=A1bor?= Date: Wed, 2 Jul 2014 09:03:29 +0200 Subject: [PATCH 05/12] Differences between jQuery UI < 1.11 and jQuery UI >= 11 are handled. --- Gruntfile.coffee | 7 +- jquery.ui-contextmenu.js | 156 ++++++++++++++++++++++----------- test/index-jquery-ui-1-11.html | 41 +++++++++ test/index.html | 2 +- test/issue-33.html | 2 +- test/tests.js | 19 +++- 6 files changed, 167 insertions(+), 60 deletions(-) create mode 100644 test/index-jquery-ui-1-11.html diff --git a/Gruntfile.coffee b/Gruntfile.coffee index 5d8d42a..29fcfef 100644 --- a/Gruntfile.coffee +++ b/Gruntfile.coffee @@ -40,12 +40,15 @@ module.exports = (grunt) -> jshintrc: ".jshintrc" qunit: - all: ["test/index.html"] + all: ["test/index.html", "test/index-jquery-ui-1-11.html"] "saucelabs-qunit": all: options: - urls: ["http://localhost:9999/test/index.html"] + urls: [ + "http://localhost:9999/test/index.html", + "http://localhost:9999/test/index-jquery-ui-1-11.html" + ] # username: process.env.SAUCE_USERNAME, # key: process.env.SAUCE_ACCESS_KEY, diff --git a/jquery.ui-contextmenu.js b/jquery.ui-contextmenu.js index 13e366b..9cc93aa 100644 --- a/jquery.ui-contextmenu.js +++ b/jquery.ui-contextmenu.js @@ -9,7 +9,8 @@ */ ;(function($, window, document, undefined) { "use strict"; - var supportSelectstart = "onselectstart" in document.createElement("div"); + var supportSelectstart = "onselectstart" in document.createElement("div"), + match, uiVersion; $.widget("moogle.contextmenu", { version: "1.4.0-1", @@ -135,7 +136,7 @@ select: $.proxy(function(event, ui){ // User selected a menu entry var retval, - isParent = (ui.item.has(">a[aria-haspopup='true']").length > 0), + isParent = $.moogle.contextmenu.isMenu(ui.item), actionHandler = ui.item.data("actionHandler"); ui.cmd = ui.item.attr("data-command"); ui.target = $(this.currentTarget); @@ -245,10 +246,9 @@ } $.Widget.prototype._setOption.apply(this, arguments); }, - /** Return ui-menu entry ( or
  • tag). */ - _getMenuEntry: function(cmd, wantLi){ - var $entry = this.$menu.find("li[data-command=" + cmd + "] a"); - return wantLi ? $entry.closest("li") : $entry; + /** Return ui-menu entry (
  • tag). */ + _getMenuEntry: function(cmd){ + return this.$menu.find("li[data-command=" + cmd + "]"); }, /** Close context menu. */ close: function(){ @@ -258,7 +258,7 @@ }, /** Enable or disable the menu command. */ enableEntry: function(cmd, flag){ - this._getMenuEntry(cmd, true).toggleClass("ui-state-disabled", (flag === false)); + this._getMenuEntry(cmd).toggleClass("ui-state-disabled", (flag === false)); }, /** Return Menu element (UL). */ getMenu: function(){ @@ -284,30 +284,19 @@ }, /** Redefine menu entry (title or all of it). */ setEntry: function(cmd, titleOrData){ - var $parent, - $entry = this._getMenuEntry(cmd, false); + var $entry = this._getMenuEntry(cmd); if(typeof titleOrData === "string"){ - if( $entry.children("span").length){ - // Replace text without removing child - $entry - .contents() - .filter(function(){ return this.nodeType === 3; }) - .first() - .replaceWith(titleOrData); - }else{ - // tag only contains text (above code doesn't work here) - $entry.text(titleOrData); - } + $.moogle.contextmenu.updateTitle($entry, titleOrData); }else{ - $parent = $entry.closest("li").empty(); + $entry.empty(); titleOrData.cmd = titleOrData.cmd || cmd; - $.moogle.contextmenu.createEntryMarkup(titleOrData, $parent); + $.moogle.contextmenu.createEntryMarkup(titleOrData, $entry); } }, /** Show or hide the menu command. */ showEntry: function(cmd, flag){ - this._getMenuEntry(cmd, true).toggle(flag !== false); + this._getMenuEntry(cmd).toggle(flag !== false); } }); @@ -315,36 +304,6 @@ * Global functions */ $.extend($.moogle.contextmenu, { - /** Convert a menu description into a into a
  • content. */ - createEntryMarkup: function(entry, $parentLi){ - var $a = null; - - // if(entry.title.match(/^---/)){ - if( !/[^\-\u2014\u2013\s]/.test( entry.title ) ){ - // hyphen, em dash, en dash: separator as defined by UI Menu 1.10 - $parentLi.text(entry.title); - }else{ - $parentLi.attr("data-command", entry.cmd); - $a = $("", { -// text: "" + entry.title, - html: "" + entry.title, // allow to pass HTML markup - href: "#" - }).appendTo($parentLi); - if( $.isFunction(entry.action) ){ - $parentLi.data("actionHandler", entry.action); - } - if(entry.uiIcon){ - $a.append($("").addClass(entry.uiIcon)); - } - if(entry.disabled){ - $parentLi.addClass("ui-state-disabled"); - } - if($.isPlainObject(entry.data)){ - $a.data(entry.data); - } - } - return $a; - }, /** Convert a nested array of command objects into a