diff --git a/.gitignore b/.gitignore index ec3c21c..11101b4 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ npm-debug.log .sizecache.json sauce_connect.log +sc_*.log diff --git a/Gruntfile.coffee b/Gruntfile.coffee index 5d8d42a..9ef6494 100644 --- a/Gruntfile.coffee +++ b/Gruntfile.coffee @@ -40,18 +40,20 @@ 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, - tunnelTimeout: 5 build: process.env.TRAVIS_JOB_ID - concurrency: 3 + throttled: 10 browsers: [ { browserName: "chrome", platform: "Windows 7" } { browserName: "firefox", platform: "Windows 7" } 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/demo/index.html b/demo/index.html index 24ad609..e309c75 100644 --- a/demo/index.html +++ b/demo/index.html @@ -8,10 +8,9 @@ - --> + --> - @@ -217,20 +216,20 @@

Sample 2

Sample 3

diff --git a/jquery.ui-contextmenu.js b/jquery.ui-contextmenu.js index bd162e7..ac942d5 100644 --- a/jquery.ui-contextmenu.js +++ b/jquery.ui-contextmenu.js @@ -9,13 +9,8 @@ */ ;(function($, window, document, undefined) { "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 || ""); - } - + var supportSelectstart = "onselectstart" in document.createElement("div"), + match, uiVersion; $.widget("moogle.contextmenu", { version: "1.4.0-1", @@ -141,10 +136,9 @@ select: $.proxy(function(event, ui){ // 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"); - ui.cmd = normCommand($a.attr("href")); + isParent = $.moogle.contextmenu.isMenu(ui.item), + 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 if( !isParent || !this.options.ignoreParentSelect){ @@ -252,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 a[href=#" + normCommand(cmd) + "]"); - 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(){ @@ -265,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(){ @@ -291,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); } }); @@ -322,35 +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{ - $a = $("", { -// text: "" + entry.title, - html: "" + entry.title, // allow to pass HTML markup - href: "#" + normCommand(entry.cmd) - }).appendTo($parentLi); - if( $.isFunction(entry.action) ){ - $a.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