Skip to content

Instantly share code, notes, and snippets.

@stepheneb
Created November 1, 2018 20:02
Show Gist options
  • Save stepheneb/77c0d764473167bde91bb0ef96ca0c69 to your computer and use it in GitHub Desktop.
Save stepheneb/77c0d764473167bde91bb0ef96ca0c69 to your computer and use it in GitHub Desktop.
double-clicking using D3.js in the browser
d3DomUIElement.on("click", clickAndDoubleClick(toggleSelectionHandler, selectAndStartEditingHandler));
clickAndDoubleClick = function(singlecallback, doublecallback) {
var f;
f = void 0;
return f = (function() {
var doubleclick, firstclick, g, t1, timer;
firstclick = true;
timer = null;
t1 = null;
doubleclick = false;
g = void 0;
return g = function(d) {
var duration, self, t2;
d3.event.stopPropagation();
self = this;
if (firstclick) {
timer = d3.timeout((function(elapsed) {
var duration, t2;
if (doubleclick) {
} else {
t2 = +new Date();
duration = t2 - t1;
t1 = t2;
firstclick = true;
singlecallback.call(self, d);
}
}), 250);
firstclick = false;
t1 = +new Date();
} else {
t2 = +new Date();
duration = t2 - t1;
t1 = t2;
if (duration < 300) {
timer.stop();
firstclick = true;
doublecallback.call(self, d);
} else {
timer.stop();
window.console.log("*** Error: double click handler fallthrough: " + duration + 'ms');
}
}
};
})();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment