I am using an (admittedly very old) jQuery plugin called contextmenu to replace the right click context menu on certain elements. The source for this plugin can be found here.
You attach the context menu to an element like so:
$(".class").contextMenu('menu_template', {
menuStyle: {
border: '0px',
},
itemStyle: {
},
itemHoverStyle: {
},
onShowMenu: function(e, menu) {
},
other stuff ....
})
Additionally, I would like to manually trigger this menu, and thought the easiest way would be to simulate a right click on the element.
I have tried:
$('.class').triggerHandler('contextmenu');
and
$('.class').trigger({
type:'mousedown',
button:2
}).trigger({
type:'mouseup',
button:2
});
and
$('.class').trigger({
type:'mousedown',
which:3
}).trigger({
type:'mouseup',
which:3
});
and just
$('.class').trigger({
type:'mousedown',
which:3
})
None of these have worked.
I am sure this has something to do with the way this plugin attaches it self to the element and overrides the context menu, but I am no JavaScript expert so am not sure what is going on.
How can I manually trigger this menu to appear?