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 structure. */
createMenuMarkup: function(options, $parentUl){
var i, menu, $ul, $li;
@@ -369,7 +322,98 @@ $.extend($.moogle.contextmenu, {
}
}
return $parentUl;
+ },
+ /** Replaces the value of elem's first text node child*/
+ replaceFirstTextNodeChild: function(elem, text) {
+ elem
+ .contents()
+ .filter(function(){ return this.nodeType === 3; })
+ .first()
+ .replaceWith(text);
}
});
+ match = $.ui.menu.version.match(/^(\d)\.(\d+)/);
+
+ uiVersion = {
+ major: parseInt(match[1], 10),
+ minor: parseInt(match[2], 10)
+ };
+
+ if ( uiVersion.major < 2 && uiVersion.minor < 11 ) {
+ $.extend($.moogle.contextmenu, {
+ /** Convert a menu description into a into a
jquery.ui-contextmenu Test Suite for jQuery UI >= 1.11.0
+
+
+
+
+
+ Sample Markup
+ Sample Markup
diff --git a/test/issue-33.html b/test/issue-33.html index ef9c1cc..6b24fe3 100644 --- a/test/issue-33.html +++ b/test/issue-33.html @@ -1,5 +1,5 @@ - + diff --git a/test/tests.js b/test/tests.js index 983eaa6..371ea86 100644 --- a/test/tests.js +++ b/test/tests.js @@ -10,7 +10,12 @@ function TestHelpers() { var lastItem = "", log = [], - $ = jQuery; + $ = jQuery, + match = $.ui.menu.version.match(/^(\d)\.(\d+)/), + uiVersion = { + major: parseInt(match[1], 10), + minor: parseInt(match[2], 10) + }; return { log: function( message, clear ) { @@ -32,12 +37,20 @@ function TestHelpers() { entryEvent: function( menu, item, type ) { lastItem = item; // window.console.log(type + ": ", menu.children( ":eq(" + item + ")" ).find( "a:first" ).length); - menu.children( ":eq(" + item + ")" ).find( "a:first" ).trigger( type ); + if ( uiVersion.major < 2 && uiVersion.minor < 11 ) { + menu.children( ":eq(" + item + ")" ).find( "a:first" ).trigger( type ); + } else { + menu.children( ":eq(" + item + ")" ).trigger( type ); + } }, click: function( menu, item ) { lastItem = item; // window.console.log("clck: ", menu.children( ":eq(" + item + ")" ).find( "a:first" ).length); - menu.children( ":eq(" + item + ")" ).find( "a:first" ).trigger( "click" ); + if ( uiVersion.major < 2 && uiVersion.minor < 11 ) { + menu.children( ":eq(" + item + ")" ).find( "a:first" ).trigger( "click" ); + } else { + menu.children( ":eq(" + item + ")" ).trigger( "click" ); + } }, entry: function( menu, item ) { return menu.children( ":eq(" + item + ")" ); @@ -54,11 +67,6 @@ jQuery(document).ready(function(){ /******************************************************************************* * QUnit setup */ -QUnit.log(function(data) { - if (window.console && window.console.log) { -// window.console.log(data.result + " :: " + data.message); - } -}); QUnit.config.requireExpects = true; @@ -90,10 +98,38 @@ var th = new TestHelpers(), {title: "Sub Item 2", cmd: "sub2" } ]} ], - $ = jQuery; - + $ = jQuery, + sauceLabsLog = []; + +// SauceLabs integration +QUnit.testStart(function (testDetails) { + QUnit.log = function (details) { + if (!details.result) { + details.name = testDetails.name; + sauceLabsLog.push(details); + } + }; +}); +QUnit.done(function (testResults) { + var tests = [], + i, len, details; + for (i = 0, len = sauceLabsLog.length; i < len; i++) { + details = sauceLabsLog[i]; + tests.push({ + name: details.name, + result: details.result, + expected: details.expected, + actual: details.actual, + source: details.source + }); + } + testResults.tests = tests; + /*jshint camelcase:false*/ + window.global_test_results = testResults; + /*jshint camelcase:true*/ +}); //--------------------------------------------------------------------------- @@ -275,7 +311,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 +337,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 +385,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 +403,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);