I'm having an issue with jsPlumb's deleteEndpoint function.
I want to delete endpoints that don't have any connections on them. I'd like for this to trigger on "connection", but I think there might be some issues with it there.
But I moved my code to "dblclick" and I am seeing the same problem. One of the nodes marked for deletion gets deleted but then EVERY endpoint in the system gets frozen in place - disconnected from it's element once its dragged. I'm not sure what's causing it: here's the relevant code and some screenshots...
jsPlumb.bind("dblclick", function(c) {
alert('starting...');
var endpoints_to_delete = new Array();
jsPlumb.selectEndpoints({source:c.sourceId}).each(function(endpoint) {
if( endpoint.connections.length <= 0 )
endpoints_to_delete.push(endpoint);
});
jsPlumb.selectEndpoints({source:c.targetId}).each(function(endpoint) {
if( endpoint.connections.length <= 0 )
endpoints_to_delete.push(endpoint);
});
alert(endpoints_to_delete.length); // 3
$.each(endpoints_to_delete, function(endpoint) {
jsPlumb.deleteEndpoint(endpoint);
});
});
Here's the graph before I attempt to delete the endpoints - all endpoints are still intact with the draggable elements they are attached to.
After attempting to delete an endpoint, EVERY endpoint gets disconnected from its element...
Looping through each element individually and deleting the endpoints worked for me - I think the references to the endpoints on the second element were getting mauled when I started working with endpoints from the first element. Hn.
deleteEmptyEndpoints: function(element)
{
var endpoints_to_delete = [];
jsPlumb.selectEndpoints({source:element}).each(function(endpoint) {
console.log(endpoint);
if( !!endpoint && endpoint.connections.length <= 0 )
{
console.log('marking ' + endpoint.getId() + ' for deletion');
endpoints_to_delete.push(endpoint);
}
});
$.each(endpoints_to_delete, function(index, endpoint) {
console.log('deleting endpoint: ' + endpoint);
jsPlumb.deleteEndpoint(endpoint);
console.log('endpoint deleted');
});
}