share
Stack Overflowcontext menu on left mouse click?
[+6] [3] Radek
[2011-04-23 00:32:36]
[ javascript jquery jstree ]
[ https://stackoverflow.com/questions/5761307/context-menu-on-left-mouse-click ]

the description of jsTree contextmenu [1] says "The contextmenu plugin enables a contextual menu to be shown, when the user right-clicks a node (or when triggered programatically by the developer)."

could somebody tell me how

Please stop writing tags in question titles. - Lightness Races in Orbit
[+5] [2014-11-06 15:58:35] Pierre de LESPINAY

Since JSTree 3

$('#jstree_list').jstree({
   ...
}).on('select_node.jstree', function (e, data) {
    setTimeout(function() {
        data.instance.show_contextmenu(data.node)
    }, 100);
});

The delay seems necessary, I don't know exactly why


1
[+1] [2011-04-25 15:56:52] Taha Jahangir

You can trigger context menu on elem (eg. a <li>) by $(elem).trigger('contextmenu.jstree')


2
[+1] [2012-07-18 19:52:50] Yoni Baciu

Had the same issue. Here's how you do it:

element.jstree({
  .
  .
  .
}).bind("select_node.jstree", function (event, data) {
  setTimeout(function() {data.rslt.obj.children('a').trigger('contextmenu')}, 100);
});

Note that the triggering is done in a setTimeout(). It did not work for me otherwise.


3