pcirella / dynatree

Automatically exported from code.google.com/p/dynatree
0 stars 0 forks source link

dblClick does not work on folder nodes #227

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I need to do action on double click on a folder (currently not available), I 
solved this issue with this change :

Before (lines=2861):
switch(event.type) {
case "click":
    return ( o.onClick && o.onClick.call(tree, dtnode, event)===false ) ? false : dtnode._onClick(event);
case "dblclick":
    return ( o.onDblClick && o.onDblClick.call(tree, dtnode, event)===false ) ? false : dtnode._onDblClick(event);

After :
switch(event.type) {
case "click":
    if(o.onClick && o.onClick.call(tree, dtnode, event)===false) return false;
    if(this.onClickTimeout) clearTimeout(this.onClickTimeout);
    if(dtnode.getEventTargetType(event)!='expander') {
        var originalEvent = event;
        this.onClickTimeout = setTimeout(function(){ dtnode._onClick(originalEvent); }, 250);
        event.preventDefault();
        return false;
    } else return dtnode._onClick(event);
case "dblclick":
    if(this.onClickTimeout) clearTimeout(this.onClickTimeout);
    return ( o.onDblClick && o.onDblClick.call(tree, dtnode, event)===false ) ? false : dtnode._onDblClick(event);

and at the last line of the function _onClick (line=1163), I catch the 
exception thrown when the event is the wrong event:
try {
    event.preventDefault();
} catch(e){}

With this, a double click made under 250ms enable the onDblClick event. ;)

Original issue reported on code.google.com by eric.bla...@gmail.com on 17 Sep 2011 at 11:01

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
to keep the original action if not DblClick event exist:

if(o.onDblClick && dtnode.getEventTargetType(event)!='expander') {
  var originalEvent = event;
  this.onClickTimeout = setTimeout(function(){ dtnode._onClick(originalEvent); }, 250);
  event.preventDefault();
  return false;
} else return dtnode._onClick(event);

Original comment by eric.bla...@gmail.com on 17 Sep 2011 at 11:21

GoogleCodeExporter commented 9 years ago
I don't understand the bug you are reporting.
What's wrong with the current onDblClick behavior?

Original comment by moo...@wwwendt.de on 18 Sep 2011 at 11:11

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Sorry, I'm french,

I just say I need to enable a DblClick on a root folder

+Folder Node   <= here the DblClick is not available, dblClick only open and 
close folder
 |
 --Child Nodes  <= here the DblClick work fine

Original comment by eric.bla...@gmail.com on 18 Sep 2011 at 9:42

GoogleCodeExporter commented 9 years ago

Original comment by moo...@wwwendt.de on 19 Sep 2011 at 5:32

GoogleCodeExporter commented 9 years ago
Thats because the default option handles click to expand a folder.
Try this option:
    clickFolderMode: 0,

Original comment by moo...@wwwendt.de on 20 Oct 2011 at 8:12

GoogleCodeExporter commented 9 years ago
No, "clickFolderMode: 0" disable the single-clicking to open the folder.

The idee is to keep the single click to open the folder and allow a callback 
function on the dblClick event

Original comment by eric.bla...@gmail.com on 20 Oct 2011 at 8:26

GoogleCodeExporter commented 9 years ago
The code I've sent works fine for me ! I open this bug only to give help if 
someone else have this problem.

Original comment by eric.bla...@gmail.com on 20 Oct 2011 at 8:29

GoogleCodeExporter commented 9 years ago
We need something similar to this as well.

Single click: expand node as normal
Double click: onDblClick event handler

We could not get it to work.

Original comment by bjohnson...@gmail.com on 16 Oct 2013 at 4:43

GoogleCodeExporter commented 9 years ago
Why is the status now "Invalid"?

The onDblClick event should be fired on double click -- regardless of clicked 
node is a parent or a leaf node.

It just makes no sense to prohibit handling double clicks on parent nodes.

Original comment by jscho...@gmail.com on 15 May 2014 at 2:20

GoogleCodeExporter commented 9 years ago
'now' was 2011 ;-)
I will look into it again, if I find time...

Original comment by moo...@wwwendt.de on 18 May 2014 at 6:57

GoogleCodeExporter commented 9 years ago
Thank you :)

I attached a minimal example to test this issue.

Original comment by jscho...@gmail.com on 19 May 2014 at 2:20

Attachments:

GoogleCodeExporter commented 9 years ago
clickFolderMode=3 (the deafult mode) does acitvate and expand folders on single 
click,
but calls preventDefault(), so no dblclick is generated.

Changing this behavior might break existing use cases, I think.

A workaround might be to set clickFolderMode to 1 (activate only).
Then implement mode 3 (activate + expand) yourself.

    $('#tree').dynatree({
        clickFolderMode: 1,  // activate only, but don't prevent dblclick events
        onClick: function(node, event) {
            // implement clickFolderMode 3: acitvate and expand folders on click
            if( node.data.isFolder ) {
                node.toggleExpand();
            }
        },
        onDblClick: function(node, event) {
            // this event will gegenerated now
        },
        children: treeData
    });

But note that we might get TWO click events now before dblklick, so toggling 
may get triggered twice.
So mixing dblclick and click behavior might not be a good idea anyway.

Any thoughts?

Original comment by moo...@wwwendt.de on 25 May 2014 at 2:34

GoogleCodeExporter commented 9 years ago

Original comment by moo...@wwwendt.de on 25 Dec 2014 at 8:17