jQuery-contextMenu icon indicating copy to clipboard operation
jQuery-contextMenu copied to clipboard

can't `destroy` context menu

Open tkhyn opened this issue 9 years ago • 6 comments

Hi and thanks for jquery-contextMenu,

From 2.2.4 I can't destroy a context menu created with $('ul').contextMenu({selector: 'li'}); using contextMenu('destroy')

This seems to be caused by the fix e738733d7b7f7a630c608799ee86b4c35da8ab92 to issue #397. Indeed, the selector is used to select children elements of the context. So $(context).is(o.selector) is always false, and the menu is never destroyed.

tkhyn avatar Aug 30 '16 05:08 tkhyn

Hmm, when I run against master it I can destroy a contextmenu fine. Can you also reproduce this on the documentation site?

bbrala avatar Oct 12 '16 12:10 bbrala

I should have been more precise in my description. I was referring to $('ul').contextMenu('destroy'), that does not destroy the menu.

STR:

  • go to https://swisnl.github.io/jQuery-contextMenu/demo/on-dom-element.html
  • open the console and type $('#the-node').contextMenu('destroy')

Expected:

  • the context menu associated to #the-node should be destroyed (and was destroyed before v.2.2.4)

Happens:

  • the context menu is not destroyed

If you put a breakpoint on line 1597 of jquery.contextMenu.js, you'll see that the code can never go further than line 1598, as context is $('#the-node') and cannot match a selector which is intended to find children elements.

tkhyn avatar Oct 12 '16 13:10 tkhyn

I think I have the same problem as described above.

Then I tried:

    $.contextMenu({ selector: 'sel', ... })
    ...
    $.contextMenu('destroy', 'sel');

Seems to work, but after some menu creation and deletion chrome crashes with stack overflow, but don't know why (in the moment).

volleybase avatar Nov 07 '16 21:11 volleybase

Hmm, i made a PR to fix this, but this breaks $.contextMenu('destroy', 'selector'); unfortunately. I need to try again later.

The problem is that it is possible to destroy either from a context (like $('.menu')) and without a context, which means it will use document as the context. This is fixable, just not for me, friday at the end of the day :)

bbrala avatar May 05 '17 14:05 bbrala

Then I tried:

$.contextMenu({' selector: 'sel', ... })
...
$.contextMenu('destroy', 'sel');

Seems to work, but after some menu creation and deletion chrome crashes with stack overflow, but don't know why (in the moment).

This worked for me. v2.6.4

$('wrapper').contextMenu({
		selector: 'input'
...
});
$('wrapper').contextMenu('destroy');

and I changed it to

$('wrapper').contextMenu({
		selector: 'input'
...
});
$.contextMenu('destroy', $('wrapper'));

bct9321 avatar Jul 20 '18 21:07 bct9321

This issue has been present for a long time and still persists. I have created an example that reproduces the issue: https://codepen.io/y1j2x34/pen/zYeLqYQ. When I click the "Remove box 1" button, the .context-menu-list node is not being deleted.

y1j2x34 avatar Nov 27 '23 09:11 y1j2x34