Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to listen for double-click on jstree?

How would I write a listener for a double-click event on a jstree object? (For example, I'd like to double-click on a tree node and paste its anchor's href value into an input field in a form somewhere.)

like image 424
Alex Reynolds Avatar asked May 09 '11 05:05

Alex Reynolds


2 Answers

I have used something like this way back a year ago, i don't know if there's any change in the current jstree version :

jstree.bind("dblclick.jstree", function (event) {
   var node = $(event.target).closest("li");
   var data = node.data("jstree");
   // Do some action
});

node : Contains the li that is being clicked.

data : Contains the metadata.

like image 183
Nirmal Avatar answered Sep 28 '22 04:09

Nirmal


Nirmal's solution works if you click anywhere on the jstree div. I wanted to enable double click only on the nodes themselves and not, for example, on the whitespace to the right. changing the solution a little enabled this:

$('#jstree-div a').live('dblclick',function (e) {
    var node = $(e.target).closest("li");
    var type = node.attr('rel');
    var item = node[0].id;

    // do stuff...
});

Not sure why the 'rel' and the 'id' attributes are in different places in the resulting node, but it works ;)

like image 28
r00pert Avatar answered Sep 28 '22 04:09

r00pert