When I attach onTaskDblClick and onTaskClick events, if I double-click on a task, onTaskClick fires twice and then onTaskDblClick fires.
How can I make this so that only onTaskDblClick fires?
Hello @Kiriu ,
This behavior occurs because the browser generates both dbl-click
and single click
in case of dbl-click
action, and the current gantt implementation can’t avoid it.
If you want to have the code which will run on a real single click, you can use the following workaround:
var sin_timer = null;
function sin_click(event_id, native_event_object)
{
if (sin_timer == null)
sin_timer = window.setTimeout(real_onclick, 500 );
console.log("sin_click="+sin_timer);
return true;
}
function dbl_click(event_id, native_event_object)
{
window.clearTimeout(sin_timer);
sin_timer = null;
console.log("dbl_click");
return true;
}
function real_onclick()
{
console.log("real_onclick");
alert("I'm called only for real single clicks");
sin_timer = null;
}
gantt.attachEvent("onTaskDblClick", dbl_click)
gantt.attachEvent("onTaskClick", sin_click)
Here is a demo:
http://snippet.dhtmlx.com/5/50f7eecbc
I had written something else using setTimeout, but I’ll rewrite it based on yours.
Thank you very much.