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:
parent
d6803007c3
commit
ca6c811870
1 changed files with 21 additions and 4 deletions
|
@ -80,12 +80,12 @@ function graphSettings(type) {
|
||||||
this.onDragMove(node, eventInfo, e);
|
this.onDragMove(node, eventInfo, e);
|
||||||
},
|
},
|
||||||
//Add also a click handler to nodes
|
//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?
|
//clicking on a node, or clicking on blank part of canvas?
|
||||||
if (node) {
|
if (node) {
|
||||||
selectNodeOnClickHandler(node);
|
selectNodeOnClickHandler(node);
|
||||||
} else {
|
} else {
|
||||||
createNodeOnClickHandler();
|
canvasDoubleClickHandler(e);
|
||||||
}//if
|
}//if
|
||||||
}//onClick
|
}//onClick
|
||||||
},
|
},
|
||||||
|
@ -425,5 +425,22 @@ function selectNodeOnClickHandler(node) {
|
||||||
});
|
});
|
||||||
}//selectNodeOnClickHandler
|
}//selectNodeOnClickHandler
|
||||||
|
|
||||||
function createNodeOnClickHandler() {
|
//for the canvasDoubleClickHandler function
|
||||||
}//createNodeOnClickHandler
|
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
|
||||||
|
|
Loading…
Reference in a new issue