| Issue 227: | dblClick does not work on folder nodes | |
| 3 people starred this issue and may be notified of changes. | Back to list |
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. ;)
Sep 18, 2011
I don't understand the bug you are reporting. What's wrong with the current onDblClick behavior?
Status:
Waiting
Sep 18, 2011
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
Sep 18, 2011
(No comment was entered for this change.)
Summary:
dblClick does not work on folder nodes
Status: Accepted Labels: Milestone-Release1.2.1
Oct 20, 2011
Thats because the default option handles click to expand a folder.
Try this option:
clickFolderMode: 0,
Status:
Invalid
Oct 20, 2011
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
Oct 20, 2011
The code I've sent works fine for me ! I open this bug only to give help if someone else have this problem.
Oct 16, 2013
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.
May 15, 2014
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.
May 18, 2014
'now' was 2011 ;-) I will look into it again, if I find time...
Status:
New
Labels: -Milestone-Release1.2.1 Milestone-Release1.2.7
May 19, 2014
Thank you :) I attached a minimal example to test this issue.
May 25, 2014
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?
Status:
Waiting
Dec 25, 2014
(No comment was entered for this change.)
Status:
Done
|
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);