Skip to content

Commit 2078744

Browse files
committed
fixing repositioning / re-opening of menus - issue swisnl#105
1 parent 9312ea5 commit 2078744

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ $.contextMenu is published under the [MIT license](http://www.opensource.org/lic
103103

104104
## Changelog ##
105105

106+
### git-master ###
107+
108+
* fixing "opening a second menu can break the layer" - ([Issue #105](https://github.com/medialize/jQuery-contextMenu/issues/105))
109+
106110
### 1.6.4 (January 19th 2013) ###
107111

108112
* fixing [jQuery plugin manifest](https://github.com/medialize/jQuery-contextMenu/commit/413b1ecaba0aeb4e50f97cee35f7c367435e7830#commitcomment-2465216), again. yep. I'm that kind of a guy. :(

src/jquery.contextMenu.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,11 @@ var // currently active contextMenu trigger
221221
return;
222222
}
223223

224+
// abort event if menu is visible for this trigger
225+
if ($this.hasClass('context-menu-active')) {
226+
return;
227+
}
228+
224229
if (!$this.hasClass('context-menu-disabled')) {
225230
// theoretically need to fire a show event at <menu>
226231
// http://www.whatwg.org/specs/web-apps/current-work/multipage/interactive-elements.html#context-menus
@@ -392,12 +397,14 @@ var // currently active contextMenu trigger
392397
}
393398
}
394399
}
400+
395401
if (target && triggerAction) {
396-
$(target).contextMenu({x: x, y: y});
397-
} else {
398-
// TODO: it would be nice if we could prevent animations here
399-
root.$menu.trigger('contextmenu:hide');
402+
root.$trigger.one('contextmenu:hidden', function() {
403+
$(target).contextMenu({x: x, y: y});
404+
});
400405
}
406+
407+
root.$menu.trigger('contextmenu:hide');
401408
}, 50);
402409
},
403410
// key handled :hover
@@ -813,7 +820,9 @@ var // currently active contextMenu trigger
813820
opt.$menu.find('ul').css('zIndex', css.zIndex + 1);
814821

815822
// position and show context menu
816-
opt.$menu.css( css )[opt.animation.show](opt.animation.duration);
823+
opt.$menu.css( css )[opt.animation.show](opt.animation.duration, function() {
824+
$trigger.trigger('contextmenu:visible');
825+
});
817826
// make options available and set state
818827
$trigger
819828
.data('contextMenu', opt)
@@ -899,6 +908,10 @@ var // currently active contextMenu trigger
899908
}
900909
});
901910
}
911+
912+
setTimeout(function() {
913+
$trigger.trigger('contextmenu:hidden');
914+
}, 10);
902915
});
903916
},
904917
create: function(opt, root) {

0 commit comments

Comments
 (0)