Skip to content

Commit 93a381d

Browse files
committed
Fixing Issue swisnl#63 - Backdrop is not properly removed on destroy
1 parent 8b95570 commit 93a381d

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/jquery.contextMenu.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ var // currently active contextMenu trigger
754754
// hide menu if callback doesn't stop that
755755
if (callback.call(root.$trigger, key, root) !== false) {
756756
root.$menu.trigger('contextmenu:hide');
757-
} else {
757+
} else if (root.$menu.parent().length) {
758758
op.update.call(root.$trigger, root);
759759
}
760760
},
@@ -764,9 +764,9 @@ var // currently active contextMenu trigger
764764
},
765765

766766
// hide <menu>
767-
hideMenu: function(e) {
767+
hideMenu: function(e, data) {
768768
var root = $(this).data('contextMenuRoot');
769-
op.hide.call(root.$trigger, root);
769+
op.hide.call(root.$trigger, root, data && data.force);
770770
},
771771
// focus <command>
772772
focusItem: function(e) {
@@ -856,14 +856,14 @@ var // currently active contextMenu trigger
856856
});
857857
}
858858
},
859-
hide: function(opt) {
859+
hide: function(opt, force) {
860860
var $this = $(this);
861861
if (!opt) {
862862
opt = $this.data('contextMenu') || {};
863863
}
864864

865865
// hide event
866-
if (opt.events && opt.events.hide.call($this, opt) === false) {
866+
if (!force && opt.events && opt.events.hide.call($this, opt) === false) {
867867
return;
868868
}
869869

@@ -1297,6 +1297,11 @@ $.contextMenu = function(operation, options) {
12971297

12981298
$('#context-menu-layer, .context-menu-list').remove();
12991299
} else if (namespaces[o.selector]) {
1300+
var $visibleMenu = $('.context-menu-list').filter(':visible');
1301+
if ($visibleMenu.length && $visibleMenu.data().contextMenuRoot.$trigger.is(o.selector)) {
1302+
$visibleMenu.trigger('contextmenu:hide', {force: true});
1303+
}
1304+
13001305
try {
13011306
if (menus[namespaces[o.selector]].$menu) {
13021307
menus[namespaces[o.selector]].$menu.remove();

0 commit comments

Comments
 (0)