ui-contextmenu
Advanced tools
Comparing version 1.8.1 to 1.8.2
{ | ||
"name": "ui-contextmenu", | ||
"description": "Turn a jQuery UI Menu widget into a contextmenu.", | ||
"version": "1.8.1", | ||
"version": "1.8.2", | ||
"main": [ | ||
@@ -6,0 +6,0 @@ "jquery.ui-contextmenu.js" |
@@ -1,4 +0,9 @@ | ||
# 1.8.2-0 / Unreleased | ||
* | ||
# 1.8.3-0 / Unreleased | ||
# 1.8.2 / 2015-02-08 | ||
* [CHANGE] #82 Add "jquery-ui/menu" as AMD dependency | ||
* [FEATURE] #85 Allow custom classes per entry | ||
* [BUGFIX] #88 Exception when target element is deleted in select event | ||
# 1.8.1 / 2014-12-21 | ||
@@ -5,0 +10,0 @@ |
@@ -8,3 +8,3 @@ /******************************************************************************* | ||
* | ||
* Copyright (c) 2013-2014, Martin Wendt (http://wwWendt.de). Licensed MIT. | ||
* Copyright (c) 2013-2015, Martin Wendt (http://wwWendt.de). Licensed MIT. | ||
*/ | ||
@@ -16,3 +16,3 @@ | ||
// AMD. Register as an anonymous module. | ||
define([ "jquery" ], factory ); | ||
define([ "jquery-ui/menu" ], factory ); | ||
} else { | ||
@@ -27,3 +27,8 @@ // Browser globals | ||
var supportSelectstart = "onselectstart" in document.createElement("div"), | ||
match, uiVersion; | ||
match = $.ui.menu.version.match(/^(\d)\.(\d+)/), | ||
uiVersion = { | ||
major: parseInt(match[1], 10), | ||
minor: parseInt(match[2], 10) | ||
}, | ||
isLTE110 = ( uiVersion.major < 2 && uiVersion.minor < 11 ); | ||
@@ -276,9 +281,13 @@ $.widget("moogle.contextmenu", { | ||
.unbind("keydown" + this.eventNamespace); | ||
this.$menu | ||
.unbind("contextmenu" + this.eventNamespace); | ||
self.currentTarget = null; // issue #44 after hide animation is too late | ||
this._hide(this.$menu, hideOpts, function() { | ||
if ( this.$menu ) { // #88: widget might have been destroyed already | ||
this.$menu | ||
.unbind("contextmenu" + this.eventNamespace); | ||
this._hide(this.$menu, hideOpts, function() { | ||
self._trigger("close"); | ||
}); | ||
} else { | ||
self._trigger("close"); | ||
}); | ||
} | ||
}, | ||
@@ -358,2 +367,50 @@ /** Handle $().contextmenu("option", key, value) calls. */ | ||
$.extend($.moogle.contextmenu, { | ||
/** Convert a menu description into a into a <li> content. */ | ||
createEntryMarkup: function(entry, $parentLi) { | ||
var $a = null; | ||
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 { | ||
if ( isLTE110 ) { | ||
// jQuery UI Menu 1.10 or before required an `<a>` tag | ||
$parentLi.attr("data-command", entry.cmd); | ||
$a = $("<a/>", { | ||
html: "" + entry.title, | ||
href: "#" | ||
}).appendTo($parentLi); | ||
if ( entry.uiIcon ) { | ||
$a.append($("<span class='ui-icon' />").addClass(entry.uiIcon)); | ||
} | ||
} else { | ||
// jQuery UI Menu 1.11+ preferes to avoid `<a>` tags | ||
$parentLi | ||
.attr("data-command", entry.cmd) | ||
.html("" + entry.title); | ||
if ( $.isFunction(entry.action) ) { | ||
$parentLi.data("actionHandler", entry.action); | ||
} | ||
if ( entry.uiIcon ) { | ||
$parentLi | ||
.append($("<span class='ui-icon' />") | ||
.addClass(entry.uiIcon)); | ||
} | ||
} | ||
if ( $.isFunction(entry.action) ) { | ||
$parentLi.data("actionHandler", entry.action); | ||
} | ||
if ( entry.disabled ) { | ||
$parentLi.addClass("ui-state-disabled"); | ||
} | ||
if ( entry.addClass ) { | ||
$parentLi.addClass(entry.addClass); | ||
} | ||
if ( $.isPlainObject(entry.data) ) { | ||
$parentLi.data(entry.data); | ||
} | ||
} | ||
}, | ||
/** Convert a nested array of command objects into a <ul> structure. */ | ||
@@ -378,2 +435,10 @@ createMenuMarkup: function(options, $parentUl) { | ||
}, | ||
/** Returns true if the menu item has child menu items */ | ||
isMenu: function(item) { | ||
if ( isLTE110 ) { | ||
return item.has(">a[aria-haspopup='true']").length > 0; | ||
} else { | ||
return item.is("[aria-haspopup='true']"); | ||
} | ||
}, | ||
/** Replaces the value of elem's first text node child */ | ||
@@ -386,88 +451,13 @@ replaceFirstTextNodeChild: function(elem, text) { | ||
.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 <li> 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 = $("<a/>", { | ||
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($("<span class='ui-icon' />").addClass(entry.uiIcon)); | ||
} | ||
if (entry.disabled) { | ||
$parentLi.addClass("ui-state-disabled"); | ||
} | ||
if ($.isPlainObject(entry.data)) { | ||
$parentLi.data(entry.data); | ||
} | ||
} | ||
}, | ||
/** Returns true if the menu item has child menu items */ | ||
isMenu: function(item) { | ||
return item.has(">a[aria-haspopup='true']").length > 0; | ||
}, | ||
/** Updates the menu item's title */ | ||
updateTitle: function(item, title) { | ||
}, | ||
/** Updates the menu item's title */ | ||
updateTitle: function(item, title) { | ||
if ( isLTE110 ) { | ||
$.moogle.contextmenu.replaceFirstTextNodeChild($("a", item), title); | ||
} | ||
}); | ||
} else { | ||
$.extend($.moogle.contextmenu, { | ||
/** Convert a menu description into a into a <li> content. */ | ||
createEntryMarkup: function(entry, $parentLi) { | ||
if ( !/[^\-\u2014\u2013\s]/.test( entry.title ) ) { | ||
$parentLi.text(entry.title); | ||
} else { | ||
$parentLi | ||
.attr("data-command", entry.cmd) | ||
.html("" + entry.title); | ||
if ( $.isFunction(entry.action) ) { | ||
$parentLi.data("actionHandler", entry.action); | ||
} | ||
if ( entry.uiIcon ) { | ||
$parentLi | ||
.append($("<span class='ui-icon' />") | ||
.addClass(entry.uiIcon)); | ||
} | ||
if ( entry.disabled ) { | ||
$parentLi.addClass("ui-state-disabled"); | ||
} | ||
if ( $.isPlainObject(entry.data) ) { | ||
$parentLi.data(entry.data); | ||
} | ||
} | ||
}, | ||
/** Returns true if the menu item has child menu items */ | ||
isMenu: function(item) { | ||
return item.is("[aria-haspopup='true']"); | ||
}, | ||
/** Updates the menu item's title */ | ||
updateTitle: function(item, title) { | ||
} else { | ||
$.moogle.contextmenu.replaceFirstTextNodeChild(item, title); | ||
} | ||
}); | ||
} | ||
} | ||
}); | ||
})); |
@@ -1,4 +0,4 @@ | ||
/*! jQuery UI context menu plugin - v1.8.1 - 2014-12-21 | https://github.com/mar10/jquery-ui-contextmenu | Copyright (c) 2014 Martin Wendt; Licensed MIT */ | ||
/*! jQuery UI context menu plugin - v1.8.2 - 2015-02-08 | https://github.com/mar10/jquery-ui-contextmenu | Copyright (c) 2015 Martin Wendt; Licensed MIT */ | ||
!function(a){"use strict";"function"==typeof define&&define.amd?define(["jquery"],a):a(jQuery)}(function(a){"use strict";var b,c,d="onselectstart"in document.createElement("div");a.widget("moogle.contextmenu",{version:"@VERSION",options:{addClass:"ui-contextmenu",autoTrigger:!0,delegate:null,hide:{effect:"fadeOut",duration:"fast"},ignoreParentSelect:!0,menu:null,position:null,preventContextMenuForPopup:!1,preventSelect:!1,show:{effect:"slideDown",duration:"fast"},taphold:!1,uiMenuOptions:{},beforeOpen:a.noop,blur:a.noop,close:a.noop,create:a.noop,createMenu:a.noop,focus:a.noop,open:a.noop,select:a.noop},_create:function(){var b,c,e,f=this.options;if(this.$headStyle=null,this.$menu=null,this.menuIsTemp=!1,this.currentTarget=null,f.preventSelect){e=(a(this.element).is(document)?a("body"):this.element).uniqueId().attr("id"),b="#"+e+" "+f.delegate+" { -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; }",this.$headStyle=a("<style class='moogle-contextmenu-style' />").prop("type","text/css").appendTo("head");try{this.$headStyle.html(b)}catch(g){this.$headStyle[0].styleSheet.cssText=b}d&&this.element.delegate(f.delegate,"selectstart"+this.eventNamespace,function(a){a.preventDefault()})}this._createUiMenu(f.menu),c="contextmenu"+this.eventNamespace,f.taphold&&(c+=" taphold"+this.eventNamespace),this.element.delegate(f.delegate,c,a.proxy(this._openMenu,this))},_destroy:function(){this.element.undelegate(this.eventNamespace),this._createUiMenu(null),this.$headStyle&&(this.$headStyle.remove(),this.$headStyle=null)},_createUiMenu:function(b){var c,d=this.options;this.isOpen()&&(c=this.currentTarget,this._closeMenu(!0),this.currentTarget=c),this.menuIsTemp?this.$menu.remove():this.$menu&&this.$menu.menu("destroy").removeClass(this.options.addClass).hide(),this.$menu=null,this.menuIsTemp=!1,b&&(a.isArray(b)?(this.$menu=a.moogle.contextmenu.createMenuMarkup(b),this.menuIsTemp=!0):this.$menu="string"==typeof b?a(b):b,this.$menu.hide().addClass(d.addClass).menu(a.extend(!0,{},d.uiMenuOptions,{blur:a.proxy(d.blur,this),create:a.proxy(d.createMenu,this),focus:a.proxy(d.focus,this),select:a.proxy(function(b,c){var e,f=a.moogle.contextmenu.isMenu(c.item),g=c.item.data("actionHandler");c.cmd=c.item.attr("data-command"),c.target=a(this.currentTarget),f&&d.ignoreParentSelect||(e=this._trigger.call(this,"select",b,c),g&&(e=g.call(this,b,c)),e!==!1&&this._closeMenu.call(this),b.preventDefault())},this)})))},_openMenu:function(b,c){var d,e,f=this.options,g=f.position,h=this,i=!!b.isTrigger,j={menu:this.$menu,target:a(b.target),extraData:b.extraData,originalEvent:b,result:null};if(f.autoTrigger||i){if(b.preventDefault(),this.currentTarget=b.target,!c){if(d=this._trigger("beforeOpen",b,j),e=j.result&&a.isFunction(j.result.promise)?j.result:null,j.result=null,d===!1)return this.currentTarget=null,!1;if(e)return e.done(function(){h._openMenu(b,!0)}),this.currentTarget=null,!1;j.menu=this.$menu}a(document).bind("keydown"+this.eventNamespace,function(b){b.which===a.ui.keyCode.ESCAPE&&h._closeMenu()}).bind("mousedown"+this.eventNamespace+" touchstart"+this.eventNamespace,function(b){a(b.target).closest(".ui-menu-item").length||h._closeMenu()}),a.isFunction(g)&&(g=g(b,j)),g=a.extend({my:"left top",at:"left bottom",of:void 0===b.pageX?b.target:b,collision:"fit"},g),this.$menu.show().css({position:"absolute",left:0,top:0}).position(g).hide(),f.preventContextMenuForPopup&&this.$menu.bind("contextmenu"+this.eventNamespace,function(a){a.preventDefault()}),this._show(this.$menu,this.options.show,function(){h._trigger.call(h,"open",b,j)})}},_closeMenu:function(b){var c=this,d=b?!1:this.options.hide;a(document).unbind("mousedown"+this.eventNamespace).unbind("touchstart"+this.eventNamespace).unbind("keydown"+this.eventNamespace),this.$menu.unbind("contextmenu"+this.eventNamespace),c.currentTarget=null,this._hide(this.$menu,d,function(){c._trigger("close")})},_setOption:function(b,c){switch(b){case"menu":this.replaceMenu(c)}a.Widget.prototype._setOption.apply(this,arguments)},_getMenuEntry:function(a){return this.$menu.find("li[data-command="+a+"]")},close:function(){this.isOpen()&&this._closeMenu()},enableEntry:function(a,b){this._getMenuEntry(a).toggleClass("ui-state-disabled",b===!1)},getMenu:function(){return this.$menu},isOpen:function(){return!!this.$menu&&!!this.currentTarget},open:function(a,b){b=b||{};var c=jQuery.Event("contextmenu",{target:a.get(0),extraData:b});return this.element.trigger(c)},replaceMenu:function(a){this._createUiMenu(a)},setEntry:function(b,c){var d,e=this._getMenuEntry(b);"string"==typeof c?a.moogle.contextmenu.updateTitle(e,c):(e.empty(),c.cmd=c.cmd||b,a.moogle.contextmenu.createEntryMarkup(c,e),a.isArray(c.children)&&(d=a("<ul/>").appendTo(e),a.moogle.contextmenu.createMenuMarkup(c.children,d)),this.getMenu().menu("refresh"))},showEntry:function(a,b){this._getMenuEntry(a).toggle(b!==!1)}}),a.extend(a.moogle.contextmenu,{createMenuMarkup:function(b,c){var d,e,f,g;for(null==c&&(c=a("<ul class='ui-helper-hidden' />").appendTo("body")),d=0;d<b.length;d++)e=b[d],g=a("<li/>").appendTo(c),a.moogle.contextmenu.createEntryMarkup(e,g),a.isArray(e.children)&&(f=a("<ul/>").appendTo(g),a.moogle.contextmenu.createMenuMarkup(e.children,f));return c},replaceFirstTextNodeChild:function(a,b){a.contents().filter(function(){return 3===this.nodeType}).first().replaceWith(b)}}),b=a.ui.menu.version.match(/^(\d)\.(\d+)/),c={major:parseInt(b[1],10),minor:parseInt(b[2],10)},c.major<2&&c.minor<11?a.extend(a.moogle.contextmenu,{createEntryMarkup:function(b,c){var d=null;/[^\-\u2014\u2013\s]/.test(b.title)?(c.attr("data-command",b.cmd),d=a("<a/>",{html:""+b.title,href:"#"}).appendTo(c),a.isFunction(b.action)&&c.data("actionHandler",b.action),b.uiIcon&&d.append(a("<span class='ui-icon' />").addClass(b.uiIcon)),b.disabled&&c.addClass("ui-state-disabled"),a.isPlainObject(b.data)&&c.data(b.data)):c.text(b.title)},isMenu:function(a){return a.has(">a[aria-haspopup='true']").length>0},updateTitle:function(b,c){a.moogle.contextmenu.replaceFirstTextNodeChild(a("a",b),c)}}):a.extend(a.moogle.contextmenu,{createEntryMarkup:function(b,c){/[^\-\u2014\u2013\s]/.test(b.title)?(c.attr("data-command",b.cmd).html(""+b.title),a.isFunction(b.action)&&c.data("actionHandler",b.action),b.uiIcon&&c.append(a("<span class='ui-icon' />").addClass(b.uiIcon)),b.disabled&&c.addClass("ui-state-disabled"),a.isPlainObject(b.data)&&c.data(b.data)):c.text(b.title)},isMenu:function(a){return a.is("[aria-haspopup='true']")},updateTitle:function(b,c){a.moogle.contextmenu.replaceFirstTextNodeChild(b,c)}})}); | ||
!function(a){"use strict";"function"==typeof define&&define.amd?define(["jquery-ui/menu"],a):a(jQuery)}(function(a){"use strict";var b="onselectstart"in document.createElement("div"),c=a.ui.menu.version.match(/^(\d)\.(\d+)/),d={major:parseInt(c[1],10),minor:parseInt(c[2],10)},e=d.major<2&&d.minor<11;a.widget("moogle.contextmenu",{version:"@VERSION",options:{addClass:"ui-contextmenu",autoTrigger:!0,delegate:null,hide:{effect:"fadeOut",duration:"fast"},ignoreParentSelect:!0,menu:null,position:null,preventContextMenuForPopup:!1,preventSelect:!1,show:{effect:"slideDown",duration:"fast"},taphold:!1,uiMenuOptions:{},beforeOpen:a.noop,blur:a.noop,close:a.noop,create:a.noop,createMenu:a.noop,focus:a.noop,open:a.noop,select:a.noop},_create:function(){var c,d,e,f=this.options;if(this.$headStyle=null,this.$menu=null,this.menuIsTemp=!1,this.currentTarget=null,f.preventSelect){e=(a(this.element).is(document)?a("body"):this.element).uniqueId().attr("id"),c="#"+e+" "+f.delegate+" { -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; }",this.$headStyle=a("<style class='moogle-contextmenu-style' />").prop("type","text/css").appendTo("head");try{this.$headStyle.html(c)}catch(g){this.$headStyle[0].styleSheet.cssText=c}b&&this.element.delegate(f.delegate,"selectstart"+this.eventNamespace,function(a){a.preventDefault()})}this._createUiMenu(f.menu),d="contextmenu"+this.eventNamespace,f.taphold&&(d+=" taphold"+this.eventNamespace),this.element.delegate(f.delegate,d,a.proxy(this._openMenu,this))},_destroy:function(){this.element.undelegate(this.eventNamespace),this._createUiMenu(null),this.$headStyle&&(this.$headStyle.remove(),this.$headStyle=null)},_createUiMenu:function(b){var c,d=this.options;this.isOpen()&&(c=this.currentTarget,this._closeMenu(!0),this.currentTarget=c),this.menuIsTemp?this.$menu.remove():this.$menu&&this.$menu.menu("destroy").removeClass(this.options.addClass).hide(),this.$menu=null,this.menuIsTemp=!1,b&&(a.isArray(b)?(this.$menu=a.moogle.contextmenu.createMenuMarkup(b),this.menuIsTemp=!0):this.$menu="string"==typeof b?a(b):b,this.$menu.hide().addClass(d.addClass).menu(a.extend(!0,{},d.uiMenuOptions,{blur:a.proxy(d.blur,this),create:a.proxy(d.createMenu,this),focus:a.proxy(d.focus,this),select:a.proxy(function(b,c){var e,f=a.moogle.contextmenu.isMenu(c.item),g=c.item.data("actionHandler");c.cmd=c.item.attr("data-command"),c.target=a(this.currentTarget),f&&d.ignoreParentSelect||(e=this._trigger.call(this,"select",b,c),g&&(e=g.call(this,b,c)),e!==!1&&this._closeMenu.call(this),b.preventDefault())},this)})))},_openMenu:function(b,c){var d,e,f=this.options,g=f.position,h=this,i=!!b.isTrigger,j={menu:this.$menu,target:a(b.target),extraData:b.extraData,originalEvent:b,result:null};if(f.autoTrigger||i){if(b.preventDefault(),this.currentTarget=b.target,!c){if(d=this._trigger("beforeOpen",b,j),e=j.result&&a.isFunction(j.result.promise)?j.result:null,j.result=null,d===!1)return this.currentTarget=null,!1;if(e)return e.done(function(){h._openMenu(b,!0)}),this.currentTarget=null,!1;j.menu=this.$menu}a(document).bind("keydown"+this.eventNamespace,function(b){b.which===a.ui.keyCode.ESCAPE&&h._closeMenu()}).bind("mousedown"+this.eventNamespace+" touchstart"+this.eventNamespace,function(b){a(b.target).closest(".ui-menu-item").length||h._closeMenu()}),a.isFunction(g)&&(g=g(b,j)),g=a.extend({my:"left top",at:"left bottom",of:void 0===b.pageX?b.target:b,collision:"fit"},g),this.$menu.show().css({position:"absolute",left:0,top:0}).position(g).hide(),f.preventContextMenuForPopup&&this.$menu.bind("contextmenu"+this.eventNamespace,function(a){a.preventDefault()}),this._show(this.$menu,this.options.show,function(){h._trigger.call(h,"open",b,j)})}},_closeMenu:function(b){var c=this,d=b?!1:this.options.hide;a(document).unbind("mousedown"+this.eventNamespace).unbind("touchstart"+this.eventNamespace).unbind("keydown"+this.eventNamespace),c.currentTarget=null,this.$menu?(this.$menu.unbind("contextmenu"+this.eventNamespace),this._hide(this.$menu,d,function(){c._trigger("close")})):c._trigger("close")},_setOption:function(b,c){switch(b){case"menu":this.replaceMenu(c)}a.Widget.prototype._setOption.apply(this,arguments)},_getMenuEntry:function(a){return this.$menu.find("li[data-command="+a+"]")},close:function(){this.isOpen()&&this._closeMenu()},enableEntry:function(a,b){this._getMenuEntry(a).toggleClass("ui-state-disabled",b===!1)},getMenu:function(){return this.$menu},isOpen:function(){return!!this.$menu&&!!this.currentTarget},open:function(a,b){b=b||{};var c=jQuery.Event("contextmenu",{target:a.get(0),extraData:b});return this.element.trigger(c)},replaceMenu:function(a){this._createUiMenu(a)},setEntry:function(b,c){var d,e=this._getMenuEntry(b);"string"==typeof c?a.moogle.contextmenu.updateTitle(e,c):(e.empty(),c.cmd=c.cmd||b,a.moogle.contextmenu.createEntryMarkup(c,e),a.isArray(c.children)&&(d=a("<ul/>").appendTo(e),a.moogle.contextmenu.createMenuMarkup(c.children,d)),this.getMenu().menu("refresh"))},showEntry:function(a,b){this._getMenuEntry(a).toggle(b!==!1)}}),a.extend(a.moogle.contextmenu,{createEntryMarkup:function(b,c){var d=null;/[^\-\u2014\u2013\s]/.test(b.title)?(e?(c.attr("data-command",b.cmd),d=a("<a/>",{html:""+b.title,href:"#"}).appendTo(c),b.uiIcon&&d.append(a("<span class='ui-icon' />").addClass(b.uiIcon))):(c.attr("data-command",b.cmd).html(""+b.title),a.isFunction(b.action)&&c.data("actionHandler",b.action),b.uiIcon&&c.append(a("<span class='ui-icon' />").addClass(b.uiIcon))),a.isFunction(b.action)&&c.data("actionHandler",b.action),b.disabled&&c.addClass("ui-state-disabled"),b.addClass&&c.addClass(b.addClass),a.isPlainObject(b.data)&&c.data(b.data)):c.text(b.title)},createMenuMarkup:function(b,c){var d,e,f,g;for(null==c&&(c=a("<ul class='ui-helper-hidden' />").appendTo("body")),d=0;d<b.length;d++)e=b[d],g=a("<li/>").appendTo(c),a.moogle.contextmenu.createEntryMarkup(e,g),a.isArray(e.children)&&(f=a("<ul/>").appendTo(g),a.moogle.contextmenu.createMenuMarkup(e.children,f));return c},isMenu:function(a){return e?a.has(">a[aria-haspopup='true']").length>0:a.is("[aria-haspopup='true']")},replaceFirstTextNodeChild:function(a,b){a.contents().filter(function(){return 3===this.nodeType}).first().replaceWith(b)},updateTitle:function(b,c){e?a.moogle.contextmenu.replaceFirstTextNodeChild(a("a",b),c):a.moogle.contextmenu.replaceFirstTextNodeChild(b,c)}})}); | ||
//# sourceMappingURL=jquery.ui-contextmenu.min.js.map |
@@ -1,2 +0,2 @@ | ||
Copyright 2013-2014 Martin Wendt and others (see commiter list on GitHub) | ||
Copyright 2013-2015 Martin Wendt and others (see commiter list on GitHub) | ||
https://github.com/mar10/jquery-ui-contextmenu | ||
@@ -3,0 +3,0 @@ |
{ | ||
"name": "ui-contextmenu", | ||
"filename": "jquery.ui-contextmenu.min.js", | ||
"version": "1.8.1", | ||
"version": "1.8.2", | ||
"title": "jQuery UI context menu plugin", | ||
@@ -6,0 +6,0 @@ "description": "Turn a jQuery UI Menu widget into a contextmenu.", |
100
README.md
@@ -26,11 +26,12 @@ # jquery.ui-contextmenu [](https://github.com/mar10/jquery-ui-contextmenu/releases/latest) [](https://travis-ci.org/mar10/jquery-ui-contextmenu) [](https://saucelabs.com/u/sauce-contextmenu) | ||
[Live demo page](http://wwwendt.de/tech/demo/jquery-contextmenu/demo/). | ||
[Live demo page](http://wwwendt.de/tech/demo/jquery-contextmenu/demo/):<br> | ||
[  ](http://wwwendt.de/tech/demo/jquery-contextmenu/demo/ "Live demo") | ||
## Example | ||
## Tutorial | ||
First, include dependencies, i.e. | ||
First, include dependencies: | ||
* jQuery 1.7+ (1.10 or later recommended) | ||
* jQuery UI 1.9+ (at least core, widget, menu), 1.11 recommended | ||
* jQuery UI 1.9+ (at least core, widget, menu), 1.11+ recommended | ||
* One of the ThemeRoller CSS themes or a custom one | ||
@@ -43,3 +44,4 @@ * jquery.ui-contextmenu.js (also available as CDN on | ||
<head> | ||
<link href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css" type="text/css" rel="stylesheet" /> | ||
<link href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css" | ||
type="text/css" rel="stylesheet" /> | ||
<script src="//code.jquery.com/jquery-1.11.1.min.js" type="text/javascript"></script> | ||
@@ -50,3 +52,3 @@ <script src="//code.jquery.com/ui/1.11.2/jquery-ui.min.js" type="text/javascript"></script> | ||
We have some HTML elements that we want to attach a popup menu to: | ||
Assume we have some HTML elements that we want to attach a popup menu to: | ||
@@ -80,2 +82,63 @@ ```html | ||
The `delegate` option defines a CSS selector, which is evaluated for all | ||
elements inside the context element (`#container` in our example).<br> | ||
In order to attach menus to *all* matching elements on the page that have | ||
`class="hasmenu"`, we may use `document` as context: | ||
```js | ||
$(document).contextmenu({ | ||
delegate: ".hasmenu", | ||
... | ||
}); | ||
``` | ||
**Note:** only one contextmenu widget instance can be bound to one element. | ||
The `menu` options may contain a (nested) array of entry defiitions. | ||
Following a list of available properties: | ||
<dl> | ||
<dt>action</dt> | ||
<dd> | ||
Type: <code>Function</code>, default: n.a.<br> | ||
Optional callback that will be executed when the entry is selected. | ||
</dd> | ||
<dt>addClass</dt> | ||
<dd> | ||
Type: <code>String</code>, default: <code>""</code><br> | ||
Additional class name(s) to be added to the entries <li> element. | ||
Separate multiple class names with a space.<br> | ||
Custom CSS may be applied like <code>.ui-menu .my-class { color: red; }</code>. | ||
</dd> | ||
<dt>cmd</dt> | ||
<dd> | ||
Type: <code>String</code>, default: <code>""</code><br> | ||
Optional identifier associated with the menu entry. | ||
It can later be accessed in the <i>select</i> event as <code>ui.cmd</code>. | ||
</dd> | ||
<dt>data</dt> | ||
<dd> | ||
Type: <code>Object</code>, default: <code>{}</code><br> | ||
Optional hash of additional properties that will be added to the entry's | ||
<i>data</i> attribute.<br> | ||
It can later be accessed in the <i>select</i> event as <code>ui.item.data()</code>. | ||
</dd> | ||
<dt>disabled</dt> | ||
<dd> | ||
Type: <code>Boolean</code>, default: <code>false</code><br> | ||
Pass <i>true</i> to disable the entry. | ||
</dd> | ||
<dt>title</dt> | ||
<dd> | ||
Type: <code>String</code>, default: <code>""</code><br> | ||
The displayed name of the menu entry. Use dashes (<code>"---"</code>) to | ||
define a separator. | ||
</dd> | ||
<dt>uiIcon</dt> | ||
<dd> | ||
Type: <code>String</code>, default: ""<br> | ||
If defined, an icon is added to the menu entry. For example passing | ||
<code>"ui-icon-copy"</code> will generate this element: | ||
<code><span class='ui-icon ui-icon-copy' /></code>.<br> | ||
See also <<a href="http://api.jqueryui.com/theming/icons/">Icon Overview</a>. | ||
</dd> | ||
</dl> | ||
Instead of handling all menu commands in the `select` event, it is also possible | ||
@@ -95,13 +158,2 @@ to attach callbacks directly to menu entries: | ||
To attach menus to *all* elements on the page that have `class="hasmenu"`, | ||
we may use `document` as context: | ||
```js | ||
$(document).contextmenu({ | ||
delegate: ".hasmenu", | ||
... | ||
}); | ||
``` | ||
**Note:** only one contextmenu widget instance can be bound to one element. | ||
### Initialize menu from an existing `<ul>` element | ||
@@ -137,6 +189,8 @@ | ||
**Note:** until jQuery UI 1.10 the use of anchors (`<a>`) in menu items was required: | ||
**Note:** until and including jQuery UI 1.10 the use of anchors (`<a>`) in menu | ||
items was required: | ||
```html | ||
<ul id="options" class="ui-helper-hidden"> | ||
<li data-command="copy"><a href="#"><span class="ui-icon ui-icon-copy"></span>Copy</a> | ||
... | ||
</ul> | ||
@@ -148,3 +202,5 @@ ``` | ||
The menu can be modified before display in order to reflect the current context. | ||
Often we need to modify the menu before it is displayed, in order to reflect the | ||
current context. | ||
This can be done in the `beforeOpen` event: | ||
@@ -188,2 +244,3 @@ ```js | ||
### Options | ||
<dl> | ||
@@ -282,2 +339,3 @@ <dt>addClass</dt> | ||
### Methods | ||
<dl> | ||
@@ -329,2 +387,3 @@ <dt>close()</dt> | ||
### Events | ||
jquery-contextmenu exposes events from [jQueryUI menu]: `blur`, `create`, `focus`, `select`. | ||
@@ -386,3 +445,3 @@ However, since the `event.target` parameter contains the menu item, we additionally pass the element | ||
Triggered when a menu item is selected.<br> | ||
<code>ui.cmd</code> contains thecommand id. | ||
<code>ui.cmd</code> contains the command id. | ||
Return <code>false</code> to prevent closing the menu. | ||
@@ -415,3 +474,2 @@ </dd> | ||
```js | ||
@@ -418,0 +476,0 @@ $(document).contextmenu({ |
@@ -374,2 +374,3 @@ // jQUnit defines: | ||
{ title: "Cut", cmd: "cut", uiIcon: "ui-icon-scissors", | ||
data: { foo: "bar" }, addClass: "custom-class-1", | ||
action: function(event, ui) { | ||
@@ -379,2 +380,4 @@ log("cut action"); | ||
equal( ui.target.text(), "AAA", "action: ui.target is set" ); | ||
equal( ui.item.data().foo, "bar", "action: ui.item.data() is set" ); | ||
ok( ui.item.hasClass("custom-class-1"), "action: addClass property works" ); | ||
} | ||
@@ -386,3 +389,3 @@ }, | ||
expect(5); | ||
expect(9); | ||
@@ -403,2 +406,4 @@ $("#container").contextmenu({ | ||
equal( ui.target.text(), "AAA", "select: ui.target is set" ); | ||
equal( ui.item.data().foo, "bar", "ui.item.data() is set" ); | ||
ok( ui.item.hasClass("custom-class-1"), "addClass property works" ); | ||
}, | ||
@@ -405,0 +410,0 @@ close: function(event) { |
{ | ||
"name": "ui-contextmenu", | ||
"version": "1.8.1", | ||
"version": "1.8.2", | ||
"title": "jQuery UI context menu plugin", | ||
@@ -5,0 +5,0 @@ "description": "Turn a jQuery UI Menu widget into a contextmenu.", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
358989
64
520
1544