diff --git a/README.md b/README.md index d781d17d..2b2161d0 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,10 @@ $.contextMenu is published under the [MIT license](http://www.opensource.org/lic ## Changelog ## +### git-master ### + +* fixing "opening a second menu can break the layer" - ([Issue #105](https://github.com/medialize/jQuery-contextMenu/issues/105)) + ### 1.6.4 (January 19th 2013) ### * fixing [jQuery plugin manifest](https://github.com/medialize/jQuery-contextMenu/commit/413b1ecaba0aeb4e50f97cee35f7c367435e7830#commitcomment-2465216), again. yep. I'm that kind of a guy. :( diff --git a/src/jquery.contextMenu.js b/src/jquery.contextMenu.js index 92556b68..a903e822 100755 --- a/src/jquery.contextMenu.js +++ b/src/jquery.contextMenu.js @@ -221,6 +221,11 @@ var // currently active contextMenu trigger return; } + // abort event if menu is visible for this trigger + if ($this.hasClass('context-menu-active')) { + return; + } + if (!$this.hasClass('context-menu-disabled')) { // theoretically need to fire a show event at // http://www.whatwg.org/specs/web-apps/current-work/multipage/interactive-elements.html#context-menus @@ -392,12 +397,14 @@ var // currently active contextMenu trigger } } } + if (target && triggerAction) { - $(target).contextMenu({x: x, y: y}); - } else { - // TODO: it would be nice if we could prevent animations here - root.$menu.trigger('contextmenu:hide'); + root.$trigger.one('contextmenu:hidden', function() { + $(target).contextMenu({x: x, y: y}); + }); } + + root.$menu.trigger('contextmenu:hide'); }, 50); }, // key handled :hover @@ -813,7 +820,9 @@ var // currently active contextMenu trigger opt.$menu.find('ul').css('zIndex', css.zIndex + 1); // position and show context menu - opt.$menu.css( css )[opt.animation.show](opt.animation.duration); + opt.$menu.css( css )[opt.animation.show](opt.animation.duration, function() { + $trigger.trigger('contextmenu:visible'); + }); // make options available and set state $trigger .data('contextMenu', opt) @@ -899,6 +908,10 @@ var // currently active contextMenu trigger } }); } + + setTimeout(function() { + $trigger.trigger('contextmenu:hidden'); + }, 10); }); }, create: function(opt, root) {