JQuery Context Menu In HTML/js Code
I have an application with some HTML/js code. I am using jquery to show a contextmenu (Version: 1.6.6) in the $document element when I rightclick in a div of this document. With 'autohide' it closes when mouse leaves the HTML document, but I would like to close the context menu in some other situations. This is my first problem, how to close the menu programatically.
My code:
$(document).contextMenu({
selector: '#' + panelId,
autoHide: true,
items: ...
callback: function(key, options) {
if (key === ...
}
I have a function where I need to close the menu, but all my tests fail:
function()
{
$(document).contextmenu(false);
$(document).trigger('contextmenu:hide');
$trigger = $('#' + panelId);
$trigger.contextMenu(false);
}
'panelId' is a value I get when I rightclick in the div, using 'oncontextmenu' attribute with 'myFunction' value. So 'myFunction' is called before displaying the context menu, and I save there the id, to be used to enable/disable items when the menu is 'about to show'
My second problem: If the context menu is open after rightclicking in a div element (saving the divId in 'myFunction'), and i rightclick in another div element, 'myFunction' is NOT called, so I can not save the new divId
, and the "new" context menu has the same options than the previous one. How can I get the rightclick when the context menu is open? I need the new divId
.
Answer
I have updated my plugin version to https://github.com/swisnl/jQuery-contextMenu/blob/master/src/jquery.contextMenu.js and my 2nd problem was solved.
Then I found how to close the menu, maybe it could help to anyone:
$('.context-menu-list').trigger('contextmenu:hide');
Regards, Diego
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM