pop up node creation on double click implemented. The x and y of the click are available to the function but are as yet unused

This commit is contained in:
Devin Howard 2012-12-15 14:47:04 -05:00
parent d6803007c3
commit ca6c811870

View file

@ -80,12 +80,12 @@ function graphSettings(type) {
this.onDragMove(node, eventInfo, e);
},
//Add also a click handler to nodes
onClick: function (node) {
onClick: function (node, eventInfo, e) {
//clicking on a node, or clicking on blank part of canvas?
if (node) {
selectNodeOnClickHandler(node);
} else {
createNodeOnClickHandler();
canvasDoubleClickHandler(e);
}//if
}//onClick
},
@ -425,5 +425,22 @@ function selectNodeOnClickHandler(node) {
});
}//selectNodeOnClickHandler
function createNodeOnClickHandler() {
}//createNodeOnClickHandler
//for the canvasDoubleClickHandler function
var canvasDoubleClickHandlerObject = new Object();
canvasDoubleClickHandlerObject.stored_timestamp = 0;
function canvasDoubleClickHandler(e) {
var TOLERANCE = 1000; //1 second
//grab the location and timestamp of the click
var stored_timestamp = canvasDoubleClickHandlerObject.stored_timestamp;
var now = Date.now(); //not compatible with IE8 FYI
if (now - stored_timestamp < TOLERANCE) {
//pop up node creation :)
$('#new_item').fadeIn('fast');
//NOTE: we have e.x, e.y so use them!!
} else {
canvasDoubleClickHandlerObject.stored_timestamp = now;
}
}//canvasDoubleClickHandler