diff --git a/jquery.ui-contextmenu.js b/jquery.ui-contextmenu.js
index aa73ad3..c7fbd05 100644
--- a/jquery.ui-contextmenu.js
+++ b/jquery.ui-contextmenu.js
@@ -22,24 +22,25 @@
$.widget("ui.contextmenu", {
- version: "0.4.0",
+ version: "0.4.1",
options: {
- delegate: "[data-menu]", // selector
+ delegate: "[data-menu]", // selector
hide: { effect: "fadeOut", duration: "fast"},
show: { effect: "slideDown", duration: "slow"},
- ignoreParentSelect: true, // Don't trigger 'select' for sub-menu parents
- menu: null, // selector or jQuery or a function returning such
- preventSelect: false, // disable text selection of target
- taphold: false, // open menu on taphold events (requires external plugins)
+ position: null, // specify positional preferences (added for issue #18 and #13).
+ ignoreParentSelect: true, // Don't trigger 'select' for sub-menu parents
+ menu: null, // selector or jQuery or a function returning such
+ preventSelect: false, // disable text selection of target
+ taphold: false, // open menu on taphold events (requires external plugins)
// Events:
- beforeOpen: $.noop, // menu about to open; return `false` to prevent opening
- blur: $.noop, // menu option lost focus
- close: $.noop, // menu was closed
- create: $.noop, // menu was initialized
- focus: $.noop, // menu option got focus
- init: $.noop, // ui-contextmenu was initialized
- open: $.noop, // menu was opened
- select: $.noop // menu option was selected; return `false` to prevent closing
+ beforeOpen: $.noop, // menu about to open; return `false` to prevent opening
+ blur: $.noop, // menu option lost focus
+ close: $.noop, // menu was closed
+ create: $.noop, // menu was initialized
+ focus: $.noop, // menu option got focus
+ init: $.noop, // ui-contextmenu was initialized
+ open: $.noop, // menu was opened
+ select: $.noop // menu option was selected; return `false` to prevent closing
},
/** Construtcor */
_create: function () {
@@ -155,6 +156,27 @@
self._closeMenu();
}
});
+
+ // required for custom positioning (issue #18 and #13).
+ var posOption = this.options.position;
+
+ if (posOption == null) {
+ posOption = {
+ my: "left top",
+ at: "left bottom",
+ of: parentTarget,
+ collision: "fit"
+ }
+ } else if (jQuery.isFunction(this.options.position)) {
+ posOption = posOption(event, ui);
+ } else {
+ // do we need to add the of?
+ var posTarget = posOption.of;
+ if (posTarget == null) {
+ posOption.of = parentTarget;
+ }
+ }
+
// Finally display the popup
$menu
.show() // required to fix positioning error (issue #3)
@@ -162,12 +184,7 @@
position: "absolute",
left: 0,
top: 0
- }).position({
- my: "left top",
- at: "left bottom",
- of: parentTarget,
- collision: "fit"
- }).hide();
+ }).position(posOption).hide();
this._show($menu, this.options.show, function(){
self._trigger.call(self, "open", event);
@@ -232,15 +249,15 @@
$menu.menu("refresh");
}else{
$.error("not implemented");
-// this.orgMenu = opts.menu;
-// opts.menu = $.ui.contextmenu.createMenuMarkup(data);
+// this.orgMenu = opts.menu;
+// opts.menu = $.ui.contextmenu.createMenuMarkup(data);
}
}else{
-// if(this.orgMenu){
-// // re-use existing temporary
-// }else{
-// }
-// $menu.menu("option", "menu", opts.menu);
+// if(this.orgMenu){
+// // re-use existing temporary
+// }else{
+// }
+// $menu.menu("option", "menu", opts.menu);
$.error("not implemented");
}
},
diff --git a/jquery.ui-contextmenu.min.js b/jquery.ui-contextmenu.min.js
index 4712583..0f324ed 100644
--- a/jquery.ui-contextmenu.min.js
+++ b/jquery.ui-contextmenu.min.js
@@ -1,2 +1 @@
-/*! jQuery UI context menu plugin - v0.3.0 - 2013-05-20 | https://github.com/mar10/jquery-ui-contextmenu | Copyright (c) 2013 Martin Wendt; Licensed MIT */
-(function(e){function t(e){return e&&e.match(/^#/)?e.substring(1):e||""}var n="onselectstart"in document.createElement("div");e.widget("ui.contextmenu",{version:"0.3.0",options:{delegate:"[data-menu]",hide:{effect:"fadeOut",duration:"fast"},show:{effect:"slideDown",duration:"slow"},ignoreParentSelect:!0,menu:null,preventSelect:!1,taphold:!1,beforeOpen:e.noop,blur:e.noop,close:e.noop,create:e.noop,focus:e.noop,init:e.noop,open:e.noop,select:e.noop},_create:function(){var t,i,s=this.options;this.$headStyle=null,this.orgMenu=null,this.currentTarget=null,this.ns="."+this.widgetName,s.preventSelect&&(i=(e(this.element).is(document)?e("body"):this.element).uniqueId().attr("id"),this.$headStyle=e("").prop("type","text/css").html("#"+i+" "+s.delegate+" { "+"-webkit-user-select: none; "+"-khtml-user-select: none; "+"-moz-user-select: none; "+"-ms-user-select: none; "+"user-select: none; "+"}").appendTo("head"),n&&this.element.delegate(s.delegate,"selectstart"+this.ns,function(e){e.preventDefault()})),e.isArray(s.menu)&&(this.orgMenu=s.menu,s.menu=e.ui.contextmenu.createMenuMarkup(s.menu)),this._getMenu().hide().addClass("ui-contextmenu").menu({blur:e.proxy(this.options.blur,this),create:e.proxy(this.options.create,this),focus:e.proxy(this.options.focus,this),select:e.proxy(function(e,t){e.relatedTarget=this.currentTarget;var n=t.item.has(">a[aria-haspopup='true']").length>0;n&&this.options.ignoreParentSelect||(this._trigger.call(this,"select",e,t)!==!1&&this._closeMenu.call(this),e.preventDefault())},this)}),t="contextmenu"+this.ns,s.taphold&&(t+=" taphold"+this.ns),this.element.delegate(s.delegate,t,e.proxy(this._openMenu,this)),this._trigger("init")},_destroy:function(){this.$headStyle&&(this.$headStyle.remove(),this.$headStyle=null),this.orgMenu&&(this.options.menu.remove(),this.options.menu=this.orgMenu,this.orgMenu=null)},_openMenu:function(t){var n=this,i=this._getMenu(),s=t,o=s.target?s.target:s,r={menu:i};return this.currentTarget=s.target,t.preventDefault(),t.relatedTarget=this.currentTarget,this._trigger("beforeOpen",t,r)===!1?!1:(e(document).bind("keydown"+this.ns,function(t){t.which===e.ui.keyCode.ESCAPE&&n._closeMenu()}).bind("mousedown"+this.ns+" touchstart"+this.ns,function(t){e(t.target).closest(".ui-menu-item").length||n._closeMenu()}),i.show().css({position:"absolute",left:0,top:0}).position({my:"left top",at:"left bottom",of:o,collision:"fit"}).hide(),this._show(i,this.options.show,function(){n._trigger.call(n,"open",t)}),void 0)},_closeMenu:function(){var t=this,n=this._getMenu();this._hide(n,this.options.hide,function(){t._trigger("close"),this.currentTarget=null}),e(document).unbind("mousedown"+this.ns).unbind("touchstart"+this.ns).unbind("keydown"+this.ns)},_setOption:function(t,n){switch(t){case"menu":this.replaceMenu(n)}e.Widget.prototype._setOption.apply(this,arguments)},_getMenu:function(){var t=this.options.menu;return"string"==typeof t?e(t):t},open:function(e){var t=jQuery.Event("contextmenu",{target:e.get(0)});return this.element.trigger(t)},close:function(){return this._closeMenu.call(this)},enableEntry:function(e,n){var i=this.element.find("a[href=#"+t(e)+"]");i.toggleClass("ui-state-disabled",n===!1)},replaceMenu:function(t){var n=this.options,i=this._getMenu();e.isArray(t)?this.orgMenu?(i.empty(),e.ui.contextmenu.createMenuMarkup(t,n.menu),i.menu("refresh")):e.error("not implemented"):e.error("not implemented")},setEntry:function(n,i){var s,o=this.element.find("a[href=#"+t(n)+"]");"string"==typeof i?o.contents().filter(function(){return 3===this.nodeType}).first().replaceWith(i):(s=o.closest("li").empty(),e.ui.contextmenu.createEntryMarkup(i,s))},showEntry:function(e,n){var i=this.element.find("a[href=#"+t(e)+"]");i.toggle(n!==!1)}}),e.extend(e.ui.contextmenu,{createEntryMarkup:function(n,i){var s=null;return n.title.match(/^---/)?i.text(n.title):(s=e("",{text:""+n.title,href:"#"+t(n.cmd)}).appendTo(i),n.uiIcon&&s.append(e("").addClass(n.uiIcon)),n.disabled&&i.addClass("ui-state-disabled")),s},createMenuMarkup:function(t,n){var i,s,o,r;for(null==n&&(n=e("").appendTo("body")),i=0;t.length>i;i++)s=t[i],r=e("- ").appendTo(n),e.ui.contextmenu.createEntryMarkup(s,r),e.isArray(s.children)&&(o=e("
").appendTo(r),e.ui.contextmenu.createMenuMarkup(s.children,o));return n}})})(jQuery);
\ No newline at end of file
+(function(e){function n(e){return e&&e.match(/^#/)?e.substring(1):e||""}var t="onselectstart"in document.createElement("div");e.widget("ui.contextmenu",{version:"0.4.1",options:{delegate:"[data-menu]",hide:{effect:"fadeOut",duration:"fast"},show:{effect:"slideDown",duration:"slow"},position:null,ignoreParentSelect:true,menu:null,preventSelect:false,taphold:false,beforeOpen:e.noop,blur:e.noop,close:e.noop,create:e.noop,focus:e.noop,init:e.noop,open:e.noop,select:e.noop},_create:function(){var n,r,i=this.options;this.$headStyle=null;this.orgMenu=null;this.currentTarget=null;this.ns="."+this.widgetName;if(i.preventSelect){r=(e(this.element).is(document)?e("body"):this.element).uniqueId().attr("id");this.$headStyle=e("").prop("type","text/css").html("#"+r+" "+i.delegate+" { "+"-webkit-user-select: none; "+"-khtml-user-select: none; "+"-moz-user-select: none; "+"-ms-user-select: none; "+"user-select: none; "+"}").appendTo("head");if(t){this.element.delegate(i.delegate,"selectstart"+this.ns,function(e){e.preventDefault()})}}if(e.isArray(i.menu)){this.orgMenu=i.menu;i.menu=e.ui.contextmenu.createMenuMarkup(i.menu)}this._getMenu().hide().addClass("ui-contextmenu").menu({blur:e.proxy(this.options.blur,this),create:e.proxy(this.options.create,this),focus:e.proxy(this.options.focus,this),select:e.proxy(function(e,t){e.relatedTarget=this.currentTarget;var n=t.item.has(">a[aria-haspopup='true']").length>0;if(!n||!this.options.ignoreParentSelect){if(this._trigger.call(this,"select",e,t)!==false){this._closeMenu.call(this)}e.preventDefault()}},this)});n="contextmenu"+this.ns;if(i.taphold){n+=" taphold"+this.ns}this.element.delegate(i.delegate,n,e.proxy(this._openMenu,this));this._trigger("init")},_destroy:function(e,t){if(this.$headStyle){this.$headStyle.remove();this.$headStyle=null}if(this.orgMenu){this.options.menu.remove();this.options.menu=this.orgMenu;this.orgMenu=null}},_openMenu:function(t){var n=this,r=this._getMenu(),i=t,s=i.target?i.target:i,o={menu:r};this.currentTarget=i.target;t.preventDefault();t.relatedTarget=this.currentTarget;if(this._trigger("beforeOpen",t,o)===false){return false}e(document).bind("keydown"+this.ns,function(t){if(t.which===e.ui.keyCode.ESCAPE){n._closeMenu()}}).bind("mousedown"+this.ns+" touchstart"+this.ns,function(t){if(!e(t.target).closest(".ui-menu-item").length){n._closeMenu()}});var u=this.options.position;if(u==null){u={my:"left top",at:"left bottom",of:s,collision:"fit"}}else if(jQuery.isFunction(this.options.position)){u=u(t,o)}else{var a=u.of;if(a==null){u.of=s}}r.show().css({position:"absolute",left:0,top:0}).position(u).hide();this._show(r,this.options.show,function(){n._trigger.call(n,"open",t)})},_closeMenu:function(){var t=this,n=this._getMenu();this._hide(n,this.options.hide,function(){t._trigger("close");this.currentTarget=null});e(document).unbind("mousedown"+this.ns).unbind("touchstart"+this.ns).unbind("keydown"+this.ns)},_setOption:function(t,n){switch(t){case"menu":this.replaceMenu(n);break}e.Widget.prototype._setOption.apply(this,arguments)},_getMenu:function(){var t=this.options.menu;return typeof t==="string"?e(t):t},open:function(e){var t=jQuery.Event("contextmenu",{target:e.get(0)});return this.element.trigger(t)},close:function(){return this._closeMenu.call(this)},enableEntry:function(e,t){var r=this.element.find("a[href=#"+n(e)+"]");r.toggleClass("ui-state-disabled",t===false)},replaceMenu:function(t){var n=this.options,r=this._getMenu();if(e.isArray(t)){if(this.orgMenu){r.empty();e.ui.contextmenu.createMenuMarkup(t,n.menu);r.menu("refresh")}else{e.error("not implemented")}}else{e.error("not implemented")}},setEntry:function(t,r){var i,s=this.element.find("a[href=#"+n(t)+"]");if(typeof r==="string"){s.contents().filter(function(){return this.nodeType===3}).first().replaceWith(r)}else{i=s.closest("li").empty();e.ui.contextmenu.createEntryMarkup(r,i)}},showEntry:function(e,t){var r=this.element.find("a[href=#"+n(e)+"]");r.toggle(t!==false)}});e.extend(e.ui.contextmenu,{createEntryMarkup:function(t,r){var i=null;if(t.title.match(/^---/)){r.text(t.title)}else{i=e("",{text:""+t.title,href:"#"+n(t.cmd)}).appendTo(r);if(t.uiIcon){i.append(e("").addClass(t.uiIcon))}if(t.disabled){r.addClass("ui-state-disabled")}}return i},createMenuMarkup:function(t,n){var r,i,s,o;if(n==null){n=e("").appendTo("body")}for(r=0;r- ").appendTo(n);e.ui.contextmenu.createEntryMarkup(i,o);if(e.isArray(i.children)){s=e("
").appendTo(o);e.ui.contextmenu.createMenuMarkup(i.children,s)}}return n}})})(jQuery)